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.
Data::Dumper
YAML
Note that the underlieing HTML::Template methods are still called, so options like strict and die_on_bad_params will still throw errors.
strict
die_on_bad_params
Called just like the HTML::Template->new() method.
HTML::Template->new()
$tmpl->set_output_format( 'YAML', @extra_params );
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.
HTML::Template::Dumper::$NAME
$NAME
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.
die
In any of the cases, the module returned must inheirt from HTML::Template::Dumper::Format. Otherwise, die is called.
HTML::Template::Dumper::Format
Any parameters you pass after the format will be put directly into the formatter's new() method.
new()
Called just like the regular HTML::Template->output(), but will return a simplified view of the template data instead of the full object.
HTML::Template->output()
The print_to parameter is respected as specified in the HTML::Template documentation.
print_to
HTML::Template
Called with a reference to a subroutine. Before output returns, this subroutine will be called with a scalar reference to the data that would otherwise have been directly returned by output. Your filter subroutine can do any modification on the value it wants. For instance, if you want the output to be (almost) valid HTML, you could write:
output
$tmpl->set_output_filter( sub { my $ref = shift; $$ref = q{ <html> <head> <title>Debugging Output</title> </head> <body bgcolor="#FFFFFF"> <pre> } . $$ref . q{ </pre> </body> </html> } });
Note that the result may or may not work with parse, depending on your filter and the format used by your dumper.
parse
Called with the data that was returned by output(). Returns a hashref of all the parameters.
output()
This can also be called as a class method, in which case it can take a second paramter containing the data format that the first paramter is in. This second parameter has the same rules applied to it as set_output_format().
set_output_format()
Formaters must inheirt from HTML::Template::Dumper::Format. There are two methods that need to be overridden.
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.
dump
Yes.
Timm Murray <tmurray@agronomy.org> http://www.agronomy.org CPAN ID: TMURRAY
Copyright 2003, American Society of Agronomy. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of either:
a) the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version, or
b) the "Artistic License" which comes with Perl.
perl(1). HTML::Template(3). Data::Dumper(3). YAML(3).
To install HTML::Template::Dumper, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Template::Dumper
CPAN shell
perl -MCPAN -e shell install HTML::Template::Dumper
For more information on module installation, please visit the detailed CPAN module installation guide.