Paul G. Weiss wrote:
Let me see if I have this straight.

With your patch, if I have:

PerlPostConfigHandler A
<VirtualHost one>
PerlPostConfigHandler B
</VirtualHost>
<VirtualHost two>
PerlPostConfigHandler C
</VirtualHost>

then A gets run once, B gets run once, and C gets run once.

But if I have:

PerlPostConfigHandler A
<VirtualHost one>
</VirtualHost>
<VirtualHost two>
PerlPostConfigHandler C
</VirtualHost>

then A gets run twice (once for the main server and once for the vhost) and C gets run once?

That's right.


If so, that would be even more confusing, and any author of a PostConfigHandler would need to make sure that the code is safe if run for each vhost. I think that would cause more problems than it would solve.

Agreed.


In my case a better solution would be to write a PerlPostConfigHandler that walked the config tree and did the right thing for each vhost. In the case of Apache::PageKit, Boris Zenter has already posted a workaround. An alternative to that would be something like this:

PerlPostConfigHandler PageKitHandler::handle
<VirtualHost one>
PerlSetVar PKIT_ROOT onevalue
PerlSetVar PKIT_SERVER serverone
</VirtualHost>
<VirtualHost one>
PerlSetVar PKIT_ROOT twovalue
PerlSetVar PKIT_SERVER servervalue
</VirtualHost>

sub handle {
my $tree = Apache::Directive->conftree;
my @pkitroots = $tree->lookup('PerlSetVar', 'PKIT_ROOT');
foreach my $node (@pkitroots) {
my $rootvalue = $node->args->[1];
my $servervalue;
my $sib = $node->parent->first_child;
while ($sib) {
if (lc $sib->directive eq 'perlsetvar' && $sub->args->[0] eq 'PKIT_SERVER') {
$servervalue = $sub->args->[1];
last;
}
$sib = $sib->next;
}
Apache::PageKit->startup($rootvalue, $servervalue);
}


In other words, look for places where PKIT_ROOT is set and then look up the value of PKIT_SERVER set in the same scope, and call Apache::PageKit->startup with both args.

Actually this doesn't quite work because if PKIT_SERVER is inherited from an enclosing scope, then the code above won't find it -- it really should recurse upward on the parent if it doesn't find a value for PKIT_SERVER. Furthermore, it doesn't consider PerlAddVar. It would be nice if Apache::Directive was extended so that one could do the equivalent of $node->dir_config("value").

You don't need to walk the config tree to accomplish that. There is a much simpler way:


sub post_config {
    my($conf_pool, $log_pool, $temp_pool, $s) = @_;

    for (my $vhost_s = $s->next; $vhost_s; $vhost_s = $vhost_s->next) {
        my $port = $vhost_s->port;
        my $val = $vhost_s->dir_config->{PostConfig};
        warn "port: $port, val $val\n";
    }
    ...

As you can see you can traverse the linked list of all vhost entries. And you get all the overrides (e.g. PerlAddVar) considered.


__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com


-- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html



Reply via email to