NAME
Data::Dumper::Perltidy - Stringify and pretty print Perl data structures.
SYNOPSIS
Use the Data::Dumper::Perltidy::Dumper()
function 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.
EXPORT
The only function exported by Data::Dumper::Perltidy is Dumper()
and it is exported automatically.
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.
The Data::Dumper $Data::Dumper::
configuration variable can 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
. In addition, and possibly more regrettably, it doesn't give access to the huge array of configuration options within Perl::Tidy
.
Patches, with tests and documentation, are welcome.
I may also add an option to use Data::Dumper::Names if available.
AUTHOR
John McNamara jmcnamara@cpan.org
BUGS
Please report any bugs or feature requests to bug-data-dumper-perltidy at rt.cpan.org
or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-Dumper-Perltidy.
The author/maintainer will be notified, and you'll be automatically notified in turn of progress on your bug.
Patches should be accompanied by tests and documentation. It isn't fair to do the fun part and leave the less-fun part to someone else. ;-)
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Data::Dumper::Perltidy
You can also look for further information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-Dumper-Perltidy
CPAN Ratings
Search CPAN
You can even email the author if you wish.
ACKNOWLEDGEMENTS
The authors and maintainers of Data::Dumper and Perl::Tidy.
The structure of this module was created using Module::Starter.
COPYRIGHT & LICENSE
Copyright 2009 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.