Skip Menu |

This queue is for tickets about the Template-Toolkit CPAN distribution.

Report information
The Basics
Id: 13721
Status: resolved
Priority: 0/
Queue: Template-Toolkit

People
Owner: Nobody in particular
Requestors: jmay [...] pobox.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.14
Fixed in: (no value)



Subject: should not collapse list with just one hashref element
If data passed to process() for interpolation into the template contains just a single hashref as an array element, then it interprets the hashref as an array. In the example below, the second list (with just one element) is handled incorrectly. #!/usr/bin/env perl use strict; use Template; my $template = " Should show 2 entries: [% FOREACH i = data.mylist1 %] [% loop.index %]: [% i.a %],[% i.c %] [% END %] Should show 1 entry: [% FOREACH i = data.mylist2 %] [% loop.index %]: [% i.one %],[% i.two %] [% END %] "; my $data = {}; bless $data, "foo"; my $tt = new Template; $tt->process(\$template, { data => $data }); package foo; sub mylist1 { return ( { a => "b", c => "d", }, { a => "f", c => "g", }, ); } sub mylist2 { return ( { one => "111", two => "222", }, ); }