[Templates] Patch: Fix problem treating single objects as lists of objects

Paul Seamons mail@seamons.com
Tue, 21 Nov 2006 08:45:08 -0700


On Monday 20 November 2006 4:44 pm, Jess Robinson wrote:
> I got bored.. this fixes it for me, albiet only probably one part of the
> underlying problem. I also didn't fix the XS side since I've no clue how
> that works. Test included.

I've been watching your threads and have been meaning to mention:

If you're crossing the language barrier between TT and Perl (and they are two 
very distinct languages) then any methods you are exposing should really only 
ever return a single result.  Perl is one of only a few languages that allow 
for you to return multiple things at the same time.  TT tries to handle this 
and does a fairly good job.  But if you are controlling results returned by 
an object - or if you are trying to wrap some other person's object's methods 
for use by TT - you should only ever return a single value.  That means you 
never return a list of values - you always encapsulate that list in an 
arrayref.  Always.

Consequently - this also is a useful and somewhat more intuitive pattern to 
use even if you aren't using TT or crossing other language boundaries.

The patch you submitted looks fine from my perspective.  But I would suggest 
not depending upon it but instead wrap or change the code that is returning 
multiple results sometimes and single results at other times.  That would be 
a two character addition to every return statement in question.

Paul