Sorry if this is a re-post. I had some list subscription trouble.
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Paul
> LeoNerd Evans
> Sent: Monday, February 27, 2006 8:20 PM
> To: [email protected]
> Subject: [Templates] Hooking into template file accesses
>
[snip]
>
> 2. It tracks the latest mtime of any file (or other data) used
during
> the building of the page, in order to set the "Last_Modified:"
> header on reply and to implement the "If_Modified_Since:" logic.
You could subclass Template::Provider::fetch and add your mtime checking
code to it. (*untested code*) e.g.
package My::Mtime::Provider;
use base qw(Template::Provider);
sub init_mtime {
my ($self) = @_;
$self->{_my_mtime} = 0;
}
sub check_mtime {
my ($self,$doc) = @_;
# remember this mtime if it's newer than
# anything else we've seen
if ($doc && $doc->modtime > $self->{_my_mtime}) {
$self->{_my_mtime} = $doc->modtime;
}
}
sub get_mtime {
my ($self) = @_;
return $self->{_my_mtime};
}
sub fetch {
my $self = shift;
my ($doc,$reason) = $self->SUPER::fetch(@_);
$self->check_mtime($doc);
return ($doc,$reason);
}
1;
Then you install the provider like this:
my %config = ( COMPILE_DIR => '/wherever', @other_opts );
my $provider = My::Mtime::Provider->new(\%config);
my $template = Template->new(%config,
LOAD_TEMPLATES => [$provider]);
Then, every time you process a template, do this:
$provider->init_mtime();
$template->process($template_name) || die $template->error;
my $mtime = $provider->get_mtime();
I hope the code doesn't have too many bugs in it.
HTH
Philip
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates