perl - How to pass environment variable to an AutoLoaded mod_perl handler, to be used at module load time? -



perl - How to pass environment variable to an AutoLoaded mod_perl handler, to be used at module load time? -

i have http request handler mod_perl needs read environment variable, %env, @ module load time. environment variable passed apache config mod_perl using perlsetenv directive.

this worked fine, until changed apache configuration autoload handler @ startup time, performance reasons. when module autoloaded this, theperlsetenv not take effect @ module load time, , variable need available %env @ request time within handler method.

is there way go on using autoload, still set environment variable in apache config available in perl's %env @ module load time?

minimal example:

here's stripped downwards test-case illustrate problem.

the apache config without autoload enabled:

perlswitches -i/home/day/modperl <location /perl> sethandler modperl perlsetenv test_perlsetenv 'does work?' perlresponsehandler modperl::test allow </location>

contents of /home/day/modperl/modperl/test.pm:

package modperl::test; utilize strict; utilize warnings; utilize apache2::requestrec (); utilize apache2::requestio (); utilize apache2::const qw(ok); %env_at_module_load = %env; # take re-create sub handler { $r = shift; $r->content_type('text/plain'); $r->print("env:\n"); foreach $key (sort keys %env) { $r->print(" $key: $env{$key}\n"); } $r->print("env_at_module_load:\n"); foreach $key (sort keys %env_at_module_load) { $r->print(" $key: $env_at_module_load{$key}\n"); } homecoming ok; } 1;

when localhost/perl viewed in browser, see this:

env: mod_perl: mod_perl/2.0.5 mod_perl_api_version: 2 path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin test_perlsetenv: work? env_at_module_load: mod_perl: mod_perl/2.0.5 mod_perl_api_version: 2 path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin test_perlsetenv: work?

hooray! test_perlsetenv available @ module load time, want.

but when alter apache config enable autoload (by using + in perlresponsehandler so):

perlresponsehandler +modperl::test

i next output instead:

env: mod_perl: mod_perl/2.0.5 mod_perl_api_version: 2 path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin test_perlsetenv: work? env_at_module_load: mod_perl: mod_perl/2.0.5 mod_perl_api_version: 2 path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

boo! test_perlsetenv no longer available @ module load time :( how can while keeping autoload behaviour?

argh, 30 seconds after posting question, found answer. give thanks rubber duck.

move perlsetenv before <location> block contains perlresponsehandler directive, , works again!

i.e. this:

perlswitches -i/home/dbarr/modperl perlsetenv test_perlsetenv 'does work?' <location /perl> sethandler modperl perlresponsehandler +modperl::test allow </location>

perl apache mod-perl2

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -