I always create harness code at the same time I create my HTML::Template files. This has the benefit of giving your designer a realistic platform on which to do their work. Implementing design on a faked-up template, as the TT user suggested above, only opens up the door to creating a broken interface.

Writing harness code at the same time you create your template files also has the added benefit of forcing me to think through the application and template functionality. Once I have a solid understanding of the functionality, it is a breeze to write a simple skeletal framework.

For creating web applications I use CGI::Application. Using this module, realistic harness code is easily created through the mechanism of run-modes. The more realistic the code is from the beginning, the more bug-free the final product will be. To illustrate what I'm talking about, here's an example of what a test harness for application and template development might look like:

package My::WebApp; use base qw/CGI::Application/; sub setup { my $self = shift; $self->start_mode('show_form'); $self->run_modes( show_form => 'show_form', list_results => 'list_results', show_detail => 'show_detail', ); } sub show_form { my $self = shift; my $tmpl = $self->load_tmpl('search_form.tmpl'); # Set up example data for template $tmpl->param('foo_checked' => '1'); return $tmpl->output(); } sub list_results { my $self = shift; my $tmpl = $self->load_tmpl('list.tmpl'); # Set up example data for template $tmpl->param('widget_loop' => [ { widget_name => 'widget_one', widget_id => '1' }, { widget_name => 'widget_two', widget_id => '2' }, { widget_name => 'widget_three', widget_id => '3' }, ]); return $tmpl->output(); } sub show_detail { my $self = shift; my $tmpl = $self->load_tmpl('detail_view.tmpl'); # Set up example data for template $tmpl->param('foo_id' => '1'); $tmpl->param('foo_name' => 'widget_one'); $tmpl->param('foo_checked' => 1); return $tmpl->output(); }

In reply to Re: Browser-viewable HTML::Template templates by Anonymous Monk
in thread Browser-viewable HTML::Template templates by dws

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.