----- Forwarded message from Rick Myers <[EMAIL PROTECTED]> -----
Date: Fri, 4 Jan 2002 20:19:23 -0500
From: Rick Myers <[EMAIL PROTECTED]>
To: Andy Wardley <[EMAIL PROTECTED]>
Subject: Apache::Template merging
Hi,
I think I've found something not quite right in the AT merge
routine (and maybe even a mod_perl/Apache bug -- who knows).
Cutting to the chase...
TT2PreProcess global
<VirtualHost x.x.x.x>
TT2PreProcess v1
</VirtualHost>
<VirtualHost x.x.x.x>
TT2PreProcess v2
</VirtualHost>
That works per TT documentation. (Of course I didn't find
the document until after I sorted through the code for a
while. But so it goes. :)
Anyway, let's say you don't set up a global at all. Just
comment out the global and you'd think that each virtual
would just use their own settings and go about their merry
way. Bzzzt. Wrong answer.
What really happens is that the DIR_MERGE routine gets
called anyway for each virtual, even though there's nothing
really to merge it with. Or so you would think. In fact,
DIR_MERGE is called with its two arguments being references
to the same object. In other words, it's being asked to
merge with itself.
The result of all this is that through the magic of AT's
cumulative settings you wind up with all your virtual hosts
calling all their preprocesses twice. Same with
postprocesses. Not good.
So, here's a suggestion which I've tested only a few times,
and then only on 5.6.1 with latest stable modules. It looks
harmless enough and handles the "just global", "just
virtual", and "global+virtual".
--- Template.pm.orig Fri Jan 4 17:27:05 2002
+++ Template.pm Fri Jan 4 18:36:24 2002
@@ -417,6 +417,11 @@
sub _merge {
my ($parent, $config) = @_;
+
+ # let's not merge with ourselves.
+ # it's not.. umm.. natural.
+ return $config if $parent eq $config;
+
my $merged = bless { }, ref($parent);
foreach my $key (keys %$parent) {
if(!ref $parent->{$key}) {
FWIW, I put this in _merge because in theory SERVER_MERGE
(as opposed to SERVER_MERGER in your code base) would have
the same problem. Unfortunately, I don't think that hook
even really exists in mod_perl-1.xx.
Rick Myers [EMAIL PROTECTED]
----------------------------------------------------
The Feynman Problem 1) Write down the problem.
Solving Algorithm 2) Think real hard.
3) Write down the answer.