NAME Templater - Parse data inside a template. SYNOPSIS #!/usr/bin/perl use Text::Templater; my $tpl = new Text::Templater($tagname); #Default tagname is "tpl" $tpl->setSource($some_template_text); #Set the data source... $tpl->setData({ name => ['bob', undef, 'daniel'], color => ['red', 'green', 'blue'], }); #Or use existing objects. $tpl->setData($cgi); $tpl->setData($sth); print $tpl->parse(); #Get the result. ABSTRACT The objective of the Templater object is to separate data manipulation from it's representation while keeping out logic as much as possible from the representation side. DESCRIPTION Templater receive the template and the data to be binded in the template. Then using the parse method, it return the result. One tag and 5 properties are defined in a xmlish way to describe data in the template. Internaly regular expressions are used instead of a xml parser, so it can be used with any kind of text files. Still, you can also use it in your xml while keeping their well-formedness and valitiy of the document. Tag properties id="unique" You can specify the id of an element to make late reference to it. This can be used for not breaking the well-formedness of a xml document. You could write instead of " />. Note that the second alternalive will work as well. name="name" You can bind a specific data value to a tag using it's hash key. A tag without a name does not make sense. In the synopsis; eqals red. index="num" Specify the index of the value to be binded. If not specified, the current iteration is taken. In the synopsis; eqals green. nullout="yes|no" If the binded value is undef or '', all the expression is discarded. no is taken by default. In the synopsis: hi equals nothing. list="CONST:1,2,3,..." Defines a specific constant "CONST" into the tag inner source. The value of CONST will alternativly be 1,2,3,1,2,etc The backslash is used as a dummy quote character. But no, you can't \u or \b :-) Tag forms The templater tag can be written as: or . The first form will replace the tag with the corresponding binded data. The second form will loop each value of the binded data; the concatenation of each result is used as the sole result. Methods new Creates a new Templater object. You can specify the tag name to be used in templates. No verification of the validity of name is made. setSource If a scalar is passed, it is set to be the template. The source of the object is returned. setData If a value is passed, it is set to be the data to bind. CGI and STH objects can be passed. The data of the object is returned. parse Takes the template and parse the data inside using the templater tags. The parsed template is returned. CREDITS Mathieu Gagnon, (c) 2005 This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.