On Mon, Sep 10, 2001 at 03:48:42PM +0100, will wrote:
> I'm passing little bunches of Class::DBI objects through to a 
> template. It's working very well, but some of their more rarely-used 
> methods involve quite laborious database work, and i'd like to avoid 
> invoking those methods unless the template requests them.

Yep.  You can just do this:

  [% person.something_really_complicated %]

The method will be called there and then.  You don't need to pre-calculate
anything and it will only get called when used.

> i was hoping that using [% foreach 
> person.something_really_complicated %] in the template would trigger 
> that method, but it doesn't seem to be so.

Should do.  Perhaps you need something like:

  [% FOREACH thingy = person.something_really_complicated %]
     [% thingy.this %] and [% thingy.that %]
  [% END %]

This is assuming that the method returns a list of things.  If it returns
a list of hash refs (a typical case) then you can indeed leave the target
off and the hash contents will get IMPORTed into the current variable set.

  [% FOREACH person.something_really_complicated %]
     [% this %] and [% that %]
  [% END %]


HTH
A



Reply via email to