Maybe it's best to use an existing implementation as the base interface. I would propose Template Toolkit because it seems to have the most comprehensive API of all templating systems. The "TPD" for Template Toolkit would virtually do nothing other than fowarding method calls to TT directly. Other template systems would need a small wrapper module to translate the TT-like method calls. Generally only a subset of the TT functionality would be supported, but this should be in most cases sufficient.

Here's a quick sketch how this could look like:

#!/usr/bin/perl -w use strict; { package MetaTemplate::TT; use base qw(Template); } { package MetaTemplate::HTML_Template; use HTML::Template; sub new { my $class = shift; bless {}, $class; } sub process { my($self, $input, $vars, $output) = @_; my @ht_args; if (ref $input eq 'SCALAR') { @ht_args = (scalarref => $input); } else { @ht_args = (filename => $input); } my $ht = HTML::Template->new(@ht_args); if ($vars) { while(my($k,$v) = each %$vars) { $ht->param($k => $v); } } my $o = $ht->output; if (ref $output eq 'SCALAR') { $$output = $o; } elsif (defined $output) { open(my $OUT, "> $output") or die $!; print $OUT $o; } else { print $o; } } } { package MetaTemplate::Text_ScriptTemplate; use Text::ScriptTemplate; sub new { my $class = shift; bless {}, $class; } sub process { my($self, $input, $vars, $output) = @_; my $tmpl = Text::ScriptTemplate->new; if (ref $input eq 'SCALAR') { $tmpl->pack($$input); } else { $tmpl->load($input); } if ($vars) { $tmpl->setq(%$vars); } my $o = $tmpl->fill; if (ref $output eq 'SCALAR') { $$output = $o; } elsif (defined $output) { open(my $OUT, "> $output") or die $!; print $OUT $o; } else { print $o; } } } my $t1 = MetaTemplate::TT->new; $t1->process(\<<EOF, { answer => 42 }); The answer is [% answer %]. EOF my $t2 = MetaTemplate::HTML_Template->new; $t2->process(\<<EOF, { answer => 42 }); The answer is <TMPL_VAR NAME=answer>. EOF my $t3 = MetaTemplate::Text_ScriptTemplate->new; $t3->process(\<<'EOF', { answer => 42 }); The answer is <%=$answer%>. EOF

In reply to Re: 1001 CPAN Template modules by eserte
in thread 1001 CPAN Template modules by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.