Actually, HTML::Template allows you to pass in subroutines which will get called to get the parameter values:
# with a subroutine reference that gets called to get the value # of the scalar. The sub will recieve the template object as a # parameter. $self->param(PARAM => sub { return 'value' });
However, since these subroutines cannot be parameterized from within the template, I am not sure how much use this is.

I'd love to be able to do the following (which is not supported, however):

$tmpl->param( blah => sub { my ($a, $b, $c) = @_; return 'something'; } ); <tmpl_var name='blah(1,2,3)'>

I think HTML::Template should have some simple kind of expression language that would allow you to these things, as well as drilling down into hashes and arrays, accessing objects (which should eliminate the need for callbacks), and doing simple arithmetics .

HTML::Template::Expr is doing some of these things already.

(Like everyone else, I have started to implement my own templating system with these ideas in mind. It is mostly a project to teach myself about Parrot, but if you are interested: http://budgie.sourceforge.net/ )


In reply to Re^3: Templating algorithm - pass in variables vs callback? by Thilosophy
in thread Templating algorithm - pass in variables vs callback? by Tanktalus

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.