Attached is a plugin module that demonstrates the problem. The
following template shows how list are treated as literal "[1, 2, 3]", as
array variables "ListTest.echo_list(1, 2, 3)", and as variables that
implement the as_list method "ListTest.echo_as_list(1, 2, 3)".
[% USE ListTest %]
[% FOREACH i IN [0, 1, 2, 3]; "$i, "; END %][0, 1, 2, 3]
[% FOREACH i IN ListTest.echo_list(0, 1, 2, 3); "$i, "; END
%]echo_list(0, 1, 2, 3)
[% FOREACH i IN ListTest.echo_as_list(0, 1, 2, 3); "$i, "; END
%]echo_as_list(0, 1, 2, 3)
[% FOREACH i IN ["", "Hello", "World"]; "$i, "; END %]["", "Hello", "World"]
[% FOREACH i IN ListTest.echo_list("", "Hello", "World"); "$i, "; END
%]echo_list("", "Hello", "World")
[% FOREACH i IN ListTest.echo_as_list("", "Hello", "World"); "$i, "; END
%]echo_as_list("", "Hello", "World")
[% FOREACH i IN [1, 2, 3]; "$i, "; END %][1, 2, 3]
[% FOREACH i IN ListTest.echo_list(1, 2, 3); "$i, "; END %]echo_list(1,
2, 3)
[% FOREACH i IN ListTest.echo_as_list(1, 2, 3); "$i, "; END
%]echo_as_list(1, 2, 3)
[% FOREACH i IN ["Hello", "World"]; "$i, "; END %]["Hello", "World"]
[% FOREACH i IN ListTest.echo_list("Hello", "World"); "$i, "; END
%]echo_list("Hello", "World")
[% FOREACH i IN ListTest.echo_as_list("Hello", "World"); "$i, "; END
%]echo_as_list("Hello", "World")
[% FOREACH i IN [1]; "$i, "; END %][1]
[% FOREACH i IN ListTest.echo_list(1); "$i, "; END %]echo_list(1)
[% FOREACH i IN ListTest.echo_as_list(1); "$i, "; END %]echo_as_list(1)
[% FOREACH i IN [0]; "$i, "; END %][0]
[% FOREACH i IN ListTest.echo_list(0); "$i, "; END %]echo_list(0)
[% FOREACH i IN ListTest.echo_as_list(0); "$i, "; END %]echo_as_list(0)
[% FOREACH i IN [""]; "$i, "; END %][""]
[% FOREACH i IN ListTest.echo_list(""); "$i, "; END %]echo_list("")
[% FOREACH i IN ListTest.echo_as_list(""); "$i, "; END %]echo_as_list("")
[% FOREACH i IN []; "$i, "; END %][]
[% FOREACH i IN ListTest.echo_list(); "$i, "; END %]echo_list()
[% FOREACH i IN ListTest.echo_as_list(); "$i, "; END %]echo_as_list()
[% FOREACH i IN 3; "$i, "; END %]3
[% FOREACH i IN ListTest.echo_scalar(3); "$i, "; END %]echo_scalar(3)
[% FOREACH i IN 0; "$i, "; END %]0
[% FOREACH i IN ListTest.echo_scalar(0); "$i, "; END %]echo_scalar(0)
[% FOREACH i IN ""; "$i, "; END %]""
[% FOREACH i IN ListTest.echo_scalar(""); "$i, "; END %]echo_scalar("")
package Template::Plugin::ListTest;
use strict;
use base 'Template::Plugin';
use Template::Plugin;
sub load { # called as MyPlugin->load($context)
my ($class, $context) = @_;
return $class; # returns 'MyPlugin'
}
#------------------------------------------------------------------------
# new($context, $name)
#
# Constructor method which returns a sub-routine closure for constructing
# complex URL's from a base part and hash of additional parameters.
#------------------------------------------------------------------------
sub new {
my $class = shift;
my $self = { CONTEXT => shift };
return bless $self, $class;
}
sub echo_list {
shift;
wantarray ? @_ : \@_;
}
sub echo_scalar {
shift;
shift;
}
sub echo_as_list {
shift;
return AsList->new(@_);
}
package AsList;
sub new {
my $class = shift;
bless { list => \@_ }, $class
}
sub as_list {
my $self = shift;
$self->{list};
}
1;
__END__