On Mon, Jul 01, 2002 at 06:23:35PM -0400, Parker, Brian  wrote:
> That makes sense.  I bet you're right. I wonder if 'sort' could be a
> no-op method for a scalar to handle this case.

That would probably be a good idea.

> > I'm pretty sure that in the long run you'll be happier if you just
> > pass references around. Only pretty sure, tho.

> You're probably right.  However, this means that there has to be
> some constraint on how classes are defined in order for them to be used
> from TT.  I think one of the most powerful features of TT is that any
> old perl object can be queried from the template for display.

This is pretty much true. Most of my web sites are built using Template
Toolkit with Class::DBI. Now for a variety of reasons, mostly historic,
Class::DBI returns plain lists, not references. So I occassionally hit
thse sorts of problems. If you're not in a position to make all your
object methods return references, then the best thing to do is to make
sure that your templates call the .list method:

  [% FOREACH color = colors.list.sort %]
  hello : [% color %]
  [% END %]

So if you started with a one element list that gets silently converted
to a scalar, this will coerce it back to a one element list, which _can_
then be sorted :)

Tony




Reply via email to