[Templates] Patch: Fix problem treating single objects as lists
of objects
Jess Robinson
castaway@desert-island.demon.co.uk
Tue, 21 Nov 2006 19:52:04 +0000 (GMT)
On Tue, 21 Nov 2006, Paul Seamons wrote:
> 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.
>
Hi Paul,
Yup, that's probably a good idea.. However the API that returns a list in
list context and an arrayref in scalar context exists and has existed in
the code I am looking at for quite a while.. I really wouldn't want to
change that just for TTs convenience.
If I could get TT to call the sub in scalar context that would work just
as well, but it doesn't.
This is more a case of grafting TT support/output onto existing code than
code written exclusively for TT.. Possibly we could wrap it somehow.. hmm.
Jess