I'm having a really strange (in my opinion) problem with Perl sections and
using the Apache::ReadConfig namespace explicitly (qualifying variables,
like %Apache::ReadConfig::Location). Here's what I'm doing: I have a small
library of routines; I'm using PerlRequire to load that library. In a Perl
section, I'm then calling a routine from that library that should alter
%Apache::ReadConfig::Location. When I dump out the ReadConfig namespace,
though (using PerlSections->dump), there's nothing in %Location.
*However*, and this is the weird part, this only happens if I don't have a
Perl section before the PerlRequire statement. This will be demonstrated
below.
I have a small test case. Here's the library, called 'foo.pl':
package Foo;
sub bar {
$Apache::ReadConfig::Location{"/foo"} = {
Options => 'ExecCGI',
};
}
1;
Here's the relevant portion of my httpd.conf, where the PerlRequire is
before the first Perl section:
PerlRequire conf/foo.pl
<Perl>
use Apache::PerlSections;
Foo::bar();
print STDERR Apache::PerlSections->dump;
</Perl>
Here's the output of starting up the webserver with that configuration file
(I compiled with PERL_TRACE on):
PerlRequire: arg=`conf/foo.pl'
attempting to require `conf/foo.pl'
loading perl module 'Apache'...ok
loading perl module 'Apache::Constants::Exports'...ok
loading perl module 'Tie::IxHash'...ok
perl_section: </Files>
perl_section: </Directory>
perl_section: </Files>
perl_section: </Directory>
perl_section: </VirtualHost>
perl_section: </Location>
perl_section: </Location>
loading perl module 'Apache'...ok
loading perl module 'Tie::IxHash'...ok
package Apache::ReadConfig;
#scalars:
#arrays:
#hashes:
1;
__END__
perl_section: </Files>
perl_section: </Directory>
perl_section: </Files>
perl_section: </Directory>
perl_section: </VirtualHost>
perl_section: </Location>
perl_section: </Location>
Nothing in the Apache::ReadConfig namespace, as you can see.
Now, here's the *working* webserver configuration, with a (blank) Perl
section coming before the PerlRequire:
<Perl>
</Perl>
PerlRequire conf/foo.pl
<Perl>
use Apache::PerlSections;
Foo::bar();
print STDERR Apache::PerlSections->dump;
</Perl>
And here's the output:
loading perl module 'Apache'...ok
loading perl module 'Apache::Constants::Exports'...ok
loading perl module 'Tie::IxHash'...ok
perl_section: </Files>
perl_section: </Directory>
perl_section: </Files>
perl_section: </Directory>
perl_section: </VirtualHost>
perl_section: </Location>
perl_section: </Location>
PerlRequire: arg=`conf/foo.pl'
attempting to require `conf/foo.pl'
loading perl module 'Apache'...ok
loading perl module 'Tie::IxHash'...ok
package Apache::ReadConfig;
#scalars:
#arrays:
#hashes:
%Location = (
'/foo' => {
'Options' => 'ExecCGI'
}
);
1;
__END__
perl_section: </Files>
perl_section: </Directory>
perl_section: </Files>
perl_section: </Directory>
perl_section: </VirtualHost>
perl_section: </Location>
perl_section: <Location /foo>
Options ExecCGI (OK) Limit=no
perl_section: </Location>
In other words, it works as expected when the blank Perl section is added
before the PerlRequire. So what seems to be happening--and I don't know the
internals side of this, so I'm just making guesses--is that the first Perl
section initializes the Apache::ReadConfig namespace, including the
%Location hash. Without this initialization, an explicit use of
%Apache::ReadConfig::Location seems to be... broken.
And that's as far as I can go with it. :)
So what I'd really like, if possible, is an explanation for this behavior;
adding the blank Perl section seems to provide a useable workaround, but I'd
like to know *why* this is happening.
Thanks all.
bye,
Benjamin Trott