Inspired by Testing Template, or should I write a diff for TT templates?, I've worked on a subclass for HTML::Template that will dump only the datastructure that would be used to fill in the template. This makes it easy to parse the output for automatic testing tools.



NAME

  HTML::Template::Dumper - Output template data in a test-friendly format


SYNOPSIS

  # Switch the module used to the regular HTML::Template when you're 
  # finished testing
  #
  #use HTML::Template;
  use HTML::Template::Dumper;


  my $tmpl = 
        #HTML::Template
        HTML::Template::Dumper
        ->new( . . . );
  $tmpl->set_output_format( 'YAML' ) if $tmpl->isa( 'HTML::Template::Dumper' );

  # Do processing for the template

  $tmpl->output();


DESCRIPTION

This module helps you to test HTML::Template-based programs by printing only the information used to fill-in the template data. This makes it much easier to automatically parse the output of your program. Currently, data can be outputed by Data::Dumper (default) or YAML.

Note that the underlieing HTML::Template methods are still called, so options like strict and die_on_bad_params will still throw errors.


USAGE

new

Called just like HTML::Template->new() method.

set_output_format


  $tmpl->set_output_format( 'YAML' );

Set the output format. Currently known formats are:

  Format Name         Module
  -------------       --------
  Data_Dumper         HTML::Template::Dumper::Data_Dumper
  YAML                HTML::Template::Dumper::YAML

The module is found by applying the following rules:

  1. If the name has a :: anywhere, then it is taken as the full name of the module.

  2. Otherwise, the module is loaded from HTML::Template::Dumper::$NAME, where $NAME is what you passed to set_output_format.

  3. If the name didn't have a :: in it, but it didn't pass rule #2, then take it as the full name of the module.

  4. If none of the above work, then call die.

In any of the cases, the module returned must inheirt from HTML::Template::Dumper::Format. Otherwise, die is called.

output

Called just like the regular HTML::Template->output(), but will return a simplified view of the template data instead of the full object.

The print_to parameter is respected as specified in the HTML::Template documentation.

parse

Called with the data that was returned by output(). Returns a hashref of all the parameters.


WRITING NEW FORMATTERS

Formaters must inheirt from HTML::Template::Dumper::Format. There are two methods used.

new

Not called with anything. Returns a blessed reference. The default implementation blesses a scalar reference in order to save a little memory. This should be sufficient for most formatters, but you can always override this method if you need it.

dump

All formatters must override this method.

It is called with a single reference which is formatted and returned.

parse

All formaters must override this method.

It is called with a single scalar that holds the complete data returned by this formatter's dump method. It returns a hashref of all the parameters held in that dump.


AUTHOR

  Timm Murray <tmurray@agronomy.org>

  http://www.agronomy.org
  CPAN ID: TMURRAY


COPYRIGHT


SEE ALSO


Update: Added readmore tags.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated


In reply to RFC: HTML::Template::Dumper by hardburn

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.