Hello,
I am seeing a wierd problem that sounds kind of like, but not exactly
like the sharing of lexical variables between inner and outer
subroutines as discussed on pages 161-162 of Apache Modules (the eagle
book).
I am writing a mirror proxy and re-writing links on any document of
content-type text. The module is humming along just fine, and suddenly
the value of one of the variables in the HTML::Parser callback will
change back to a value it held several invocations earlier when it was
parsing a completely different document with a compltely different URI.
Here's the
basic setup:
sub handler {
my $r = shift;
< lot's of stuff cut >
parse_response($proxy_uri, # original URI up thru $r->filename
$proxied_host, # host handler sent request to
$proxied_path, # proxied filename
$response->content # response content
);
< some more stuff cut >
return OK;
}
sub parse_response {
my($proxy_uri, $proxied_host, $proxied_path, $html_response) = @_;
< some stuff cut >
my $p = HTML::Parser->(api_version=>3,
start_h => [\$process_tag,
"tagname,
tokenpos,
text"],
default => [sub{print @_;}, "text"]);
$p->unbroken_text;
$p->parse($html_response);
sub process_tag {
my($tagname, $pos, $text) = @_;
< process the tag >
}
}
Inside "sub process_tag" (a callback handler)the content of of the
variables $proxied_host and $proxied_path all the sudden like revert
back to a value held in the previous invocation of the content handler.
$proxy_uri probably suffered the same fate, but since it's value is
generally the same between invocations there's no easy way to tell.
The other peculiarity is that the problem doesn't show up immediately.
The parent subroutine (sub parse_response) will already be some number
of tags into the response when the variables revert. On the other hand,
the problem as discribed in the eagle book suggests I would see the
problem immediately. Also, these variables are not lexically scoped
inside the start tag callback handler. They are scoped in the parent
parse_response subroutine, the callback handler being lexically within
the scope of its parent.
The result is: I am really confused. If this is that same problem, do
I need to declare those variables globally in the content handler? Or
would changing to a $p->handler(start => sub { ... }, "x, y, z");
anonymous mechanism do as well. Or worse yet, is this problem something
entirely different?
Thanks,
Rob
--
_ _ _ _ _ _ _ _ _ _
/\_\_\_\_\ /\_\ /\_\_\_\_\_\
/\/_/_/_/_/ /\/_/ \/_/_/_/_/_/ QUIDQUID LATINE DICTUM SIT,
/\/_/__\/_/ __ /\/_/ /\/_/ PROFUNDUM VIDITUR
/\/_/_/_/_/ /\_\ /\/_/ /\/_/
/\/_/ \/_/ /\/_/_/\/_/ /\/_/ (Whatever is said in Latin
\/_/ \/_/ \/_/_/_/_/ \/_/ appears profound)
Rob Tanner
McMinnville, Oregon
[EMAIL PROTECTED]