I'm including an abuse of the mechanism in a separate comment, because it is not directly related to the tutorial.
use strict;
use warnings;
my $foo = 5;
print "Content-type: text/plain\n";
print "Content-disposition: inline; filename=foo.txt\n\n";
printf "Package: %s\n", __PACKAGE__;
printf "[%s] Before: %s\n", $$, $foo;
goodness(5);
printf "[%s] After: %s\n", $$, $foo;
}
sub goodness {
my $val = shift;
printf "[%s] goodness: %s\n", $$, $foo;
$foo += $val;
Which Apache::Registry will turn into this:
package Apache::ROOTfoo_2ecom::test_2epl;
use Apache qw(exit);
sub handler {
#line 1 /www/foo.com/test.pl
use strict;
use warnings;
my $foo = 5;
print "Content-type: text/plain\n";
print "Content-disposition: inline; filename=foo.txt\n\n";
printf "Package: %s\n", __PACKAGE__;
printf "[%s] Before: %s\n", $$, $foo;
goodness(5);
printf "[%s] After: %s\n", $$, $foo;
}
sub goodness {
my $val = shift;
printf "[%s] goodness: %s\n", $$, $foo;
$foo += $val;
}
By adding an extra '}' before the
sub goodness declaration we are really closing
sub handler {, and then at the end of the script we leave off the closing '}', since one will be added by Apache::Registry.