VERSION
This document describes version 0.20 of Data::Dmp (from Perl distribution Data-Dmp), released on 2016-06-03.SYNOPSIS
use Data::Dmp; # exports dd() and dmp()
dd [1, 2, 3]; # prints "[1,2,3]"
$a = dmp({a => 1}); # -> "{a=>1}"
DESCRIPTION
Data::Dmp is a Perl dumper like Data::Dumper. It's compact (only about 175 lines of code long), starts fast and does not use any non-core modules except Regexp::Stringify when dumping regexes. It produces compact single-line output (similar to Data::Dumper::Concise). It roughly has the same speed as Data::Dumper (usually a bit faster for smaller structures) and faster than Data::Dump, but does not offer the various formatting options. It supports dumping objects, regexes, circular structures, coderefs. Its code is first based on Data::Dump: I removed all the parts that I don't need, particularly the pretty formatting stuffs) and added some features that I need like proper regex dumping and coderef deparsing.SETTINGS
$Data::Dmp::OPT_PERL_VERSION => str (default: 5.010)
Set target Perl version. If you set this to, say 5.010, then the dumped code will keep compatibility with Perl 5.10.0. This is used in the following ways:- passed to Regexp::Stringify
-
when dumping code references
For example, in perls earlier than 5.016, feature.pm does not understand:
no feature ':all';
so we replace it with:
no feature;
$Data::Dmp::OPT_REMOVE_PRAGMAS => bool (default: 0)
If set to 1, then pragmas at the start of coderef dump will be removed. Coderef dump is produced by B::Deparse and is of the form like:
sub { use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval'; $a <=> $b }
If you want to dump short coderefs, the pragmas might be distracting. You can turn turn on this option which will make the above dump become:
sub { $a <=> $b }
Note that without the pragmas, the dump might be incorrect.
BENCHMARKS
[1..10]: Rate Data::Dump Data::Dumper Data::Dmp Data::Dump 21199+-23/s -- -67.3% -76.4% Data::Dumper 64920+-110/s 206.24+-0.62% -- -27.7% Data::Dmp 89744+-27/s 323.34+-0.47% 38.24+-0.24% -- [1..100]: Rate Data::Dump Data::Dmp Data::Dumper Data::Dump 2667.7+-2.7/s -- -76.0% -76.2% Data::Dmp 11131.4+-3.1/s 317.27+-0.43% -- -0.6% Data::Dumper 11199+-57/s 319.8+-2.2% 0.61+-0.51% -- Some mixed structure: Rate Data::Dump Data::Dmp Data::Dumper Data::Dump 6096+-16/s -- -68.4% -80.5% Data::Dmp 19284+-39/s 216.3+-1% -- -38.5% Data::Dumper 31335+-94/s 414+-2% 62.49+-0.58% --
FUNCTIONS
dd($data, ...) => $data ...
Exported by default. Like "Data::Dump"'s "dd" (a.k.a. "dump"), print one or more data to STDOUT. Unlike "Data::Dump"'s "dd", it always prints and return the original data (like XXX), making it convenient to insert into expressions. This also removes ambiguity and saves one "wantarray()" call.dmp($data, ...) => $str
Exported by default. Return dump result as string. Unlike "Data::Dump"'s "dd" (a.k.a. "dump"), it never prints and only return the data.FAQ
When to use Data::Dmp? How does it compare to other dumper modules?
Data::Dmp might be suitable for you if you want a relatively fast pure-Perl data structure dumper to eval-able Perl code. It produces compact, single-line Perl code but offers little/no formatting options. Data::Dmp and Data::Dump module family usually produce Perl code that is ``more eval-able'', e.g. it can recreate circular structure.Data::Dump produces visually nicer output (some alignment, use of range operator to shorten lists, use of base64 for binary data, etc) but no built-in option to produce compact/single-line output. It's more suitable for debugging. It's also relatively slow. I usually use its variant, Data::Dump::Color, for console debugging.
Data::Dumper is a core module, offers a lot of formatting options (like disabling hash key sorting, setting verboseness/indent level, and so on) but you usually have to configure it quite a bit before it does exactly like you want (that's why there are modules on CPAN that are just wrapping Data::Dumper with some configuration, like Data::Dumper::Concise et al). It does not support dumping Perl code that can recreate circular structures.
Of course, dumping to eval-able Perl code is slow (not to mention the cost of re-loading the code back to in-memory data, via eval-ing) compared to dumping to JSON, YAML, Sereal, or other format. So you need to decide first whether this is the appropriate route you want to take. (But note that there is also Data::Dumper::Limited and Data::Undump which uses a format similar to Data::Dumper but lets you load the serialized data without eval-ing them, thus achieving the speed comparable to JSON::XS).
HOMEPAGE
Please visit the project's homepage at <https://metacpan.org/release/Data-Dmp>.SOURCE
Source repository is at <https://github.com/perlancar/perl-Data-Dmp>.BUGS
Please report any bugs or feature requests on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Dmp>When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
AUTHOR
perlancar <[email protected]>COPYRIGHT AND LICENSE
This software is copyright (c) 2016 by [email protected].This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.