You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2004/09/18 20:17:30 UTC

[mp2] remove the magicness of PerlLoadModule wrt directives

Geoff wanted PerlLoadModule be available to all modules that require
an interpreter be created early, not merely directive handlers.

So as discussed in several threads the conclusion was:

- remove the magickness of PerlLoadModule wrt directives
- add a special Apache::Module API which will add directives, like so:

package MyApache::MyDirectives;
my @cmds = (...);
Apache::Module::add(__PACKAGE__, \@cmds);

since this issue is marked as mp2-release show-stopper, Philippe hs 
volunteered to resolve it. Is that OK Geoff? (you are the owner of this 
item in todo/release). Also do you already have some code available? 
Especially tests, since you wanted it because you wanted to ensure that 
the module is loaded early, but I have not seen any test cases.

While we are at it, we may consider renaming this directive, since it's 
now getting even further away from Load thing. PerlModuleNow? 
PerlModuleEarly?

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [Patch mp2] remove the magicness of PerlLoadModule wrt directives

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.

Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> 
>> Index: src/docs/2.0/api/Apache/Module.pod
>> ===================================================================
> 
> 
>> +  #Define a configuration directive
>> +  my @directives = (
>> +    name => 'MyDirective',
>> +  );
> 
> 
> 1) indent 4 s.t.p.
> 2) where is the hash ref?
> 
> otherwise +1 to commit

Done deal!

--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 
88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 
88C3A5A5

Re: [Patch mp2] remove the magicness of PerlLoadModule wrt directives

Posted by Stas Bekman <st...@stason.org>.
Philippe M. Chiasson wrote:

> Index: src/docs/2.0/api/Apache/Module.pod
> ===================================================================

> +  #Define a configuration directive
> +  my @directives = (
> +    name => 'MyDirective',
> +  );

1) indent 4 s.t.p.
2) where is the hash ref?

otherwise +1 to commit

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [Patch mp2] remove the magicness of PerlLoadModule wrt directives

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Stas Bekman wrote:
> Philippe M. Chiasson wrote:
> 
>> Attached is the small patch to remove the magicness of PerlLoadModule 
>> and add
>> Apache::Module::add() as discussed earlier.
> 
> excellent! a few minor comments below.
> 
>> [...]
>> +
>> +Apache::Module::add(__PACKAGE__, \@CMDS);
> 
> I suppose there is no point making those upcase anymore, since they 
> aren't special (above and below / tests + docs). What do you think?

Think it's a very good idea, and I liked Geoff's suggestion of 
@directives instead.

>> Index: src/docs/2.0/api/Apache/CmdParms.pod
> 
> [...]
> 
>>  The extra information passed through C<cmd_data> in
>> -C<L<@APACHE_MODULE_COMMANDS|docs::2.0::user::config::custom/C_cmd_data_>>. 
>>
>> +C<L<@CMDS|docs::2.0::user::config::custom/C_cmd_data_>>.
> 
> 
> but it's no longer passed in cmd_data user-wise. Shouldn't it link to 
> Apache::Module::add() and the latter to cmd_data?

Yes, I guess it makes more sense that way.

> [...] 
> missing add() call?

Yup.

>> Index: src/docs/2.0/api/Apache/Const.pod
> [...]  
>> -=item * A global array C<@APACHE_MODULE_COMMANDS> for declaring the
>> -new directives and their behavior.
>> +=item * An array C<L<@CMDS|/C__CMDS_>> for declaring the new 
>> directives and their
>> +behavior.
>> +
>> +=item * A call to 
>> C<L<Apache::Module::add()|docs::2.0::api::Apache::Module/C_add_>> to 
>> register the new
>> +directives with apache.
>  
> wrap the line?

Indeed.

> [...]
> 
> may be add a note that @CMDS is not a special name and any other name 
> will do?

That's a good idea. Added.

>> +=head2 Apache::Module::add()
> 
> Call it: "Activating the new directive" or "Registering ..."  or 
> something like that? Apache::Module::add() looks like an API entry, 
> which is already defined elsewhere.

"Registering the new directives" is it.

-- 
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 
88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 
88C3A5A5

Re: [Patch mp2] remove the magicness of PerlLoadModule wrt directives

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Geoffrey Young wrote:

>>>+Apache::Module::add(__PACKAGE__, \@CMDS);
>>>      
>>>
>>I suppose there is no point making those upcase anymore, since they
>>aren't special (above and below / tests + docs). What do you think?
>>    
>>
>
>I was going to say the same thing.
>
>  my @directives = (...);
>
>is probably a good choice, since that's the designation out there in the
>eagle book and cookbook, so folks using it can just take that array from the
>old Makefile.PL and paste it into the .pm.
>  
>
I like @directives much better than @CMDS, I'll make that change.

>other than that, I've applied the patch and ported both Apache-AuthenHook
>and Apache-Template over and they work just fine.
>
>+1
>  
>
Great, still fixing a few problems with the documentation, but it should 
reach your
nearest CVS server soon.

>--Geoff
>
>  
>


Re: [Patch mp2] remove the magicness of PerlLoadModule wrt directives

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>> +Apache::Module::add(__PACKAGE__, \@CMDS);
> 
> 
> I suppose there is no point making those upcase anymore, since they
> aren't special (above and below / tests + docs). What do you think?

I was going to say the same thing.

  my @directives = (...);

is probably a good choice, since that's the designation out there in the
eagle book and cookbook, so folks using it can just take that array from the
old Makefile.PL and paste it into the .pm.

other than that, I've applied the patch and ported both Apache-AuthenHook
and Apache-Template over and they work just fine.

+1

--Geoff

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [Patch mp2] remove the magicness of PerlLoadModule wrt directives

Posted by Stas Bekman <st...@stason.org>.
Philippe M. Chiasson wrote:
> Attached is the small patch to remove the magicness of PerlLoadModule 
> and add
> Apache::Module::add() as discussed earlier.

excellent! a few minor comments below.

> Index: t/response/TestCompat/apache_module.pm
> ===================================================================
> RCS file: /home/cvs/modperl-2.0/t/response/TestCompat/apache_module.pm,v
> retrieving revision 1.3
> diff -u -I$Id -r1.3 apache_module.pm
> --- t/response/TestCompat/apache_module.pm	16 Sep 2004 16:32:08 -0000	1.3
> +++ t/response/TestCompat/apache_module.pm	8 Nov 2004 19:09:38 -0000
> @@ -11,11 +11,13 @@
>  use Apache::compat ();
>  use Apache::Constants qw(OK);
>  
> -our @APACHE_MODULE_COMMANDS = (
> +my @CMDS = (
>      {
>          name => 'TestCompatApacheModuleParms',
>      },
>  );
> +
> +Apache::Module::add(__PACKAGE__, \@CMDS);

I suppose there is no point making those upcase anymore, since they aren't 
special (above and below / tests + docs). What do you think?

> Index: src/docs/2.0/api/Apache/CmdParms.pod
[...]
>  The extra information passed through C<cmd_data> in
> -C<L<@APACHE_MODULE_COMMANDS|docs::2.0::user::config::custom/C_cmd_data_>>.
> +C<L<@CMDS|docs::2.0::user::config::custom/C_cmd_data_>>.

but it's no longer passed in cmd_data user-wise. Shouldn't it link to 
Apache::Module::add() and the latter to cmd_data?

>    $info = $parms->info;
>  
> @@ -213,7 +216,7 @@
>  For example here is how to pass arbitrary information to a directive
>  subroutine:
>  
> -  our @APACHE_MODULE_COMMANDS = (
> +  my @CMDS = (
>      {
>        name => 'MyDirective1',
>        func => \&MyDirective,

missing add() call?

> Index: src/docs/2.0/api/Apache/Const.pod
> ===================================================================
> RCS file: /home/cvs/modperl-docs/src/docs/2.0/api/Apache/Const.pod,v
> retrieving revision 1.27
> diff -u -I$Id -r1.27 Const.pod
> --- src/docs/2.0/api/Apache/Const.pod	17 Sep 2004 19:28:15 -0000	1.27
> +++ src/docs/2.0/api/Apache/Const.pod	8 Nov 2004 19:21:09 -0000
> @@ -87,7 +87,7 @@
>    use Apache::Const -compile => qw(:cmd_how);
>  
>  The C<:cmd_how> constants group is used in
> -C<L<@APACHE_MODULE_COMMANDS|docs::2.0::user::config::custom/C_args_how_>>
> +C<L<Apache::Module::add()|docs::2.0::user::config::custom/C_args_how_>>
>  and
>  C<L<$cmds-E<gt>args_how|docs::2.0::api::Apache::Command/C_args_how_>>.

same as C_cmd_data_ comment above?

> Index: src/docs/2.0/user/config/custom.pod
[...]
> -A minimal configuration module is comprised of two groups of elements:
> +A minimal configuration module is comprised of three groups of elements:
>  
>  =over
>  
> -=item * A global array C<@APACHE_MODULE_COMMANDS> for declaring the
> -new directives and their behavior.
> +=item * An array C<L<@CMDS|/C__CMDS_>> for declaring the new directives and their
> +behavior.
> +
> +=item * A call to C<L<Apache::Module::add()|docs::2.0::api::Apache::Module/C_add_>> to register the new
> +directives with apache.

wrap the line?

> -=head2 C<@APACHE_MODULE_COMMANDS>
> +=head2 C<@CMDS>
>  
> -C<@APACHE_MODULE_COMMANDS> is a global array of hash references. Each
> +C<@CMDS> is an array of hash references. Each
>  hash represents a separate new configuration directive. In our example
>  we had:
>  
> -  our @APACHE_MODULE_COMMANDS = (
> +  my @CMDS = (
>        {
>         name         => 'MyParameter',
>         func         => __PACKAGE__ . '::MyParameter',
> @@ -274,7 +278,7 @@
>  you to store arbitrary strings for later retrieval from your
>  directive handler.  For instance:
>  
> -  our @APACHE_MODULE_COMMANDS = (
> +  my @CMDS = (
>        {
>         name         => '<Location',
>         # func defaults to Redirect()
> @@ -313,6 +317,14 @@
>  chosen for a reason - this is exactly how httpd core handles these
>  two directives.

may be add a note that @CMDS is not a special name and any other name will do?

> +=head2 Apache::Module::add()

Call it: "Activating the new directive" or "Registering ..."  or something 
like that? Apache::Module::add() looks like an API entry, which is already 
defined elsewhere.

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


[Patch mp2] remove the magicness of PerlLoadModule wrt directives

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Attached is the small patch to remove the magicness of PerlLoadModule and add
Apache::Module::add() as discussed earlier.

-- 
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Re: [mp2] remove the magicness of PerlLoadModule wrt directives

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
>>>>Are you trying to say that we should stop deferring the perl startup as
>>>>you've suggested before?
>>>
>>>
>>>
>>>no, I think the current behavior of PerlModule is fine, as it works
>>>sufficiently well for most cases.  if we have a way (other than hacking
>>>together a <Perl> section) to make sure that perl code can run at config
>>>time as well, then I'm all set.
>>
>>
>>You mean once Philippe does the change in the subject, you are all set?
>>Or do you need something else?
>>
> 
> 
> if the API you quoted at the start of this thread (and that we had agreed
> upon previously) is introduced I think we'll be all set, yes.  and when that
> happens I'll port my two directive handler modules for mp2 over to the new
> interface to make sure they still work - then we'll really know :)

Excellent.


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] remove the magicness of PerlLoadModule wrt directives

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>>> Are you trying to say that we should stop deferring the perl startup as
>>> you've suggested before?
>>
>>
>>
>> no, I think the current behavior of PerlModule is fine, as it works
>> sufficiently well for most cases.  if we have a way (other than hacking
>> together a <Perl> section) to make sure that perl code can run at config
>> time as well, then I'm all set.
> 
> 
> You mean once Philippe does the change in the subject, you are all set?
> Or do you need something else?
> 

if the API you quoted at the start of this thread (and that we had agreed
upon previously) is introduced I think we'll be all set, yes.  and when that
happens I'll port my two directive handler modules for mp2 over to the new
interface to make sure they still work - then we'll really know :)

--Geoff

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] remove the magicness of PerlLoadModule wrt directives

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:

>>>as I've brought up before, I think the entire notion of "starting
>>>early" is
>>>bogus - it's not "early" if I require perl code to run while
>>>httpd.conf is
>>>being parsed, it is exactly the right time.
>>
>>
>>Are you trying to say that we should stop deferring the perl startup as
>>you've suggested before?
> 
> 
> no, I think the current behavior of PerlModule is fine, as it works
> sufficiently well for most cases.  if we have a way (other than hacking
> together a <Perl> section) to make sure that perl code can run at config
> time as well, then I'm all set.

You mean once Philippe does the change in the subject, you are all set? Or 
do you need something else?

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] remove the magicness of PerlLoadModule wrt directives

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> So Philippe you have a green light then :) And I suppose you can ping
> Geoff for more real-world tests, once you adjust the existing tests.

:)

 > Of course one could argue that PerlModuleEarly is just as ambiguous, but
> hey I was just suggesting a more intuitive name. I didn't suggest that
> it was the best choice.

:)

> 
>> as I've brought up before, I think the entire notion of "starting
>> early" is
>> bogus - it's not "early" if I require perl code to run while
>> httpd.conf is
>> being parsed, it is exactly the right time.
> 
> 
> Are you trying to say that we should stop deferring the perl startup as
> you've suggested before?

no, I think the current behavior of PerlModule is fine, as it works
sufficiently well for most cases.  if we have a way (other than hacking
together a <Perl> section) to make sure that perl code can run at config
time as well, then I'm all set.

--Geoff

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] remove the magicness of PerlLoadModule wrt directives

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
[...]
>>Especially tests, since you wanted it because you wanted to ensure that
>>the module is loaded early, but I have not seen any test cases.
> 
> 
> Apache-AuthenHook on CPAN is a good example.  at the end of AuthenHook.xs I
> have this code:
> 
>     ap_register_provider(modperl_global_get_pconf(),
>                          AUTHN_PROVIDER_GROUP,
>                          SvPV_nolen(newSVsv(provider)), "0",
>                          &authn_AAH_provider);
> 
> which needs to be called _before_ mod_auth_basic or mod_auth_digest go
> looking for a provider specified in httpd.conf.  if AuthenHook were not
> implemented via directive handlers there would be no way to do this outside
> of inserting <Perl> sections in httpd.conf or somesuch.

So Philippe you have a green light then :) And I suppose you can ping 
Geoff for more real-world tests, once you adjust the existing tests.

>>While we are at it, we may consider renaming this directive, since it's
>>now getting even further away from Load thing. PerlModuleNow?
>>PerlModuleEarly?
> 
> 
> I think the name is exactly right.  from an apache perspective, LoadModule
> runs a module's init routines when LoadModule is called, without later
> deferring the init until some later time.  PerlLoadModule would do exactly
> the same - load a perl module and run it's init code _now_.  using
> PerlLoadModule is analgous to all the other Perl* directives we have
> (PerlSetVar, PerlPassEnv, etc) that are pretty much behave exactly the same
> as Apache directives but are tweaked for Perl purposes.

sure. Just don't forget that most users aren't core apache people and they 
have no clue what LoadModule does besides loading the module. So I was 
trying to suggest semantics which will be more intuitive for the majority 
of the users, not a handfull of experts. And the non-experts will 
certainly confuse, PerlLoadModule and PerlModule, since the semantic 
different is very ambiguous if you take away your Apache internals knowledge.

Of course one could argue that PerlModuleEarly is just as ambiguous, but 
hey I was just suggesting a more intuitive name. I didn't suggest that it 
was the best choice.

> as I've brought up before, I think the entire notion of "starting early" is
> bogus - it's not "early" if I require perl code to run while httpd.conf is
> being parsed, it is exactly the right time.

Are you trying to say that we should stop deferring the perl startup as 
you've suggested before?


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [mp2] remove the magicness of PerlLoadModule wrt directives

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Stas Bekman wrote:
> Geoff wanted PerlLoadModule be available to all modules that require
> an interpreter be created early, not merely directive handlers.
> 
> So as discussed in several threads the conclusion was:
> 
> - remove the magickness of PerlLoadModule wrt directives
> - add a special Apache::Module API which will add directives, like so:
> 
> package MyApache::MyDirectives;
> my @cmds = (...);
> Apache::Module::add(__PACKAGE__, \@cmds);
> 
> since this issue is marked as mp2-release show-stopper, Philippe hs
> volunteered to resolve it. Is that OK Geoff? (you are the owner of this
> item in todo/release). 

sure.  philippe can knock himself out :)

> Also do you already have some code available?

no, I never got to implementing it.

> Especially tests, since you wanted it because you wanted to ensure that
> the module is loaded early, but I have not seen any test cases.

Apache-AuthenHook on CPAN is a good example.  at the end of AuthenHook.xs I
have this code:

    ap_register_provider(modperl_global_get_pconf(),
                         AUTHN_PROVIDER_GROUP,
                         SvPV_nolen(newSVsv(provider)), "0",
                         &authn_AAH_provider);

which needs to be called _before_ mod_auth_basic or mod_auth_digest go
looking for a provider specified in httpd.conf.  if AuthenHook were not
implemented via directive handlers there would be no way to do this outside
of inserting <Perl> sections in httpd.conf or somesuch.

> 
> While we are at it, we may consider renaming this directive, since it's
> now getting even further away from Load thing. PerlModuleNow?
> PerlModuleEarly?

I think the name is exactly right.  from an apache perspective, LoadModule
runs a module's init routines when LoadModule is called, without later
deferring the init until some later time.  PerlLoadModule would do exactly
the same - load a perl module and run it's init code _now_.  using
PerlLoadModule is analgous to all the other Perl* directives we have
(PerlSetVar, PerlPassEnv, etc) that are pretty much behave exactly the same
as Apache directives but are tweaked for Perl purposes.

as I've brought up before, I think the entire notion of "starting early" is
bogus - it's not "early" if I require perl code to run while httpd.conf is
being parsed, it is exactly the right time.

--Geoff

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org