CGI-Application-Plugin-TT-LastModified-1.02/0000755000076400007640000000000011365144533017717 5ustar grahamgrahamCGI-Application-Plugin-TT-LastModified-1.02/Changes0000444000076400007640000000037111365144533021211 0ustar grahamgrahamRevision history for Perl extension CGI::Application::Plugin::TT::LastModified: 1.02 Fri Apr 23 22:26 PDT 2010 - Switch to Git 1.01 Tue Apr 28 10:43 PDT 2009 - typo fix in POD 1.00 Sun Sep 30 17:51 PDT 2007 - initial version CGI-Application-Plugin-TT-LastModified-1.02/MANIFEST.SKIP0000444000076400007640000000007011365144533021610 0ustar grahamgrahamBuild _build/ .git/ \..*\.swp blib/ Makefile pm_to_blib CGI-Application-Plugin-TT-LastModified-1.02/META.yml0000444000076400007640000000107011365144533021164 0ustar grahamgraham--- name: CGI-Application-Plugin-TT-LastModified version: 1.02 author: - Graham TerMarsch (cpan@howlingfrog.com) abstract: Set "Last-Modified" header based on TT template license: perl resources: license: ~ requires: CGI::Application: 4 CGI::Application::Plugin::TT: 0 CGI::Util: 0 List::Util: 0 provides: CGI::Application::Plugin::TT::LastModified: file: lib/CGI/Application/Plugin/TT/LastModified.pm version: 1.02 generated_by: Module::Build version 0.32 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 CGI-Application-Plugin-TT-LastModified-1.02/t/0000755000076400007640000000000011365144533020162 5ustar grahamgrahamCGI-Application-Plugin-TT-LastModified-1.02/t/auto-last-modified.t0000444000076400007640000000052111365144533024032 0ustar grahamgrahamuse strict; use warnings; use Test::More tests => 2; use lib 't/lib'; BEGIN { use_ok( 'TestApp::AutoLastModified' ); }; # set up CGI:App for testing $ENV{CGI_APP_RETURN_ONLY} = 1; # run our test my $app = TestApp::AutoLastModified->new(); my $res = $app->run(); like( $res, qr/^Last-Modified:/mi, 'Last-Modified header present' ); CGI-Application-Plugin-TT-LastModified-1.02/t/last-modified.t0000444000076400007640000000051111365144533023063 0ustar grahamgrahamuse strict; use warnings; use Test::More tests => 2; use lib 't/lib'; BEGIN { use_ok( 'TestApp::LastModified' ); }; # set up CGI:App for testing $ENV{CGI_APP_RETURN_ONLY} = 1; # run our test my $app = TestApp::LastModified->new(); my $res = $app->run(); like( $res, qr/^Last-Modified:/mi, 'Last-Modified header present' ); CGI-Application-Plugin-TT-LastModified-1.02/t/pod.t0000444000076400007640000000020111365144533021120 0ustar grahamgrahamuse Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); CGI-Application-Plugin-TT-LastModified-1.02/t/pod-coverage.t0000444000076400007640000000023011365144533022713 0ustar grahamgrahamuse Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD" if $@; all_pod_coverage_ok(); CGI-Application-Plugin-TT-LastModified-1.02/t/plain.t0000444000076400007640000000047711365144533021460 0ustar grahamgrahamuse strict; use warnings; use Test::More tests => 2; use lib 't/lib'; BEGIN { use_ok( 'TestApp::Plain' ); }; # set up CGI:App for testing $ENV{CGI_APP_RETURN_ONLY} = 1; # run our test my $app = TestApp::Plain->new(); my $res = $app->run(); unlike( $res, qr/^Last-Modified/mi, 'no Last-Modified header present' ); CGI-Application-Plugin-TT-LastModified-1.02/t/templates/0000755000076400007640000000000011365144533022160 5ustar grahamgrahamCGI-Application-Plugin-TT-LastModified-1.02/t/templates/bottom.html0000444000076400007640000000002011365144533024340 0ustar grahamgraham CGI-Application-Plugin-TT-LastModified-1.02/t/templates/index.html0000444000076400007640000000010011365144533024142 0ustar grahamgraham[% INCLUDE 'top.html' %] Woo-hoo! [% INCLUDE 'bottom.html' %] CGI-Application-Plugin-TT-LastModified-1.02/t/templates/top.html0000444000076400007640000000001611365144533023643 0ustar grahamgraham CGI-Application-Plugin-TT-LastModified-1.02/t/lib/0000755000076400007640000000000011365144533020730 5ustar grahamgrahamCGI-Application-Plugin-TT-LastModified-1.02/t/lib/TestApp/0000755000076400007640000000000011365144533022310 5ustar grahamgrahamCGI-Application-Plugin-TT-LastModified-1.02/t/lib/TestApp/AutoLastModified.pm0000444000076400007640000000033411365144533026041 0ustar grahamgrahampackage TestApp::AutoLastModified; use strict; use base qw(TestApp::base); use CGI::Application::Plugin::TT::LastModified qw(:auto); sub test { my $self = shift; return $self->tt_process( 'index.html' ); } 1; CGI-Application-Plugin-TT-LastModified-1.02/t/lib/TestApp/Plain.pm0000444000076400007640000000030711365144533023707 0ustar grahamgrahampackage TestApp::Plain; use strict; use base qw(TestApp::base); use CGI::Application::Plugin::TT::LastModified; sub test { my $self = shift; return $self->tt_process( 'index.html' ); } 1; CGI-Application-Plugin-TT-LastModified-1.02/t/lib/TestApp/base.pm0000444000076400007640000000065511365144533023564 0ustar grahamgrahampackage TestApp::base; use strict; use base qw(CGI::Application); use CGI::Application::Plugin::TT; sub cgiapp_init { my $self = shift; $self->tt_config( TEMPLATE_OPTIONS => { INCLUDE_PATH => 't/templates/', POST_CHOMP => 1, DEBUG => 1, }, ); } sub setup { my $self = shift; $self->start_mode( 'test' ); $self->run_modes([qw( test )]); } 1; CGI-Application-Plugin-TT-LastModified-1.02/t/lib/TestApp/LastModified.pm0000444000076400007640000000041611365144533025211 0ustar grahamgrahampackage TestApp::LastModified; use strict; use base qw(TestApp::base); use CGI::Application::Plugin::TT::LastModified; sub test { my $self = shift; my $html = $self->tt_process( 'index.html' ); $self->tt_set_last_modified_header(); return $html; } 1; CGI-Application-Plugin-TT-LastModified-1.02/Build.PL0000444000076400007640000000103411365144533021207 0ustar grahamgrahamuse strict; use warnings; use Module::Build; Module::Build->new( 'module_name' => 'CGI::Application::Plugin::TT::LastModified', 'dist_author' => 'Graham TerMarsch (cpan@howlingfrog.com)', 'license' => 'perl', 'create_makefile_pl'=> 'traditional', 'requires' => { 'CGI::Application' => 4, 'CGI::Application::Plugin::TT' => 0, 'CGI::Util' => 0, 'List::Util' => 0, }, )->create_build_script(); CGI-Application-Plugin-TT-LastModified-1.02/Makefile.PL0000444000076400007640000000112311365144533021664 0ustar grahamgraham# Note: this file was auto-generated by Module::Build::Compat version 0.32 use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'CGI::Application::Plugin::TT::LastModified', 'VERSION_FROM' => 'lib/CGI/Application/Plugin/TT/LastModified.pm', 'PREREQ_PM' => { 'CGI::Application' => 4, 'CGI::Application::Plugin::TT' => 0, 'CGI::Util' => 0, 'List::Util' => 0 }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [] ) ; CGI-Application-Plugin-TT-LastModified-1.02/README.txt0000444000076400007640000000065711365144533021423 0ustar grahamgrahamCGI::Application::Plugin::TT::LastModified adds "Last-Modified" header based on modification time of TT template component 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. To install: perl Build.PL ./Build ./Build test ./Build install or perl Makefile.PL make make test make install CGI-Application-Plugin-TT-LastModified-1.02/MANIFEST0000444000076400007640000000056311365144533021052 0ustar grahamgrahamBuild.PL Makefile.PL Changes MANIFEST MANIFEST.SKIP META.yml README.txt lib/CGI/Application/Plugin/TT/LastModified.pm t/auto-last-modified.t t/last-modified.t t/plain.t t/pod.t t/pod-coverage.t t/lib/TestApp/base.pm t/lib/TestApp/AutoLastModified.pm t/lib/TestApp/LastModified.pm t/lib/TestApp/Plain.pm t/templates/top.html t/templates/bottom.html t/templates/index.html CGI-Application-Plugin-TT-LastModified-1.02/lib/0000755000076400007640000000000011365144533020465 5ustar grahamgrahamCGI-Application-Plugin-TT-LastModified-1.02/lib/CGI/0000755000076400007640000000000011365144533021067 5ustar grahamgrahamCGI-Application-Plugin-TT-LastModified-1.02/lib/CGI/Application/0000755000076400007640000000000011365144533023332 5ustar grahamgrahamCGI-Application-Plugin-TT-LastModified-1.02/lib/CGI/Application/Plugin/0000755000076400007640000000000011365144533024570 5ustar grahamgrahamCGI-Application-Plugin-TT-LastModified-1.02/lib/CGI/Application/Plugin/TT/0000755000076400007640000000000011365144533025117 5ustar grahamgrahamCGI-Application-Plugin-TT-LastModified-1.02/lib/CGI/Application/Plugin/TT/LastModified.pm0000444000076400007640000001410511365144533030020 0ustar grahamgrahampackage CGI::Application::Plugin::TT::LastModified; ############################################################################### # Required inclusions. ############################################################################### use strict; use warnings; use CGI::Util qw(expires); use List::Util qw(max); ############################################################################### # Version numbering. ############################################################################### our $VERSION = '1.02'; ############################################################################### # Export our methods. ############################################################################### our @EXPORT = qw( tt_last_modified tt_set_last_modified_header ); ############################################################################### # Subroutine: import() ############################################################################### # Custom import routine, which allows for 'tt_set_last_modified_header()' to be # auto-added in as a TT post process hook. ############################################################################### sub import { my $pkg = shift; my $auto = shift; my $caller = scalar caller; # manually export our symbols foreach my $sym (@EXPORT) { no strict 'refs'; *{"${caller}::$sym"} = \&{$sym}; } # sanity check caller package, and set up auto-header functionality if (not UNIVERSAL::isa($caller, 'CGI::Application')) { warn "Calling package is not a CGI::Application module.\n"; } elsif (not UNIVERSAL::can($caller, 'tt_obj')) { warn "Calling package hasn't imported CGI::Application::Plugin::TT.\n"; } elsif ($auto and ($auto eq ':auto')) { $caller->add_callback( tt_post_process => \&tt_set_last_modified_header ); } } ############################################################################### # Subroutine: tt_last_modified() ############################################################################### # Returns the most recent modification time for any component of the most # recently processed template (via 'tt_process()'). Time is returned back to # the caller as "the number of seconds since the epoch". ############################################################################### sub tt_last_modified { my $self = shift; my $ctx = $self->tt_obj->context(); my $mtime = 0; foreach my $provider (@{$ctx->{'LOAD_TEMPLATES'}}) { foreach my $file (keys %{$provider->{'LOOKUP'}}) { my $c_mtime = $provider->{'LOOKUP'}{$file}[3]; $mtime = max( $mtime, $c_mtime ); } } return $mtime; } ############################################################################### # Subroutine: tt_set_last_modified_header() ############################################################################### # Sets a "Last-Modified" header in the HTTP response, equivalent to the last # modification time of the template components as returned by # 'tt_last_modified()'. ############################################################################### sub tt_set_last_modified_header { my $self = shift; my $mtime = $self->tt_last_modified(); if ($mtime) { my $lastmod = expires( $mtime, 'http' ); $self->header_add( '-last-modified' => $lastmod ); } } 1; =head1 NAME CGI::Application::Plugin::TT::LastModified - Set "Last-Modified" header based on TT template =head1 SYNOPSIS # 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 ); } =head1 DESCRIPTION C adds support to C for setting a "Last-Modified" header based on the most recent modification time of I of the components of a template that was processed with TT. Normally you'll want to call it manually, on as "as needed" basis; if you're processing templates with TT you're most likely dealing with dynamic content (in which case you probably don't even want a "Last-Modified" header). The odd time you'll want to set a "Last-Modified" header, though, this plugin helps make that easier. B you have a desire to have the "Last-Modified" header set automatically for you, though, C does have an C<:auto> import tag which auto-registers L as a "tt_post_process" hook for you. If you've got an app that just processes static TT pages and generates output, this'll be useful for you. =head1 METHODS =over =item import() Custom import routine, which allows for C to be auto-added in as a TT post process hook. =item tt_last_modified() Returns the most recent modification time for any component of the most recently processed template (via C). Time is returned back to the caller as "the number of seconds since the epoch". =item tt_set_last_modified_header() Sets a "Last-Modified" header in the HTTP response, equivalent to the last modification time of the template components as returned by C. =back =head1 AUTHOR Graham TerMarsch (cpan@howlingfrog.com) =head1 COPYRIGHT 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. =head1 SEE ALSO L, L, L