Greetings,
I'm trying use custom directives during a BEGIN block of one of my
modules so that I can use the directive as a configuration parameter for
a singleton in the handler package.
I use Apache2::ServerUtil->server to get the server object during the
BEGIN block and run $cfg = Apache2::Module::get_config(__PACKAGE__,
Apache2::ServerUtil->server) to grab the MyVarOne value to create the
singleton but $cfg is undef during startup...
get_config() works normally though during invocation in a handler()
where I use $r->server for the server object, $cfg returns the proper value.
Here's the code I'm using. I'm guessing that get_config() may not
return what I'm looking for during startup since it functions properly
at runtime. Any ideas? $pkg_global will be a template object, which is
why I want to construct it during startup. I can make a new object with
each handler call but I was hoping to avoid that.
TIA,
- Fred
-----------------
t/conf/extra.last.conf.in
PerlModule My::TestHandler
MyVarOne '/a/filepath'
<Location /test>
SetHandler modperl
PerlResponseHandler My::TestHandler
</Location>
-------------------------
lib/My/TestHandler
package My::TestHandler;
use strict;
use warnings;
use Apache2::Const -compile => qw( OK );
use Apache2::RequestIO ();
use Apache2::Log ();
use Data::Dumper;
my $pkg_global;
BEGIN {
use Apache2::Module;
use Apache2::CmdParms;
my @directives = (
{
name => 'MyVarOne',
errmsg => 'varone errmsg',
args_how => 'ITERATE',
req_override => 'OR_ALL',
},
);
Apache2::Module::add(__PACKAGE__, [EMAIL PROTECTED]);
use Apache2::ServerUtil;
my $s = Apache2::ServerUtil->server;
my $cfg = Apache2::Module::get_config(__PACKAGE__, $s);
print STDERR "Config: " . Dumper($cfg); # $cfg is undef during startup
$pkg_global = $cfg;
}
sub handler {
my $r = shift;
my $cfg = Apache2::Module::get_config(__PAKAGE__, $r->server);
$r->log->debug("Config from handler: " . Dumper($cfg)); # <=== this
one works properly
$r->content_type('text/plain');
$r->print('testhandler');
return Apache2::Const::OK;
}
sub MyVarOne {
my ($cfg, $parms, $args) = @_;
$cfg->{_myvarone} = $args;
}
1;
-----------------
t/01handler.t
#!perl
use strict;
use warnings FATAL => 'all';
use Apache::Test;
use Apache::TestRequest;
plan tests => 1;
my $uri = '/test';
my $res = GET $uri;
ok $res->is_success;