Perl - Template Toolkit - How get list of variables in the template? -


i using perl dancer , template::toolkit.

i'm trying create generic routine passed template , http get/post parameters.

i need find way list of variables in template, can retrieve them parameters, or return error if 1 or more missing.

i can go ugly regex route, hoping better/cleaner way.

all the templates xml/soap few variables here , there.

any ideas?

if enable trace_vars option on template context can use variables method hash of values accessed.

this code shows brief example

use strict; use warnings;  use template::context; use data::dump;  $template = '[% person.name %] <[% person.email %]>';  $context = template::context->new(trace_vars => 1); $compiled = $context->template(\$template) or die $context->error; $variables = $compiled->variables;  dd $variables; 

output

{ person => { email => {}, name => {} } } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -