Subject: | Problem with eval'ed blocks |
Distribution: Template-Timer-0.02
Perl version: 5.6.1
OS: FreeBSD 4.5
This module does a great job with templates stored in files. However, if it encouters a template in a string that's being rendered via the eval filter, it chokes. Attached is a patch that will allow it to handle these eval'ed blocks.
Here's a failing test (eval.t):
use Test::More tests => 1;
use Template::Timer;
my $tt = Template->new( {
CONTEXT => Template::Timer->new
} );
my $block = "[% thing = 'doohickey' %]";
ok( $tt->process( \*DATA, { block => $block } ), 'eval' );
__DATA__
[% block | eval %]
[% thing %]
--- blib/lib/Template/Timer.pm.orig Tue Oct 26 11:10:10 2004
+++ blib/lib/Template/Timer.pm Mon Jun 13 10:13:17 2005
@@ -2,6 +2,7 @@
use warnings;
use strict;
+require UNIVERSAL;
=head1 NAME
@@ -23,6 +24,8 @@
Using Template::Timer is simple.
+ use Template::Timer;
+
my %config = ( # Whatever your config is
INCLUDE_PATH => "/my/template/path",
COMPILE_EXT => ".ttc",
@@ -63,7 +66,11 @@
my $super = __PACKAGE__->can("SUPER::$sub") or die;
*$sub = sub {
my $self = shift;
- my $template = ref $_[0] ? $_[0]->name : $_[0];
+ my $template = $_[0];
+ if ( ref $_[0] ) {
+ $template = $_[0]->name if UNIVERSAL::isa( $_[0], 'Template::Document' );
+ $template = '(evaluated block)' if ref $_[0] eq 'SCALAR';
+ }
my $start = [Time::HiRes::gettimeofday];
my $data = $super->($self, @_);
my $elapsed = Time::HiRes::tv_interval($start);