Dave Howorth wrote:
> Cees Hek wrote:
>> Check what version of Template Toolkit you are using.  This was
>> something that was changed in v2.20:
>>
>> * Applied a patch to Template::Stash from Jess Robinson which allows you
>>   to call a list method on a single object and have it automatically
>>   upgraded to a single item list.  Changed the XS Stash to do the same.
>>   http://lists.tt2.org/pipermail/templates/2006-November/009115.html
> 
> OK. It does seem that I have the patch but looking at it I don't
> understand why it would work. Debugging it, it doesn't work. So I'm
> obviously missing some important point :) Let me show what I've done so
> you can spot my mistake!

Here's some more testing. The test that the patch added to stash.t
doesn't check the list vmethod at all. It only uses the first vmethod
and since there is no hash_first mplementation, it doesn't check that
code path. I added some fairly random extra tests to stash.t and they
appear to confirm my belief that the patch does not work.

NB These tests are designed to illustrate the faulty behaviour. They're
not intended as tests of the correct behaviour, except for the last.
(IMHO, it would be useful if the test object had two attributes, as that
would expose problems more easily)

-- test --
[% obj.list.size %]
-- expect --
1

-- test --
[% obj.list.0 %]
-- expect --
AnObject

-- test --
[% obj.list.0.value %]
-- expect --
an object

-- test --
[% obj.list.0.key %]
-- expect --
name

-- test --
[% obj.list.0.name %]
-- expect --
an object


ok 50 - template text 19 processed OK: [% obj.list.size %]
ok 51 - template text 19 matched expected
ok 52 - template text 20 processed OK: [% obj.list.0 %]
MATCH FAILED
 input: [[% obj.list.0 %]\n]
expect: [AnObject]
output: [HASH(0x9240080)]
FAILED 53:  - template text 20 did not match expected
not ok 53 - template text 20 did not match expected
ok 54 - template text 21 processed OK: [% obj.list.0.value %]
ok 55 - template text 21 matched expected
ok 56 - template text 22 processed OK: [% obj.list.0.key %]
ok 57 - template text 22 matched expected
ok 58 - template text 23 processed OK: [% obj.list.0.name %]
MATCH FAILED
 input: [[% obj.list.0.name %]\n]
expect: [an object]
output: []
FAILED 59:  - template text 23 did not match expected
not ok 59 - template text 23 did not match expected

Cheers, Dave


_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to