Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Template Toolkit 2 strange behaviour

by Rhandom (Curate)
on Nov 17, 2011 at 17:42 UTC ( #938654=note: print w/replies, xml ) Need Help??

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
    Thanks for your recommendation, I had already checked the reviews and your module at CPAN. I will try it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://938654]
[Corion]: A good daypart!
Corion feels slightly bad for initiating a discussion yesterday and then running away. I guess I should write that up as a meditation or SoPW
[Corion]: Not the "running away" part but the question+ discussion about IO-less HTTP modules
[Corion]: (or how/where to patch AnyEvent::HTTP or LWP::UserAgent to take control of both the callstack and the data transfer)

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2016-12-08 09:03 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (137 votes). Check out past polls.