Skip Menu |

This queue is for tickets about the Template-Toolkit CPAN distribution.

Report information
The Basics
Id: 19827
Status: resolved
Worked: 10 min
Priority: 0/
Queue: Template-Toolkit

People
Owner: Nobody in particular
Requestors: davekam [...] pobox.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.15
Fixed in: (no value)



Subject: list vmethod broken on blessed objects in 2.15
In 2.15, doing obj.list where obj is a blessed object instantiated as a hash treats it as a hash, decomposing into an array of key/value/etc. This is different behavior from 2.14, where it would be treated as a scalar and put into a one-element array. The latter behavior is what I would expect and what I believe is also most useful -- otherwise there is no way to ensure creation of an array when you have an unknown number of blessed objects. The change between 2.14 and 2.15 is not documented in the changes file and, if interpreted correctly here, is a significant bug. The behavior is the same with perl and XS stashes.
The hash.list vmethod has not changed from 2.14 to 2.15. It always has returned a decomposed version of the hash, as documented in Template::Manual::VMethods. What has changed in 2.15 is that we now have full support for calling hash virtual methods on objects composed from hashes. In 2.14 calling .list on a hash object resulted in the *scalar* .list virtual method being called incorrectly. This, as documented returns the single item in a list: [$obj] So it's more correct to say that TT was broken in 2.14 and has now been fixed in 2.15. This is the relevant entry in the Changes file: Stash ----- * Activated a patch in Template::Stash from Stephen Howard which adds code for the full set of fallbacks for dot ops called against objects which don't implement the specific method. For example [% hashobj.vmethod %] [% listobj.2 %] and [% listobj.vmethod %] now all work with the Perl Template::Stash. Added code to the XS Stash to do the same and updated tests. http://template-toolkit.org/pipermail/templates/2003-December/005417.html In anticipation of the fact that this does make the behaviour of some vmethods inadvertently change (as you've discovered) we do plan to "fix" hash.list to do what it should have done all along (i.e. the same thing that item.list does). This planned change is documented in Template::Manual::VMethods docs and also in the Changes file. Cheers A
Subject: Re: [rt.cpan.org #19827] list vmethod broken on blessed objects in 2.15
Date: Tue, 13 Jun 2006 03:38:54 +0200
To: bug-Template-Toolkit [...] rt.cpan.org
From: David Kamholz <davekam [...] pobox.com>
On Jun 12, 2006, at 9:17 AM, Andy_Wardley via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=19827 > > > The hash.list vmethod has not changed from 2.14 to 2.15. It always > has > returned a decomposed version of the hash, as documented in > Template::Manual::VMethods. > > What has changed in 2.15 is that we now have full support for calling > hash virtual methods on objects composed from hashes. In 2.14 calling > .list on a hash object resulted in the *scalar* .list virtual method > being called incorrectly. This, as documented returns the single item > in a list: [$obj] > > So it's more correct to say that TT was broken in 2.14 and has now > been > fixed in 2.15.
Right, but it's highly debatable whether the expected and most useful behavior is to always invoke the hash vmethods on objects composed from hashes. As it is now, there is apparently *no* way in 2.15 to uniformly handle the results of a method that returns zero or more objects. I had been using .list in order to make sure the object was always an array. As far as I'm concerned they are just objects; I don't need to know, or care, that they are hashes, as I access the objects only via their methods. The 2.15 behavior is quite unintuitive. The whole point of objects is that they are objects! I haven't checked to see if obj.foo first tries $obj->foo or $obj-> {foo}, but if $obj is blessed it should certainly be the former. I'm not really sure how this should be resolved, as I can see certain restricted situations when you would not want a distinction between blessed and unblessed hashes, but in any case I don't think the 2.15 behavior should just be imposed by fiat, leaving no easy way to do what seems a perfectly logical thing to want to do, and which used to work fine. Dave
Subject: Re: [rt.cpan.org #19827] list vmethod broken on blessed objects in 2.15
Date: Tue, 13 Jun 2006 03:45:16 +0200
To: bug-Template-Toolkit [...] rt.cpan.org
From: David Kamholz <davekam [...] pobox.com>
Sorry, I missed the last bit of your message -- glad to see that this behavior will change soon. Too bad it couldn't have been worked into 2.15, though. I'll just stick with 2.14 until the change goes in. Dave
I'm closing this old ticket for TT2. TT3 will Do The Right Thing.