>>>>> "PH" == Perrin Harkins <[EMAIL PROTECTED]> writes:
PH> Hmmm... If I'm reading the code correctly, what's supposed to happen is
PH> that the stash (where your plugin instance lives) gets localized when you
PH> call $tt->process() and de-localized at the end, which should result in
PH> anything you added to it (with your USE s = session) getting DESTROY-ed.
Ok... here's a mini-plugin that exhibits this behavior, and a command
line script for it. My mod_perl handler is essentially the same as
the command line script, except that $tt is a package "my" variable,
and the $tt->process() is called from the package handler() method.
In mod_perl, I change the goober object's "print" to "warn" so they go
to the error_log file. The destroy message only shows up when httpd
exits.
Does anyone else have issues with TT plugin objects not getting
destroyed under the mod_perl environment? It works as expected in the
command line version below. That is, after process() finishes, the
object goes away.
TT version 2.0
mod_perl 1.24_02-dev
Apache 1.3.14
FreeBSD 4.2-STABLE (from Jan 29)
My/goober.pm:
--cut here--
#! /usr/bin/perl
package My::goober;
use strict;
use base qw( Template::Plugin );
sub new {
my $class = shift;
my $context = shift;
my $id = rand;
print "creating goober object $id\n";
return bless { id => $id, _CONTEXT => $context }, $class;
}
sub DESTROY {
my $self = shift;
print "goober object $self->{id} destroyed\n";
}
1;
--cut here--
and the script to run it on command line:
--cut here--
#!/usr/bin/perl -w
use strict;
use Template;
$| = 1;
my $tt =
Template->new({
PLUGIN_BASE => 'My',
POST_CHOMP => 1,
PRE_CHOMP => 1,
VARIABLES => {
foo => 'hi!',
},
}
)
or die "Template::new failure";
my $template = <<"EOT";
[% USE g = goober %]
...template output...
[% foo %]
EOT
print "Starting to process template\n";
$tt->process(\$template,undef) or die $tt->error();
print "Template processing done\n";
--cut here--
here's my mod_perl handler:
--cut here--
#! /usr/bin/perl
package MLM::MLMhandler;
use strict;
use 5.005;
use Apache::Constants qw(OK DECLINED NOT_FOUND SERVER_ERROR);
use vars qw($Debug $VERSION);
$Debug ||= 0;
BEGIN {
$VERSION = do { my @r=(q$Revision: 0.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r
};
}
use Template;
use Apache::Util;
my $tt =
Template->new({
PRE_PROCESS => 'header.tt',
POST_PROCESS => 'footer.tt',
DEFAULT => 'notfound.html',
ABSOLUTE => 1,
INCLUDE_PATH =>
'/home/khera/proj/vk-mlm/website/docs/_templates:/home/khera/proj/vk-mlm/website/docs',
PLUGIN_BASE => 'MLM::Plugins',
VARIABLES =>
{
time2str => sub {
return Apache::Util::ht_time(($_[1]||time),($_[0]||'%c'),0);
},
},
})
or die "Template::new failure";
sub handler {
my($r) = @_;
# only works on main request
return DECLINED unless ($r->is_main());
my $subr = $r->lookup_uri($r->uri); # uri is relative to doc root
my $fileName = $subr->filename; # absolute file name
return NOT_FOUND unless -f $fileName; # file not found
# return DECLINED unless -T _; # not a text file
# send headers to the client
$r->send_http_header('text/html');
return OK if $r->header_only(); # HEAD request, so skip out early!
Apache->request($r); # plugins might need it
$tt->process($fileName, undef, $r)
or do { warn $tt->error(); return SERVER_ERROR; };
return OK;
}
1;
--cut here--