Skip Menu |

This queue is for tickets about the UNIVERSAL-can CPAN distribution.

Report information
The Basics
Id: 17501
Status: resolved
Priority: 0/
Queue: UNIVERSAL-can

People
Owner: Nobody in particular
Requestors: BADGERSRC [...] cpan.org
Cc: markdclements [...] yahoo.co.uk
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.03
Fixed in: (no value)



CC: markdclements [...] yahoo.co.uk
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. I haven't found a workaround as yet. 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. I'm not entirely sure whether this bug should be posted under UNIVERSAL::can or Template toolkit. Apologies if I have made the wrong decision to post it here first. regards, Mark
On Mon Feb 06 06:40:15 2006, BADGERSRC wrote: Show quoted text
> Template toolkit fails on processing FOREACH without setting an error if > UNIVERSAL::can has been used. In effect, truncated output is returned.
By redefining UNIVERSAL::can manually I've tracked down the problem to Template::Iterator, which calls UNIVERSAL::can as a method. The attached patch, as far as I can tell, clears up the problem. I'll open a bug in Template-Toolkit and mark this one as resolved. Mark
--- /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') {