List,
I want to access the server configuration of a virtual host from a
module loaded via PerlPostConfigRequire after the config phase is done
but before the server is ready to serve requests.
In a main server that would be no problem. One could use
the PerlPostConfigHandler MyApp::Foo.
This, however, will not work for VirtualHost as I learned from some
earlier posts on this list.
One possibility I can see is to define a perl section in the virtual
host that sets some variable that identifies the virtual host section
(e.g. the name of the virt host)
Then from the module one could do $s->next to walk through all the
servers and compare the server name of each $s stuff with the
value of the just set variable.
See:
<VitualHost *:6666>
ServerName server6666
<Perl>
$virtHost = 'server6666'
$Apache2::PerlSections::Save = 1;
</Perl>
PerlPostConfigRequire MyApp/Foo.pm
…
</VirtualHost>
MyApp::Foo then should have the following:
...
my $virtHost;
my $dump = Apache2::PerlSections->dump;
eval($dump);
# Then
print STDERR "MyApp::Foo called in virtual host section $vistHost \n";
# would write to the error log the value of $virtHost set in the appropriate PerlSection.
This soution, however, limits the usage of <Perl> sections in my virtual host.
That is not a particular problem for me right now but might be later.
For record: I'm using apache 2.2 modperl 2.0.2.
Is there any straightforward way?
Thanks,
--Attila