in reply to Template::Toolkit: get the names of mentioned variables?

Not really, there are so many legitimate variants that it's next to impossible to parse the template to determine what variables are going to be called (what do you do when you run up against var1.$var2.{$var3.$var4}.something?

What I ended up doing when I needed to solve a similar problem was to override the Template::Stash object, with one that could determine the value to be put there at runtime. You may want to check the Class::DBI::Template::Stash subclass in my Class::DBI::Template module to see how I solved it.


We're not surrounded, we're in a target-rich environment!
  • Comment on Re: Template::Toolkit: get the names of mentioned variables?

Replies are listed 'Best First'.
Re^2: Template::Toolkit: get the names of mentioned variables?
by dgaramond2 (Monk) on Apr 21, 2005 at 02:02 UTC

    Yeah, that's what I was afraid of. But since my template texts are currently very simple, for now I'm just going to do a regex parsing to extract the variables. Today's the deadline, argh!

    Thanks for the pointer, though. I'm just familiarizing with the various classes and I'll look into subclassing Template::Stash later. Seems like the proper thing to do. I'm thinking of processing the template twice, in the first pass my custom stash will remember the variable names.

      Well, subclassing Template::Stash is not hard at all after all. I just needed to supply a custom get() method. Works like a charm! I've accomplished what I needed to be done in the first place. Perl is great!