Perl Monk, Perl Meditation | |
PerlMonks |
RFC: Template::YetAnotherby domm (Chaplain) |
on Nov 15, 2002 at 22:41 UTC ( [id://213300]=perlmeditation: print w/replies, xml ) | Need Help?? |
NAMETemplate::YetAnotherINTRODUCTIONWhy another templating system?There are a lot of templating modules on CPAN. Some are obvious, some are hidden in very strange namespaces (eg HTML::Processor). Some are used a lot, some not. I read a lot of manpages, but definitly not all and none completly. If there is a module doing what I am proposing, please inform me! Before we continue, read Perrin Harkins' "Choosing a Templating System", available here There are different types of Templating Systems available. Some are complete Application Frameworks, including stuff like Session Management, Form Handling etc. Examples include Mason, AxKit and Embperl. They are nice. They work. But that's not what I'm looking for. I want Just Templates. Why? Because IMO, the main reason for using templates is to seperate code from markup. The code produces some data. The markup displays the data. Those Application Frameworks don't seem to be too good at seperating code and markup (I have to admit though, that I know next to nothing about them, only that they are too big/powerfull). After all, they embed code in markup. So I am looking for a "pipeline"-type, Just-Template System, which reduces the number of available modules somewhat. The best-known contestors here are TemplateToolkit resp. Apache::Template and HTML::Template. But if you look at there manpages, you'll quickly find references to stuff like "TPL_LOOP" (HTML::Template). TT2 even has it's own mini-language. So, once again, code (even rather trivial) mixed with the markup. There is one module, CGI::FastTemplate, that does seperate code from markup completly. But the way different templates are strung together seems rather comlicated to me. But why is there no Templating System with a clean seperation of code and markup? There are two types of code (at least) that pollute nearly all Templating Systems:
I didn't find anything. So I am proposing this:
Template::YetAnotherThe name is just a placeholder right now, other ideas are:
The templates are completly dumb. There is absolutly no piece of code in a template - neither Perl nor "mini language". A template consists of arbitrary text (e.g. HTML) and Template Tags, e.g. % title % Your application builds up a data structure. The data structure consists of various Perl Data Types (Strings, Arrays, Hashes) and Template::YetAnother Objects (or Data Structures marked with some other kind of metainformation, e.g. with attributes) The data structure gets passed to Template::YetAnother, which magically find the right template for each object and replaces all Template Tags (recursivly) with the dumped/stringified data structure. Template::YetAnother is like Data::Dumper on steroids. It's the big Stringifyer. Template::YetAnother doesn't use one monolithic template, but a lot of small template fragments, each one correlating to a data type generated by the application. Template::YetAnother is just an idea right now. I am trying the "write documentation, write tests, write code" way of development... There is only a small prove-of-concept type bit of code (I can send it/post it if somebody cares..). I'll really appreciate feedback on this. I hope that this descripction is clear enought. If not, let me know and I'll post some clarification / examples. SYNOPSIS
DESCRIPTIONnew
Generates a new Template::YetAnother Handler Object. fill
Fill the template with the data in the data structure. _gen
Generates a new Template Fragment You usually do not have to call this. You just say
and AUTOLOAD passes it to "_gen" SEE ALSOSearch for "template" on http://search.cpan.org, if you dare.
Back to
Meditations
|
|