Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Templating algorithm - pass in variables vs callback?

by merlyn (Sage)
on Mar 01, 2005 at 11:47 UTC ( [id://435370]=note: print w/replies, xml ) Need Help??


in reply to Templating algorithm - pass in variables vs callback?

In template toolkit:
my $lazy = do { my $result; sub { unless (defined $result) { ... do expensive computation ... ... assigning to $result ... } return $result; }; }; my %vars = { lazy => $lazy, easy => 2 + 2, }; $template->process('mything.tt', \%vars);
From the template, you use both "lazy" and "easy" the same way. Except that "lazy" is a coderef. That's what's cool about TT: the call is the same.

I seem to recall a module that does this for you. Yes, Data::Lazy.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://435370]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found