Subject: | Template toolkit FOREACH problem if UNIVERSAL::can is used |
Template toolkit fails on processing FOREACH without setting an error if
UNIVERSAL::can has been used. In effect, truncated output is returned.
use strict;
use warnings;
use Template;
use UNIVERSAL::can;
print "\$UNIVERSAL::can::VERSION: $UNIVERSAL::can::VERSION\n";
print "\$Template::VERSION: $Template::VERSION\n";
my $templateText = qq(
start
size = [% numbers.size %]
[% FOREACH number IN numbers %] [% number %]
[% END %]
end
);
my $params = {
numbers => [1,2,3]
};
my $template = Template->new( {DEBUG => 1 });
$template->process( \$templateText, $params ) or die $template->error;
output:
$UNIVERSAL::can::VERSION: 1.03
$Template::VERSION: 2.14
start
size = 3
comment out "use UNIVERSAL::can" and output is:
$UNIVERSAL::can::VERSION:
$Template::VERSION: 2.14
start
size = 3
1
2
3
end
perl is 5.8.7 on debian sarge. My windows box did not demonstrate this
problem until UNIVERSAL::can was upgraded from 1.00 to 1.03.
The attached patch (against Template::Iterator) seems to clear up the issue.
regards,
Mark
Subject: | template_iterator.diff |
--- /usr/lib/perl5/Template/Iterator.pm 2004-10-04 12:27:39.000000000 +0200
+++ /home/perl/lib/perl/5.8.7/Template/Iterator.pm 2006-02-06 13:16:37.000000000 +0100
@@ -54,6 +54,8 @@
use Template::Constants;
use Template::Exception;
+use Scalar::Util qw(blessed);
+
$VERSION = sprintf("%d.%02d", q$Revision: 2.65 $ =~ /(\d+)\.(\d+)/);
$DEBUG = 0 unless defined $DEBUG;
@@ -81,7 +83,7 @@
$data = [ map { { key => $_, value => $data->{ $_ } } }
sort keys %$data ];
}
- elsif (UNIVERSAL::can($data, 'as_list')) {
+ elsif (blessed $data && $data->can('as_list')) {
$data = $data->as_list();
}
elsif (ref $data ne 'ARRAY') {