Have you asked these questions on the HTML::Template list? You could probably get a few really good ideas from them. In the meantime, you should look at HTML::Template::Expr which will let you execute functions inside of your templates. You could probably do something like
use HTML::Template::Expr; HTML::Template::Expr->register_function( execute => sub { shift->run(); } );
then in your template
<tmpl_var expr="execute(some_object)">
I would also suggest you look at CGI::Application::Plugin::AnyTemplate as well.

Eventialy I will want to change CGI::App (or create something similar) to add this functionality and also strip of a need to define wich methods are OK to be run_modes. Idea that I have is simply alow any sub whose name doesnt start with _.

Look at CGI::Application::Plugin::AutoRunMode for something very similar that uses method attributes to designate a sub as a run mode. But I really think that using a leading '_' on a method a really bad idea. It would be completely counter-intuitive to what any other perl programmer would think since it's tradition for '_' to make private methods.

-- More people are killed every year by pigs than by sharks, which shows you how good we are at evaluating risk. -- Bruce Schneier

In reply to Re: Extending HTML::Template, how to do it? by mpeters
in thread Extending HTML::Template, how to do it? by techcode

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.