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",
},
);
}