On 10/12/2009 10:52, [email protected] wrote:
> 1) Did I understand TT behavior correctly?
Yes. I'm afraid so.
> 2) What is the reason for such behavior? Isn’t there any way in Perl to
> determine whether item an object or a hash ref is?
It's one hideous hack after another layered on top of an awful design
decision on my part to call all methods and functions in list context.
I deserve to be shot for all the pain and suffering I have caused. Well,
perhaps not shot but taken out the back and given a sound beating at the
very least.
> 3) Is this already solved in some TT version or is it planned to be
> solved in some further version (3.0, …)?
Yes. In TT3 all functions and object methods are called in scalar context
by default. You have to use '@' as an explicit prefix if you want it called
in list context.
[% foo() # scalar context %]
[% @foo() # list context %]
[% foo.bar() # scalar context %]
[% f...@bar() # list context %]
TT3 won't be ready for production use any time soon, but an early alpha
release isn't far off.
> 4) Is there any way how this could be worked around?
Explicitly add the .list vmethod after your function/method call. That will
force the single item to a list while leaving an existing list unchanged. It
should resolve the ambiguity.
[% your_function.list.sort %]
HTH
A
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates