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!
The relevant code in Template::Stash is:
# failed to call object method, so try some fallbacks
if (reftype $root eq 'HASH') {
if( defined($value = $root->{ $item })) {
return $value unless ref $value eq 'CODE'; ##
RETURN
@result = &$value(@$args);
}
elsif ($value = $HASH_OPS->{ $item }) {
@result = &$value($root, @$args);
}
elsif ($value = $LIST_OPS->{ $item }) { # XXX
@result = &$value([$root], @$args); # XXX
} # XXX
}
(I've added the # XXX to emphasise the patch).
To my simple brain, it's never going to call list_list since it tries
hash_list first and that succeeds. Indeed, when I run it, that's what I see.
So I single-stepped it. Here's the debugger output (n.b I added
$DB::single = 1; just before this stanza, so all line numbers are out by
one):
Template::Stash::_dotop(/usr/local/lib/perl/5.10.1/Template/Stash.pm:505):
505: if (reftype $root eq 'HASH') {
DB<1> p $root
TDB::Schema::Result::Keyword=HASH(0xb383b00)
DB<2> p $item
list
DB<3> n
Template::Stash::_dotop(/usr/local/lib/perl/5.10.1/Template/Stash.pm:506):
506: if( defined($value = $root->{ $item })) {
DB<3> n
Template::Stash::_dotop(/usr/local/lib/perl/5.10.1/Template/Stash.pm:511):
511: @result = &$value($root, @$args);
DB<3> p $value
CODE(0xb0c6ff8)
DB<4> p $root
TDB::Schema::Result::Keyword=HASH(0xb383b00)
DB<5> p $root->{$item}
DB<6> p $HASH_OPS->{ $item }
CODE(0xb0c6ff8)
DB<7> p $LIST_OPS->{ $item }
CODE(0xb0b2328)
DB<8> n
Template::Stash::_dotop(/usr/local/lib/perl/5.10.1/Template/Stash.pm:561):
561: if (defined $result[0]) {
562: return ## RETURN
DB<9> p $result[0]
ARRAY(0xb376ed8)
DB<10> x $result[0]
0 ARRAY(0xb376ed8)
0 HASH(0xb383920)
'key' => '_column_data'
'value' => HASH(0xb383c30)
'kwd_definition' => 'Presence or two or more structural units
within the protein or protein region corresponding to family or
superfamily domain.'
'kwd_id' => 1
'kwd_txt' => 'internal structural duplication'
1 HASH(0xb383520)
'key' => '_in_storage'
'value' => 1
2 HASH(0xb3836e0)
'key' => '_source_handle'
'value' => DBIx::Class::ResultSourceHandle=HASH(0xb383590)
'schema' => 'TDB::Schema'
'source_moniker' => 'Keyword'
and indeed, it's never reaching the patch code.
So what am I doing wrong?
Cheers, Dave
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates