Hello.

On Thursday 30 July 2009 22:16:47 C. Chad Wallace wrote:
> At 9:22 AM on 30 Jul 2009, E R wrote:
> > After compiling a template, Is there a way to get a list of all
> > variables that it references?
> > It seems that this is something the compiler could keep track of if it
> > doesn't already.
>
> If you have your compiled templates cached on disk (with the COMPILE_DIR
> option), you can try this command:
>
> perl -ne "while ( /\\\$stash->get\\(\\[?'(\w+)'/g ) { print \
> qq/\$1\\n/ }" /path/to/cached_template_file|sort -u
>
> I just quickly whipped that up based on the idea that every variable
> lookup would compile to a $stash->get() call.  It seems to work pretty
> well... but I'll admit it's not exactly graceful. :-)  And if there are
> references to variables that don't result in a $stash->get call, those
> would be missed.

There's also (at least) 'getref', and you probably want to find 
assigned-to-but-unused variables, too.

A somewhat cleaner way to do it would be to decorate Template::Directive 
methods ('ident', 'indentref', 'assign', plus probably some others that I've 
missed ;-).

-- 
Alexey A. Kiritchun
Yandex, search systems department
developer

_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to