Stas Bekman wrote:
> Apache-Test automagically assigns port numbers to vhost sections, e.g.:
>
> <VirtualHost myhost>
> PerlSetVar foo bar
> </VirtualHost>
>
> is expanded to:
>
> Listen 0.0.0.0:8530
> <VirtualHost _default_:8530>
> ServerName lapin.stason.org:8530
> PerlSetVar foo bar
> </VirtualHost>
>
> But what if I need to use <Perl> inside Vhost, since some values require
> a code to be run? If I do:
>
> <Perl>
> my $val = get_val();
> $VirtualHost{myhost} = {
> PerlSetVar => ["foo", $bar],
> }
> </Perl>
$val != $bar ??
> A-T won't know to expand it. On the other hand, doing:
>
> <VirtualHost myhost>
> <Perl>
> my $val = get_val();
> $PerlSetVar = ["foo", $bar];
> </Perl>
> /VirtualHost>
That should be:
$PerlSetVar = "foo $val";
And seems to work for me.
<Location /test-gozer>
PerlHandler My::Gozer
SetHandler perl-script
</Location>
PerlSetVar gozer "doesn't rule"
<VirtualHost gozer>
<Perl>
$PerlSetVar = 'gozer rules';
sub My::Gozer::handler {
my $r = shift;
$r->send_http_header('text/plain');
$r->print("Gozer " . $r->dir_config("gozer") . "\n");
return Apache2::Const::OK;
}
</Perl>
</VirtualHost>
$> t/TEST -start
waiting 120 seconds for server to start: ok (waited 13 secs)
server localhost:8529 started
server localhost:8530 listening (filter_out_apache)
server localhost:8531 listening (gozer)
[...]
$> GET http://localhost:8529/test-gozer
Gozer doesn't rule
$> GET http://localhost:8531/test-gozer
Gozer rules
> is not putting the config into the right vhost (it goes to the top-level
> config.
>
> The only tricky way I've managed to enjoy the both worlds, is using
> add_config:
>
> <Perl>
> use Apache2::ServerUtil ();
> my $val = get_val();
> Apache2::ServerUtil->server->add_config([split /\n/, <<EOI]);
> # t/limit/maxx_conn.t
> <VirtualHost myhost>
> PerlSetVar foo $var
> </VirtualHost>
> EOI
>
> </Perl>
$val != $var again ;-)
> I don't see how we can make A-T aware of <Perl> in any other ways. Ideas?
The correct way would seem to be
<VirtualHost>
[...]
<Perl>
[...]
</Perl>
[...]
</VirtualHost>
And it seems to be working.
--
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
signature.asc
Description: OpenPGP digital signature
