Fred Moyer wrote:
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.

Aha - simple solution is use the first instance of get_config() in the handler and cache it. Sorry for the noise - got caught up in 'why isnt it working when maybe it should'. Still a bit curious why it doesn't work with a ServerUtil->server object during startup, should any one familiar with the details care to indulge me I would be delighted.

-----------------

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;

Reply via email to