[cgiapp] Planned CGI::Application update: html_tmpl_class() will now allow setting-- great for debugging!

Mark Stosberg mark at summersault.com
Fri Jul 3 21:34:45 EDT 2009


I'm planning to release a simple update to CGI::Application soon and wanted to
allow for some feedback first.

Relatively recently, the 'html_tmpl_class()' class method was added, as a way
to more easily specify an alternative to HTML::Template. Because of the simple
original implemenation, this needed to be done with a sub-class.

I found a great use of this to use HTML::Template::Dumper for testing and
debugging, as I illustrate below. To make this even easier, the update will
allow you to set the html_tmpl_class() value directly, rather than creating a
sub-class if you just want to overide this one method.

The following example will be added to the docs for load_tmpl():

#####

Here's an example case allowing you to precisely test what's sent to your
templates:

    $ENV{CGI_APP_RETURN_ONLY} = 1;
    my $webapp = WebApp->new;
       $webapp->html_tmpl_class('HTML::Template::Dumper');
    my $out_str = $webapp->run;
    my $tmpl_href = eval "$out_str";

    # Now Precisely test what would be set to the template
    is ($tmpl_href->{pet_name}, 'Daisy', "Daisy is sent template");

This is a powerful technique because HTML::Template::Dumper loads and considers
the template file would actually be used. If the 'pet_name' token was missing
in the template, the above test would fail. So, you are testing both your code
and your templates in a much more precise way than using simple regular
expressions to see if the string "Daisy" appeared somewhere on the page.

####

Any further suggestions before I upload this?

    Mark

-- 
http://mark.stosberg.com/





More information about the cgiapp mailing list