Template::Plugin::DataPrinter - Template Toolkit dumper plugin using Data::Printer
version 0.017
[% USE DataPrinter %] [% DataPrinter.dump(variable) %] [% DataPrinter.dump_html(variable) %]
This is a dumper plugin for Template::Toolkit which uses Data::Printer instead of Data::Dumper.
Data::Printer is a colorised pretty-printer with nicely human-readable object output.
The provided methods match those of Template::Plugin::Dumper.
Generates an ansi-colorised dump of the data structures passed.
[% USE DataPrinter %] [% DataPrinter.dump(myvar) %] [% DataPrinter.dump(myvar, yourvar) %]
Generates a html-formatted dump of the data structures passed. The ansi colorisation is converted to html by HTML::FromANSI::Tiny.
[% USE DataPrinter %] [% DataPrinter.dump_html(myvar) %] [% DataPrinter.dump_html(myvar, yourvar) %]
This plugin has no configuration of its own, but the underlying Data::Printer and HTML::FromANSI::Tiny modules can be configured using the dp and hfat parameters.
dp
hfat
[% USE DataPrinter(dp = { ... }, hfat = { ... }) %]
A hashref containing the params to be passed to Data::Printer::import.
Data::Printer::import
See the Data::Printer documentation for more information.
A hashref containing the params to be passed to HTML::FromANSI::Tiny->new.
HTML::FromANSI::Tiny->new
See the HTML::FromANSI::Tiny documentation for more information.
Colorisation is turned on by default. To turn it off, use Data::Printer's colored parameter:
colored
[% USE DataPrinter(dp = { colored = 0 }) %]
This module can be used more-or-less as a drop-in replacement for the default Dumper plugin by specifying an explicit plugin mapping to the Template constructor:
Template
my $template = Template->new(..., PLUGINS => { Dumper => 'Template::Plugin::DataPrinter', }, );
Then existing templates such as the one below will automatically use the DataPrinter plugin instead.
DataPrinter
[% USE Dumper(Indent=0, Pad="<br>") %] [% Dumper.dump(variable) %] [% Dumper.dump_html(variable) %]
Any unrecognised constructor parameters are silently ignored, so the Indent and Pad parameters above will have no effect.
Indent
Pad
A custom Data::Printer configuration file can be specified like so:
[% USE DataPrinter(dp = { rc_file = '/path/to/my/rcfile.conf' }) %]
Beware that setting colored = 0 in your .dataprinter file will not work. This must be specified in the USE DataPrinter code.
colored = 0
USE DataPrinter
[% USE DataPrinter(dp = { rc_file = '...', colored = 0 }) %]
Setting colored = 0 in the .dataprinter file will not work. The colored = 0 setting must appear in the USE DataPrinter line.
Template::Toolkit
Data::Printer
HTML::FromANSI::Tiny
Stephen Thirlwall <sdt@cpan.org>
This software is copyright (c) 2021 by Stephen Thirlwall.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Template::Plugin::DataPrinter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::Plugin::DataPrinter
CPAN shell
perl -MCPAN -e shell install Template::Plugin::DataPrinter
For more information on module installation, please visit the detailed CPAN module installation guide.