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)];

In reply to Re: Template Toolkit 2 strange behaviour by Rhandom
in thread Template Toolkit 2 strange behaviour by Aramis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.