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:
- If the name has a :: anywhere, then it is taken as the full name of the module.
- Otherwise, the module is loaded from HTML::Template::Dumper::$NAME, where $NAME is what you passed to set_output_format.
- 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.
- 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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: RFC: HTML::Template::Dumper
by jdtoronto (Prior) on Nov 17, 2003 at 18:11 UTC | |
Re: RFC: HTML::Template::Dumper
by dws (Chancellor) on Nov 17, 2003 at 20:27 UTC | |
Re: RFC: HTML::Template::Dumper
by pernod (Chaplain) on Nov 18, 2003 at 11:16 UTC | |
Re: RFC: HTML::Template::Dumper
by EvdB (Deacon) on Nov 18, 2003 at 20:01 UTC |