Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Extending HTML::Template, how to do it?

by techcode (Hermit)
on Jun 16, 2005 at 22:26 UTC ( [id://467477]=perlquestion: print w/replies, xml ) Need Help??

techcode has asked for the wisdom of the Perl Monks concerning the following question:

I've been using combination of CGI::Application, HTML::Template and few other modules for quite some time.

But I need to ajust it a bit to match my needs. And I would like to add a new template tag - similar to TMPL_INCLUDE. But it would not include other template files, but output of some object.

Kind of, if it finds say <-- TMPL_PLUGIN NAME="some_name" --> it will require some_name.pm; and then call it's method, say output.

I've been looking into filters for HTML::Template, but simply couldnt make it work for anything. Even some simple thing like any other regex that normaly works ...

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 _.
  • Comment on Extending HTML::Template, how to do it?

Replies are listed 'Best First'.
Re: Extending HTML::Template, how to do it?
by mpeters (Chaplain) on Jun 17, 2005 at 00:54 UTC
    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

      No I havent asked it on HTML::Template's mailing list. Will check out. But also your solution seems quite interesting and quite simpler than what I was thinking - probably even faster :)

      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.
      Well that's the general idea, and it depends in the way you look at it. In some way, it is private - as that it shouldnt be able to execute it as run_mode. But will think about some other notation.

      I also tougth to implement few other things (sessions, some sort of DB abstraction that I wrote and few more things) in an all-in-one convinient module/framework

      Currently I just want this done for myself as I have few projets comming (last semester project, and disertation project, few sites I want to do) and dont have time to write this for the public - not to mention that I dont have knowlege (testing, documentation ...etc) to put it on CAPN (and obviosly no time to learn it).

      I just found CGI::Builder, seems nice, will check out that first - before I start writing myown framework ;)
        Honestly if you're interested in frameworks, then you should really look at what's happening in the CGI::Application world at this time. It has a new plugin/callback system and if you look at CPAN you'll see lots of new plugins including one for session integration.

        And if those aren't enough for you, there is a soon to be arriving CGI::Application::Framework. And if that still isn't enough for you, I'd look at Catalyst.

        -- More people are killed every year by pigs than by sharks, which shows you how good we are at evaluating risk. -- Bruce Schneier
Re: Extending HTML::Template, how to do it?
by dragonchild (Archbishop) on Jun 17, 2005 at 13:31 UTC
    I've been playing with Catalyst this week and I have found it compares very favorably to CGI::Application in terms of functionality and capabilities. It wins big in that it promotes the use of Class::DBI and Template Toolkit, which are the richer offerings in their respective categories.

    The only reason, in my opinion, to use CGI::Application over Catalyst is that CGI::Application has a longer track record. If that isn't a big factor for you, use Catalyst.


    • In general, if you think something isn't in Perl, try it out, because it usually is. :-)
    • "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://467477]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-22 07:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found