Philippe M . Chiasson wrote:

> Hi, this patch implements the Apache->module() functionnality with a few differences.
> 
> Apache->module() is in Apache::compat and the real name for this is 
>Apache::Module::loaded()
> and I am open for better suggestions.  "if (Apache->module('Apache::Auth'))" doesn't 
>quite
> make as much sense to me than "if (Apache::Module::loaded('Apache::Auth'))"
> 
> Added a fet test cases for it and took the time to rewrite the module.t tests
> with Stas's cool t_cmp()
> 
> The behavious is now 3-fold instead of 2 like mod_perl 1.x
> 
> 1- if the name ends in '.c' then it will return true/false if that apache
> module is present or not.
> 
> 2- if the name ends in '.so' then it will return true/false if that apache
> module is present and was loaded as a DSO
> 
> 3- else it returns true/false if a perl module of that name is already loaded.
> 
> Comments most welcome.
> 
> Index: todo/api.txt
> ===================================================================
> RCS file: /home/anoncvs/mod_perl-2-cvs/todo/api.txt,v
> retrieving revision 1.6
> diff -u -I'$Id' -I'$Revision' -r1.6 api.txt
> --- todo/api.txt      2001/09/28 13:51:57     1.6
> +++ todo/api.txt      2001/10/02 07:17:48
> @@ -28,9 +28,6 @@
>  $r->log_reason:
>  should be simple, see modperl_log.h
>  
> -Apache->module:
> -not yet implemented
> -
>  Apache->server_root_relative:
>  needs to default to current pool (pconf at startup, r->pool at request
>  time)
> Index: xs/maps/apache_functions.map
> ===================================================================
> RCS file: /home/anoncvs/mod_perl-2-cvs/xs/maps/apache_functions.map,v
> retrieving revision 1.30
> diff -u -I'$Id' -I'$Revision' -r1.30 apache_functions.map
> --- xs/maps/apache_functions.map      2001/09/17 01:06:08     1.30
> +++ xs/maps/apache_functions.map      2001/10/02 07:17:48
> @@ -180,6 +180,7 @@
>  >ap_show_directives
>  >ap_show_modules
>  >ap_register_hooks
> + mpxs_Apache__Module_loaded
>  
>  MODULE=Apache::Directive
>   ap_directive_t *:DEFINE_conftree | | SV *:CLASS
> Index: xs/Apache/Module/Apache__Module.h
> ===================================================================
> RCS file: /home/anoncvs/mod_perl-2-cvs/xs/Apache/Module/Apache__Module.h,v
> retrieving revision 1.2
> diff -u -I'$Id' -I'$Revision' -r1.2 Apache__Module.h
> --- xs/Apache/Module/Apache__Module.h 2001/03/26 15:51:50     1.2
> +++ xs/Apache/Module/Apache__Module.h 2001/10/02 07:17:48
> @@ -1,2 +1,31 @@
>  #define mpxs_Apache__Module_top_module(CLASS) \
>  (CLASS ? ap_top_module : ap_top_module)
> +
> +static MP_INLINE
> +int mpxs_Apache__Module_loaded(const char *name)
> +{
> +    dTHX; /*XXX*/
> +    module *mod;
> +     
> +    if (0 == ap_strcmp_match(name,"*.c")) {
> +        mod = modperl_get_ap_module(name);
> +        return ( NULL != mod );
> +    }
> +    else if (0 == ap_strcmp_match(name,"*.so")) {
> +        size_t len = strlen(name);
> +        char *so = malloc(len+1);


should we actually use malloc? I thought that we have to use APR for 
this kind of staff? In any case if you use malloc, you should check for 
success, right?


> Index: t/response/TestAPI/module.pm
> ===================================================================
> RCS file: /home/anoncvs/mod_perl-2-cvs/t/response/TestAPI/module.pm,v
> retrieving revision 1.1
> diff -u -I'$Id' -I'$Revision' -r1.1 module.pm
> --- t/response/TestAPI/module.pm      2001/04/04 05:45:48     1.1
> +++ t/response/TestAPI/module.pm      2001/10/02 07:17:48
> @@ -4,32 +4,51 @@
>  use warnings FATAL => 'all';
>  
>  use Apache::Test;
> +use Apache::TestConfig;
> +use Apache::TestUtil;
>  use Apache::Module ();
>  use DynaLoader ();
>  
>  sub handler {
>      my $r = shift;
>  
> -    plan $r, tests => 6;
> +    my $cfg = Apache::TestConfig->thaw;


that's too heavy. please use Apache::Test::config() instead. I'll 
correct other tests not to use thaw.


> -    ok $top_module->version;
> +    ok t_cmp($cfg->{httpd_info}{MODULE_MAGIC_NUMBER}, $top_module->version . ':0' , 
>q{$top_module->version});


< 74-80 char wrap here please, and the rest of the file

  
> -    ok $top_module->module_index;
> +    ok t_cmp(scalar(keys(%{$cfg->{modules}})), $top_module->module_index, 
>q{$top_module->module_index});


better readable as %{ $cfg->{modules} }

  
> -    ok $top_module->name;
> +    ok t_cmp('mod_perl.c', $top_module->name(), q{$top_module->name});


> +    ok t_cmp(0, Apache::Module::loaded('foo'), "Apache::Module::loaded('foo')");


'foo' is too useful to be make sure that it won't fail in the future, if 
someone adds module_foo (like module_example). When in doubt, use the 
test package name, e.g.  TestAPI__module, it's unique in t.

...the rest looks good :) thanks Philippe

_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to