Data::Template - Generate data structures from templates
use Data::Template; $dt = Data::Template->new(); $tt = { who => 'me', to => '${a}', subject => 'Important - trust me', body => <<'BODY', When I was ${b}, I realized that I had not ${c}. Do you? BODY }; $data = $dt->process($tt, { a => 'someone', b => 'somewhere', c => '100$' });
Templates usually convert text templates to text. This module goes further by converting data structure templates to data structures.
Beyond that, nothing new. I am lazy and the Template Toolkit is here today - so I use it.
The current implementation handles hash refs, array refs and non-ref scalars (strings). The processing rules are:
(outdated) Each non-ref scalar starting with '=' is processed as a template.
(outdated) Other non-ref scalars are left as they are. Except, those starting with '\=' for which s/^\\=/=/ is done (a way to have strings starting with '=').
s/^\\=/=/
Array refs have their elements recursively processed.
Hash refs have keys processed as non-ref scalars and values recursively processed.
(The implementation so far is so naïve that causes laughs. But laughing may be good.)
A constructor. Wow!
$data = $dt->process($tt, $vars)
Process the templates generating a new data structure. It dies on errors (or not - see constructor parameters to come soon).
For processing a scalar.
For processing an array.
For processing a hash.
Soon.
Template - as this is used to process the text templates.
Please reports bugs via CPAN RT, http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-Template
A. R. Ferreira, <ferreira@cpan.org>
Copyright (C) 2006-2007 by A. R. Ferreira
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'naïve'. Assuming CP1252
To install Data::Template, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Template
CPAN shell
perl -MCPAN -e shell install Data::Template
For more information on module installation, please visit the detailed CPAN module installation guide.