http://www.perlmonks.org?node_id=467516


in reply to Extending HTML::Template, how to do it?

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