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.
HTML::Template::Dumper - Output template data in a test-friendly format
# 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();
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.
Called just like HTML::Template->new() method.
$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:
In any of the cases, the module returned must inheirt from HTML::Template::Dumper::Format. Otherwise, die is called.
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.
Called with the data that was returned by output(). Returns a hashref of all the parameters.
Formaters must inheirt from HTML::Template::Dumper::Format. There are two methods used.
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.
All formatters must override this method.
It is called with a single reference which is formatted and returned.
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.
Timm Murray <tmurray@agronomy.org> http://www.agronomy.org CPAN ID: TMURRAY
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 |