Text-Template reviews

cpanratings
 

RSS | Module Info | Add a review of Text-Template

Text-Template (1.44) *****

I just love the idea of this module! It makes so much *sense*, to stop reinventing the wheel, and simply use perl itself as the templating language. Simple, elegant, not bloated. And this just *works*.
And I really like the ability to change delimeters, because it means I can have multiple "layers" of templating which I can put in a pipeline... (my scripts teperl and etalpmet wouldn't be able to work together otherwise...)
Sure, there are a few quibbles, such as what's been mentioned in earlier reviews, and, one I sort of wish would be possible to implement: to be able to go

{ if ($some_test) { }

some optional text I don't always want to output

blah blah blah

{ } # close if }

but I suspect such a construct violates the whole way the module works. I'll make do with HERE documents...

Text-Template (1.44) *****

ditto mirod :) simple and powerful module and does not implement a "template language"...

The only bad thing is, you must use a global variable for the variables inside a template, you can't declare it with my(), but there is a hash mechanism to avoid this or you can use package globals.

Text::Template / Text-Template (1.44) *****

There are (way too!) many templating systems on CPAN, but IMHO none of them is as simple and as elegant as Text::Template.
Text::Template just lets you include Perl code in a file or a string. Include Perl code between { } and it will be executed and the return value will replace the code fragment. Extra features include a way to change the delimiters, a special variable that gather the output, error handling, a safe mode and the option to refer to variables from your code, from a hash or from a specific namespace.
This will let you generate plain text, but also HTML, XML... any text-based format really.
The drawback of this approach is that it is probably not recommended to give a template that includes too much Perl to a graphic designer. OTOH a template maintainer who already knows Perl does not have to learn a new templating language, and can use all of the power of Perl.