Template::Generate - Generate TT2 templates from data and documents
This document describes version 0.04 of Template::Generate, released September 18, 2003.
use Template::Generate; my $obj = Template::Generate->new; my $template = $obj->generate( { first => 'Autrijus', last => 'Tang', score => 55, } => "(Simon's Blog) Score: 55, Name: Autrijus Tang", { first => 'Simon', last => 'Cozens', score => 61, } => "(Simon's Blog) Score: 61, Name: Simon Cozens", ); # "(Simon's Blog) Score: [% score %], Name: [% first %] [% last %]" print $template;
This module generates TT2 templates. It can take data structures and rendered documents together, and deduce templates that could have performed the transformation.
It is a companion to Template and Template::Extract; their relationship is shown below:
Template: ($template + $data) ==> $document # normal Template::Extract: ($document + $template) ==> $data # tricky Template::Generate: ($data + $document) ==> $template # very tricky
This module is considered experimental.
This method takes any number of ($data, $document) pairs, and returns a sorted list of possible templates that can satisfy all of them. In scalar context, the template with most variables is returned.
You may set $Template::Generate::DEBUG to a true value to display generated regular expressions.
$Template::Generate::DEBUG
Currently, the generate method only handles [% GET %] and [% FOREACH %] directives (both single-level and nested), although support for [% ... %] is planned in the future.
generate
[% GET %]
[% FOREACH %]
[% ... %]
Template, Template::Extract
Autrijus Tang <autrijus@autrijus.org>
Copyright 2003 by Autrijus Tang <autrijus@autrijus.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install Template::Generate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::Generate
CPAN shell
perl -MCPAN -e shell install Template::Generate
For more information on module installation, please visit the detailed CPAN module installation guide.