[Templates] Problem with HASH.size vs ARRAY.size
Jess Robinson
castaway@desert-island.demon.co.uk
Mon, 20 Nov 2006 22:14:51 +0000 (GMT)
On Fri, 17 Nov 2006, apv wrote:
> So, I've messed around with .list and []s everywhere and I can't make this
> work.
>
> Doing this (DBIx::Class underneath):
> [% comments = article.comments(status => 'approved') %]
> <h2>comment count: [% comments.size %]</h2>
>
> If there are more than one; it works fine. "comments" is an array ref of
> comment objects.
>
> If there is only one comment, it returns a single comment object (HASH) and
> instead of getting "1" for the comment count, we get the key/val pair count.
> Is there something simple I'm missing? If possible, I don't want to resort to
> installing "ref" methods in the OPS tables; or whatever else.
>
You're missing a back-compat borkage for an undocumented feature.. calling
list methods on hashes used to fall through, now it doesnt, it just doesnt
call them.. (It always returned one obj instead of an array if there was
only one, but you didn't notice because it tried list methods after
hash methods couldnt be found..
See my recent emails.
Jess