NAME
Data::Dumper::Perltidy - Dump and pretty print Perl data structures.
SYNOPSIS
To use Data::Dumper::Perltidy::Dumper()
to stringify and pretty print a Perl data structure:
use Data::Dumper::Perltidy;
...
print Dumper $some_data_structure;
DESCRIPTION
Data::Dumper::Perltidy
encapsulates both Data::Dumper
and Perl::Tidy
to provide a function that stringifies a Perl data structure in a pretty printed format. See the documentation for Data::Dumper and Perl::Tidy for further information.
Data::Dumper can be used for, among other things, stringifying complex Perl data structures into a format that is suitable for printing and debugging.
Perl::Tidy can be used to pretty print Perl code in a consistent and configurable manner.
Data::Dumper also provides a certain level of pretty printing via the $Data::Dumper::Indent
variable but it isn't quite as nice as the Perl::Tidy output.
Let's look at an example to see how this module can be used. Say you have a complex data structure that you wish to inspect. You can use the Data::Dumper::Perltidy::Dumper()
function as follows (note that the syntax is the same as Data::Dumper):
#!/usr/bin/perl -w
use strict;
use Data::Dumper::Perltidy;
my $data = [{ title => 'This is a test header' },{ data_range =>
[ 0, 0, 3, 9 ] },{ format => 'bold' }];
print Dumper $data;
This would print out:
$VAR1 = [
{ 'title' => 'This is a test header' },
{ 'data_range' => [ 0, 0, 3, 9 ] },
{ 'format' => 'bold' }
];
By comparison the standard Data::Dumper::Dumper()
output would be:
$VAR1 = [
{
'title' => 'This is a test header'
},
{
'data_range' => [
0,
0,
3,
9
]
},
{
'format' => 'bold'
}
];
Which isn't too bad but if you are used to Perl::Tidy and the perltidy utility you may prefer the Data::Dumper::Perltidy::Dumper()
output.
FUNCTIONS
Dumper()
The Dumper()
function takes a list of perl structures and returns a stringified and pretty printed form of the values in the list. The values will be named $VARn
in the output, where n
is a numeric suffix.
You can modify the Perl::Tidy output by passing arguments via the $Data::Dumper::Perltidy::ARGV
configuration variable:
$Data::Dumper::Perltidy::ARGV = '-nst -mbl=2 -pt=0 -nola';
See the Perl::Tidy docs for more information on the available arguments. By default Data::Dumper::Perltidy
uses the argument -npro
to ignore any local .perltidyrc
configuration file.
The Data::Dumper $Data::Dumper::
configuration variables can also be used to influence the output where applicable. For further information see the Data::Dumper documentation.
Note: unlike Data::Dumper::Dumper()
this function doesn't currently return a list of strings in a list context.
RATIONALE
I frequently found myself copying the output of Data::Dumper::Dumper()
into an editor so that I could run perltidy
on it. This module scratches that itch.
LIMITATIONS
This module doesn't attempt to implement all, or even most, of the functionality of Data::Dumper
.
AUTHOR
John McNamara <jmcnamara@cpan.org>
BUGS
Please report any bugs or feature requests to https://github.com/jmcnamara/data-dumper-perltidy/issues on Github.
ACKNOWLEDGEMENTS
The authors and maintainers of Data::Dumper
and Perl::Tidy
.
SEE ALSO
Data::Printer, which also has a full list of alternatives.
COPYRIGHT & LICENSE
Copyright 2009-2012 John McNamara, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.