Hi Felipe,
On 27/10/10 20:56, Felipe Gasper (cPanel) wrote:
> If I have:
>
> perl -MTemplate -MTemplate::Stash -le
> 'Template->new({STASH=>Template::Stash->new()})->process(\"Hi. [%
> FOREACH key IN x.keys() %]Key [% key %], [% END
> %]",{x=>{a=>2,b=>3,keys=>[4,5,6]}});'
>
> ...one would think, not being familiar with TT, that “x.keys()” is a
> method call.
>
> As many of us know, though, TT looks first at the “keys” item of the “x”
> hash.
Although it doesn't really answer your question, normally I don't find
the hash-item-first behaviour to be too restrictive due to the
additional methods available. In this case:
perl -MTemplate -e'Template->new->process(\q{Hi. [% FOREACH key IN
x.list("keys") %]Key [% key %], [% END %]},{x=>{a=>2,[4,5,6]}});'
Another similar case is:
perl -MTemplate -e'Template->new->process(\q{Size was [%
obj.list("keys").size %].}, { obj => { size => {123=>1} } });'
Similar workarounds using .each or .pairs usually make it easy enough to
work around vmethod/key overlap. Would be interested to see other
alternatives though.
Tom
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates