I've looked at the mod_perl documentation on how to eliminate the problem of values being remembered when a named inner subroutine accesses a lexical symbol. I *thought* I was doing things correctly, but when I precompile (or even preload) CGI, I get the same types of problems, regardless.
Looks to me like the problem is not about CGI, but about the way you are using lexical variables. You have created two closures.
My/Form.pm: package My::Form; use strict; use CGI; use base 'Exporter'; our @EXPORT = 'dojob';
my $foo; my $q;
Get rid of those two lines. They are turning the other subs into closures.
sub do_work {
print "<html><body><form><input type=\"text\" name=\"foo\" value=\"$foo\"><br><input type=\"submit\"></form></body></html>";
}
Should be:
sub do_work {
my $foo = shift;
print "<html><body><form><input type=\"text\" name=\"foo\" value=\"$foo\"><br><input type=\"submit\"></form></body></html>";
}
sub dojob { my $q = new CGI; $foo = $q->param('foo'); print "Content-type: text/html\n\n"; do_work($foo); }
That will be fine, once you remove the declaration of $q above. You should be seeing a warning in your logs about this ($q masks earlier variable...). Turn on warnings, if you haven't already.
- Perrin
-- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html