in reply to Template Toolkit 2 strange behaviour
Template::Alloy, which should be a drop in replacement for Template::Tookit, has a configuration option called CALL_CONTEXT that can be set to one of smart (default), item, or list. There are many ways you can change the context you call in, you can set the global CALL_CONTEXT option during new, you can set it locally using a [% CONFIG CALL_CONTEXT => "list" %] inside your template, or you can use the @() and $() context specifiers (as in [% results = @( myobj.mymethod() ) %]).
The following is a table of what is returned in each context copied from the Template::Alloy pod.
return values smart context list context item context ------------- ------------- ------------ ------------ A 'foo' 'foo' 'foo' 'foo' B undef undef undef undef C (no return value) undef [] undef D (7) 7 7 7 E (7,8,9) 7,8,9 7,8,9 9 F @a = (7) 7 7 1 G @a = (7,8,9) 7,8,9 7,8,9 3 H ({b=>"c"}) {b=>"c"} {b=>"c"} {b=>"c"} I (1) 1 [1] 1 J (1,2) [1,2] [1,2] 2 K 7,8,9 7,8,9 [7,8,9] 7,8,9 L (undef, "foo") die "foo" undef, "foo" "foo" M wantarray?1:0 1 1 0
Disclaimer: I am the author.
my @a=qw(random brilliant braindead); print $a[rand(@a)];
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Template Toolkit 2 strange behaviour
by Aramis (Initiate) on Nov 17, 2011 at 18:59 UTC |
In Section
Seekers of Perl Wisdom