http://www.perlmonks.org?node_id=969595


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

Replies are listed 'Best First'.
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!!!