Set "last-modified" header based on tt template
# when you want to set the "Last-Modified" header manually
use base qw(CGI::Application);
use CGI::Application::Plugin::TT;
use CGI::Application::Plugin::TT::LastModified;
sub my_runmode {
my $self = shift;
my %params = (
...
);
my $html = $self->tt_process( 'template.html', \%params );
$self->tt_set_last_modified_header();
return $html;
}
# when you want the "Last-Modified" header set automatically
use base qw(CGI::Application);
use CGI::Application::Plugin::TT;
use CGI::Application::Plugin::TT::LastModified qw(:auto);
sub my_runmode {
my $self = shift;
my %params = (
...
);
return $self->tt_process( 'template.html', \%params );
}
\*(C`CGI::Application::Plugin::TT::LastModified\*(C' adds support to \*(C`CGI::Application\*(C' for setting a \*(L"Last-Modified\*(R" header based on the most recent modification time of any of the components of a template that was processed with \s-1TT\s0.
Normally you'll want to call it manually, on as \*(L"as needed\*(R" basis; if you're processing templates with \s-1TT\s0 you're most likely dealing with dynamic content (in which case you probably don't even want a \*(L"Last-Modified\*(R" header). The odd time you'll want to set a \*(L"Last-Modified\*(R" header, though, this plugin helps make that easier.
If you have a desire to have the \*(L"Last-Modified\*(R" header set automatically for you, though, \*(C`CGI::Application::Plugin::TT::LastModified\*(C' does have an \*(C`:auto\*(C' import tag which auto-registers \*(L"tt_set_last_modified_header()\*(R" as a \*(L"tt_post_process\*(R" hook for you. If you've got an app that just processes static \s-1TT\s0 pages and generates output, this'll be useful for you.
Custom import routine, which allows for \*(C`tt_set_last_modified_header()\*(C' to be auto-added in as a \s-1TT\s0 post process hook.
Returns the most recent modification time for any component of the most recently processed template (via \*(C`tt_process()\*(C'). Time is returned back to the caller as \*(L"the number of seconds since the epoch\*(R".
Sets a \*(L"Last-Modified\*(R" header in the \s-1HTTP\s0 response, equivalent to the last modification time of the template components as returned by \*(C`tt_last_modified()\*(C'.
Graham TerMarsch ([email protected])
Copyright (C) 2007, Graham TerMarsch. All Rights Reserved.
This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
CGI::Application::Plugin::TT, CGI::Application, Template.