Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: importing functions with "PerlModule" Apache directive

by Anonymous Monk
on May 09, 2012 at 10:50 UTC ( #969595=note: print w/ replies, xml ) Need Help??


in reply to importing functions with "PerlModule" Apache directive

I am not able to find out if there is a way to pass to PerlModule directive the functions and/or parameters

PerlModule site:perl.apache.org -> http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlModule_

PerlModule Foo::Bar
is equivalent to Perl's:
require Foo::Bar;
PerlModule is used to load modules using their package names.

See also: PerlRequire.

http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlRequire_

PerlRequire does the same thing as PerlPostConfigRequire, but you have almost no control of when this code is going to be executed. Therefore you should be using either PerlConfigRequire (executes immediately) or PerlPostConfigRequire (executes just before the end of the server startup) instead. Most of the time you want to use the latter.

http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlPostConfigRequire_

PerlPostConfigRequire /home/httpd/perl/lib/startup.pl
is equivalent to Perl's:
require "/home/httpd/perl/lib/startup.pl";

Looking at my current apache2/mod_perl2 config, I see I'm using

PerlRequire "...startup.pl"
just as http://perl.apache.org/docs/1.0/guide/config.html#PerlModule_and_PerlRequire_Directives recommends. This is not ideal for apache2 as http://perl.apache.org/docs/2.0/user/handlers/server.html#When_Does_perl_Start_To_Run explains.

Use  PerlRequire   "...startup.pl"   for Apache1/mod_perl-1

Use  PerlPostConfigRequire "...startup.pl"   for Apache2/mod_perl-2


Comment on Re: importing functions with "PerlModule" Apache directive
Select or Download Code
Re^2: importing functions with "PerlModule" Apache directive
by acanfora (Novice) on May 09, 2012 at 11:34 UTC
    I was just thinking about to use the PerlPostConfigRequire directive, I actually just switched to it in my apache.conf and everything is working fine:
    PerlPostConfigRequire /etc/apache2/startup.pl
    It is not yet clear to me the behavior with exported functions, I mean, I put in startup.pl
    use CGI qw(-compile -utf8);
    and avoided to import CGI in my test script, but I can still call Vars() function directly, which from CGI documentation should not be visible:
    #!/usr/bin/perl $ENV{PATH}=''; local our $o; $o->{authenticated}=0; local our $cookie; local our $duration=600; local our $r=new CGI; local our $p=Vars; ...
    What's going on?

      and avoided to import CGI in my test script, but I can still call Vars() function directly, which from CGI documentation should not be visible:

      What's going on?

      You're imagining things :)

      Even if you used  use CGI qw(-compile -utf8 Vars ); there is no way Vars would be available to your script , unless you're using something ( its not ModPerl::Registry ) to make it available

        Pay attention: I stated that Vars is actually available in my test script even if I did not imported it (purposely, at least) in any way.
        startup.pl script: use CGI; mytestscript: #!/usr/bin/perl local our $p=Vars; # it works!!!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969595]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2014-10-23 02:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (123 votes), past polls