Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Templating algorithm - pass in variables vs callback?

by fergal (Chaplain)
on Mar 02, 2005 at 00:09 UTC ( [id://435662]=note: print w/replies, xml ) Need Help??


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

It's been mentioned already but I thought I'd give an example in Petal
my $t = Petal->new($template_file); print $t->process( user -> $user, );

Here $user is an object that has many methods that return strings or arrays or other objects. In a Petal expression "user/name" will result in a call to $user->name. "user/account/balance" will result in a call to $user->account->balance. Since these are methods, they can be as lazy as they like, they can pull things out of databases at the last moment, perform complex calculations etc.

In Petal the syntax for hash access is the same as method call (basically it calls a method if it can otherwise it treats it as a hash key) so it's easy to switch between them. Particularly handy when you're protyping and you want to pump some sample data into your template to make sure everything's OK.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-20 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found