NAME
Template::Generate - Generate TT2 templates from data and documents
VERSION
This document describes version 0.04 of Template::Generate, released September 18, 2003.
SYNOPSIS
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;
DESCRIPTION
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.
METHODS
generate($data => $document, $data => $document, ...)
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.
CAVEATS
Currently, the generate
method only handles [% GET %]
and [% FOREACH %]
directives (both single-level and nested), although support for [% ... %]
is planned in the future.
SEE ALSO
AUTHORS
Autrijus Tang <autrijus@autrijus.org>
COPYRIGHT
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.