[Templates] FOREACH problem with wantarray and a single element result

Michael Lackhoff michael at lackhoff.de
Sat Jun 21 11:31:48 BST 2008


On 21.06.2008 10:48 Andy Wardley wrote:

> There's a workaround for TT2 in the form of the scalar plugin.  That's
> new to 2.20 (which isn't released yet), but you can grab it from SVN.
> 
> http://tt2.org/svnweb/Template2/view/trunk/lib/Template/Plugin/Scalar.pm
> 
>      [% USE Scalar %]
> 
>      # TT2 calls object methods in array context by default
>      [% object.method %]
> 
>      # force it to use scalar context
>      [% object.scalar.method %]
> 
>      # also works with subroutine references
>      [% scalar.my_sub_ref %]

Yes, this does indeed work, thanks!

> The problem is fixed properly for TT3.  All methods will be called in scalar
> context by default.  The '@' sigil will be used to force list context when
> you really want it.
> 
>      # TT3
>      [% object.method %]     # scalar context by default
> 
>      [% object. at method %]    # force list context

looking forward to it ;-)

-Michael





More information about the templates mailing list