Template-Timer-1.00/0000755000076400007640000000000011154403450012740 5ustar andyandyTemplate-Timer-1.00/Makefile.PL0000644000076400007640000000206711154403234014717 0ustar andyandyuse strict; use warnings; use ExtUtils::MakeMaker; my %parms = ( NAME => 'Template::Timer', AUTHOR => 'Andy Lester ', VERSION_FROM => 'Timer.pm', ABSTRACT_FROM => 'Timer.pm', PL_FILES => {}, PREREQ_PM => { 'Template' => 0, 'Test::More' => 0, 'Time::HiRes' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Template-Timer-*' }, ); if ( $ExtUtils::MakeMaker::VERSION ge '6.36' ) { $parms{EXTRA_META} = < generated_by: ExtUtils::MakeMaker version 6.44 distribution_type: module requires: Template: 0 Test::More: 0 Time::HiRes: 0 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 resources: license: http://dev.perl.org/licenses/ Repository: http://github.com/petdance/template-timer/ Template-Timer-1.00/MANIFEST0000644000076400007640000000016411154400614014071 0ustar andyandyChanges MANIFEST META.yml # Will be created by "make dist" Makefile.PL README Timer.pm t/00-load.t t/eval.t t/pod.t Template-Timer-1.00/README0000644000076400007640000000315111154402122013613 0ustar andyandyTemplate::Timer provides inline timings of the template processing througout your code. It's an overridden version of Template::Context that wraps the process() and include() methods. Using Template::Timer is simple. my %config = ( # Whatever your config is INCLUDE_PATH => "/my/template/path", COMPILE_EXT => ".ttc", COMPILE_DIR => "/tmp/tt", ); if ( $development_mode ) { $config{ CONTEXT } = Template::Timer->new( %config ); } my $template = Template->new( \%config ); Now when you process templates, HTML comments will get embedded in your output, which you can easily grep for. .... INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install COPYRIGHT AND LICENSE Copyright (C) 2004-2009 Andy Lester This library is free software; you can redistribute it and/or modify it under the terms of either the GNU Public License v3, or the Artistic License 2.0. * http://www.gnu.org/copyleft/gpl.html * http://www.opensource.org/licenses/artistic-license-2.0.php Template-Timer-1.00/Timer.pm0000644000076400007640000001006011154402672014360 0ustar andyandypackage Template::Timer; use warnings; use strict; =head1 NAME Template::Timer - Rudimentary profiling for Template Toolkit =head1 VERSION Version 1.00 =cut our $VERSION = '1.00'; =head1 SYNOPSIS Template::Timer provides inline timings of the template processing througout your code. It's an overridden version of L that wraps the C and C methods. Using Template::Timer is simple. use Template::Timer; my %config = ( # Whatever your config is INCLUDE_PATH => '/my/template/path', COMPILE_EXT => '.ttc', COMPILE_DIR => '/tmp/tt', ); if ( $development_mode ) { $config{ CONTEXT } = Template::Timer->new( %config ); } my $template = Template->new( \%config ); Now when you process templates, HTML comments will get embedded in your output, which you can easily grep for. The nesting level is also shown. .... Note that since INCLUDE is a wrapper around PROCESS, calls to INCLUDEs will be doubled up, and slightly longer than the PROCESS call. =cut use base qw( Template::Context ); use Time::HiRes (); our $depth = 0; our $epoch = undef; our @totals; foreach my $sub ( qw( process include ) ) { no strict; my $super = __PACKAGE__->can("SUPER::$sub") or die; *{$sub} = sub { my $self = shift; my $what = shift; my $template = ref($what) eq 'ARRAY' ? join( ' + ', @{$what} ) : ref($what) ? $what->name : $what; my $level; my $processed_data; my $epoch_elapsed_start; my $epoch_elapsed_end; my $now = [Time::HiRes::gettimeofday]; my $start = [@{$now}]; DOIT: { local $epoch = $epoch ? $epoch : [@{$now}]; local $depth = $depth + 1; $level = $depth; $epoch_elapsed_start = _diff_disp($epoch); $processed_data = $super->($self, $what, @_); $epoch_elapsed_end = _diff_disp($epoch); } my $spacing = ' ' x $level; my $level_elapsed = _diff_disp($start); my $ip = uc substr( $sub, 0, 1 ); my $start_stats = "L$level $epoch_elapsed_start $spacing$ip $template"; my $end_stats = "L$level $epoch_elapsed_end $level_elapsed $spacing$ip $template"; @totals = ( $start_stats, @totals, $end_stats ); if ( $level > 1 ) { return $processed_data; } my $summary = join( "\n", '', '', ); @totals = (); return "$processed_data\n$summary\n"; }; # sub } # for sub _diff_disp { my $starting_point = shift; return sprintf( '%7.3f', Time::HiRes::tv_interval($starting_point) * 1000 ); } =head1 AUTHOR Andy Lester, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 ACKNOWLEDGEMENTS Thanks to Randal Schwartz, Bill Moseley, and to Gavin Estey for the original code. =head1 COPYRIGHT & LICENSE This library is free software; you can redistribute it and/or modify it under the terms of either the GNU Public License v3, or the Artistic License 2.0. * http://www.gnu.org/copyleft/gpl.html * http://www.opensource.org/licenses/artistic-license-2.0.php =cut 1; # End of Template::Timer Template-Timer-1.00/t/0000755000076400007640000000000011154403450013203 5ustar andyandyTemplate-Timer-1.00/t/eval.t0000644000076400007640000000073211154400614014320 0ustar andyandy#!perl -Tw use strict; use warnings; use Test::More tests => 3; BEGIN { use_ok( 'Template' ); } BEGIN { use_ok( 'Template::Timer' ); } my $tt = Template->new( { CONTEXT => Template::Timer->new } ); my $block = q{[% thing = 'doohickey' %]}; TODO: { # See RT # 13225 local $TODO = 'Problem identified but not fixed'; my $rc = $tt->process( \*DATA, { block => $block } ); ok( $rc, 'eval' ); } __DATA__ [% block | eval %] [% thing %] Template-Timer-1.00/t/pod.t0000644000076400007640000000024711154400614014154 0ustar andyandy#!perl -T use strict; use warnings; use Test::More; eval 'use Test::Pod 1.14'; plan skip_all => 'Test::Pod 1.14 required for testing POD' if $@; all_pod_files_ok(); Template-Timer-1.00/t/00-load.t0000644000076400007640000000025011154400614014520 0ustar andyandy#!perl use strict; use warnings; use Test::More tests => 1; BEGIN { use_ok( 'Template::Timer' ); } diag( "Testing Template::Timer $Template::Timer::VERSION" ); Template-Timer-1.00/Changes0000644000076400007640000000170611154403410014233 0ustar andyandyRevision history for Template::Timer Template::Timer is now hosted on github at http://github.com/petdance/template-timer/ 1.00 Fri Mar 6 23:32:49 CST 2009 ==================================== [ENHANCEMENTS] Measurements are now in milliseconds, not seconds. Now shows nesting level in the notes. The times are all shown as a summary at the end, not throughout the page. 0.04 Sun Oct 16 22:56:51 CDT 2005 ==================================== [FIXES] When calling [% PROCESS block_1 + block_2 %] the block names are passed as an array reference to process(). Template::Timer was assuming that any ref() passed was an object and calling ->name on that object. Thanks to Bill Moseley. 0.02 Tue Oct 26 11:08:33 CDT 2004 ==================================== First actual working version. Fixed bonheaded typo. 0.01 Tue Oct 26 09:58:24 CDT 2004 ==================================== First rudimentary version. Patches and comments welcome.