This is exactly my situation! That solves my problem, thank you very
much! Btw: 5:33 AM, even before first coffee? Excellent work! ;)
I just would dare to extend your solution:
either by making VMethod of it:
$Template::Stash::LIST_OPS->{ as_list } = sub {
return ref( $_[0] ) eq 'ARRAY' ? shift : [shift];
};
so you can do:
FOR i = field.options.as_list;
or by hacking .list VMethod:
my $tt_hash_list = $Template::Stash::HASH_OPS->{ list };
$Template::Stash::HASH_OPS->{ list } = sub {
#ref( $_[0] ) should be either 'HASH' or 'MyObj=HASH' otherwise
return ref( $_[0] ) eq 'HASH' ? &$tt_hash_list(@_) : [shift];
};
so you can do:
FOR i = field.options.list;
Thank you all, guys!
Best regards,
PD
-----Original Message-----
From: Bill Moseley [mailto:[email protected]]
Sent: Thursday, December 10, 2009 3:45 PM
To: Danihlik Petr PLZ ELD
Cc: [email protected]; [email protected]
Subject: Re: [Templates] Single object list problem by VMethods
On Thu, Dec 10, 2009 at 5:33 AM, <[email protected]> wrote:
6 Sorted array of 1 MyObj item : MyObj=HASH(0x1c57c2c) -> foo =
name =
I think that's the issue where a single object (as a hash ref) ends up
looking like a list of keys and values when used as a list. I see that
I often do this:
FOR i = as_list( field.options );
Where field.options returns a list of objects and as_list is:
$stash{as_list} = sub { return ref( $_[0] ) eq 'ARRAY' ? shift :
[shift] };
Not 100% sure if that's your situation -- just passing by on my way to
coffee and noticed your message.
--
Bill Moseley
[email protected]
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates