You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Larry Leszczynski <la...@furph.com> on 2003/02/17 19:33:19 UTC
Trouble using dir_config for PerlSetVar inside Perl section
Hi all -
I'm having trouble using server->dir_config in my startup.pl to read
variables set by PerlSetVar inside a Perl section. I'm using Perl 5.6.1,
Apache 1.3.27, and mod_perl 1.27.
In startup.pl I have:
my $file = Apache->server->dir_config("CFG") || "";
warn "Missing path to config file in httpd.conf" unless $file;
In httpd.conf, this works just fine:
PerlSetVar CFG /path/to/file
PerlRequire startup.pl
and this works fine too:
PerlSetVar CFG /path/to/file
<Perl>
$PerlRequire = "startup.pl";
</Perl>
But this does not work (CFG is not set in startup.pl):
<Perl>
push @{$Location{"/"}->{PerlSetVar}}, ["CFG", "/path/to/file"];
</Perl>
PerlRequire startup.pl
and this does not work either:
<Perl>
push @{$Location{"/"}->{PerlSetVar}}, ["CFG", "/path/to/file"];
$PerlRequire = "startup.pl";
</Perl>
It seems like this should work, right? I'm pretty sure the syntax of the
"push" is OK because if I modify the syntax I get a message:
(2)No such file or directory: <Perl>: PerlSetVar takes two arguments,
Perl config var and value
Thanks,
Larry Leszczynski
larryl@furph.com
Re: Trouble using dir_config for PerlSetVar inside Perl section
Posted by Larry Leszczynski <la...@furph.com>.
Hi Geoff -
> > and this does not work either:
> > <Perl>
> > push @{$Location{"/"}->{PerlSetVar}}, ["CFG", "/path/to/file"];
> > $PerlRequire = "startup.pl";
> > </Perl>
>
[snip]
>
> what may be happening is that your dynamic configuration may be putting your
> PerlSetVar into a per-directory scope instead of a per-server scope, since
> your config is now in a <Perl> section. meaning, Apache->server->dir_config
> is (rightfully) empty because now your configuration is in
> Apache->request->dir_config. of course, you can't get at $r->dir_config at
> startup, so you're pretty much SOL.
>
> try looking at $r->dir_config('CFG') in a request and see if your value is
> there. if it is, then I guess my theory is right, and there is little that
> can be done about it.
Thanks, you're right about what is happening. Since I need to set the
config file path dynamically in httpd.conf and I need to access it in
startup.pl, I ended up using an environment variable instead:
PerlPassEnv CFG
<Perl>
$ENV{CFG} ||= "/path/to/file";
$PerlRequire = "startup.pl";
</Perl>
I had to use PerlPassEnv outside the Perl section - using something like:
push @PerlSetEnv, ["CFG", "/path/to/file"];
inside the Perl section seems to have the same issues with per-directory
scope as PerlSetVar.
Thanks,
Larry
Re: Trouble using dir_config for PerlSetVar inside Perl section
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Larry Leszczynski wrote:
> Hi all -
>
> I'm having trouble using server->dir_config in my startup.pl to read
> variables set by PerlSetVar inside a Perl section. I'm using Perl 5.6.1,
> Apache 1.3.27, and mod_perl 1.27.
>
[snip]
>
> and this does not work either:
> <Perl>
> push @{$Location{"/"}->{PerlSetVar}}, ["CFG", "/path/to/file"];
> $PerlRequire = "startup.pl";
> </Perl>
>
> It seems like this should work, right?
you may be running into an odditity of PerlSetVar. internally, mod_perl has
logic to merge per-server and per-directory PerlSetVar attributes, doing it
itself instead of relying on Apache. while this is good under most
circumstances, I think you've uncovered someplace where it doesn't work as
well as you'd like.
what may be happening is that your dynamic configuration may be putting your
PerlSetVar into a per-directory scope instead of a per-server scope, since
your config is now in a <Perl> section. meaning, Apache->server->dir_config
is (rightfully) empty because now your configuration is in
Apache->request->dir_config. of course, you can't get at $r->dir_config at
startup, so you're pretty much SOL.
try looking at $r->dir_config('CFG') in a request and see if your value is
there. if it is, then I guess my theory is right, and there is little that
can be done about it.
HTH
--Geoff