1Data::Dmp(3)          User Contributed Perl Documentation         Data::Dmp(3)
2
3
4

NAME

6       Data::Dmp - Dump Perl data structures as Perl code
7

VERSION

9       This document describes version 0.23 of Data::Dmp (from Perl
10       distribution Data-Dmp), released on 2017-01-30.
11

SYNOPSIS

13        use Data::Dmp; # exports dd() and dmp()
14        dd [1, 2, 3]; # prints "[1,2,3]"
15        $a = dmp({a => 1}); # -> "{a=>1}"
16

DESCRIPTION

18       Data::Dmp is a Perl dumper like Data::Dumper. It's compact (only about
19       175 lines of code long), starts fast and does not use any non-core
20       modules except Regexp::Stringify when dumping regexes. It produces
21       compact single-line output (similar to Data::Dumper::Concise). It
22       roughly has the same speed as Data::Dumper (usually a bit faster for
23       smaller structures) and faster than Data::Dump, but does not offer the
24       various formatting options. It supports dumping objects, regexes,
25       circular structures, coderefs. Its code is first based on Data::Dump: I
26       removed all the parts that I don't need, particularly the pretty
27       formatting stuffs) and added some features that I need like proper
28       regex dumping and coderef deparsing.
29

SETTINGS

31   $Data::Dmp::OPT_PERL_VERSION => str (default: 5.010)
32       Set target Perl version. If you set this to, say 5.010, then the dumped
33       code will keep compatibility with Perl 5.10.0. This is used in the
34       following ways:
35
36       ·   passed to Regexp::Stringify
37
38       ·   when dumping code references
39
40           For example, in perls earlier than 5.016, feature.pm does not
41           understand:
42
43            no feature ':all';
44
45           so we replace it with:
46
47            no feature;
48
49   $Data::Dmp::OPT_REMOVE_PRAGMAS => bool (default: 0)
50       If set to 1, then pragmas at the start of coderef dump will be removed.
51       Coderef dump is produced by B::Deparse and is of the form like:
52
53        sub { use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval'; $a <=> $b }
54
55       If you want to dump short coderefs, the pragmas might be distracting.
56       You can turn turn on this option which will make the above dump become:
57
58        sub { $a <=> $b }
59
60       Note that without the pragmas, the dump might be incorrect.
61
62   $Data::Dmp::OPT_DEPARSE => bool (default: 1)
63       Can be set to 0 to skip deparsing code. Coderefs will be dumped as
64       "sub{"DUMMY"}" instead, like in Data::Dump.
65
66   $Data::Dmp::OPT_STRINGIFY_NUMBERS => bool (default: 0)
67       If set to true, will dump numbers as quoted string, e.g. 123 as "123"
68       instead of 123. This might be helpful if you want to compute the hash
69       of or get a canonical representation of data structure.
70

BENCHMARKS

72        [1..10]:
73                              Rate    Data::Dump Data::Dumper Data::Dmp
74        Data::Dump     30417+-55/s            --       -66.2%    -74.0%
75        Data::Dumper   89888+-79/s  195.52+-0.6%           --    -23.1%
76        Data::Dmp    116890+-160/s 284.29+-0.87% 30.04+-0.21%        --
77
78        [1..100]:
79                               Rate    Data::Dump  Data::Dmp Data::Dumper
80        Data::Dump    3712.3+-7.9/s            --     -73.9%       -74.9%
81        Data::Dmp    14211.3+-4.9/s 282.82+-0.82%         --        -3.8%
82        Data::Dumper    14771+-28/s   297.9+-1.1% 3.94+-0.2%           --
83
84        Some mixed structure:
85                            Rate    Data::Dump    Data::Dmp Data::Dumper
86        Data::Dump    8764+-16/s            --       -67.6%       -80.1%
87        Data::Dmp    27016+-36/s  208.28+-0.7%           --       -38.6%
88        Data::Dumper 43995+-13/s 402.02+-0.95% 62.85+-0.22%           --
89

FUNCTIONS

91   dd($data, ...) => $data ...
92       Exported by default. Like "Data::Dump"'s "dd" (a.k.a. "dump"), print
93       one or more data to STDOUT. Unlike "Data::Dump"'s "dd", it always
94       prints and return the original data (like XXX), making it convenient to
95       insert into expressions. This also removes ambiguity and saves one
96       "wantarray()" call.
97
98   dmp($data, ...) => $str
99       Exported by default. Return dump result as string. Unlike
100       "Data::Dump"'s "dd" (a.k.a. "dump"), it never prints and only return
101       the data.
102

FAQ

104   When to use Data::Dmp? How does it compare to other dumper modules?
105       Data::Dmp might be suitable for you if you want a relatively fast pure-
106       Perl data structure dumper to eval-able Perl code. It produces compact,
107       single-line Perl code but offers little/no formatting options.
108       Data::Dmp and Data::Dump module family usually produce Perl code that
109       is "more eval-able", e.g. it can recreate circular structure.
110
111       Data::Dump produces visually nicer output (some alignment, use of range
112       operator to shorten lists, use of base64 for binary data, etc) but no
113       built-in option to produce compact/single-line output. It's more
114       suitable for debugging.  It's also relatively slow. I usually use its
115       variant, Data::Dump::Color, for console debugging.
116
117       Data::Dumper is a core module, offers a lot of formatting options (like
118       disabling hash key sorting, setting verboseness/indent level, and so
119       on) but you usually have to configure it quite a bit before it does
120       exactly like you want (that's why there are modules on CPAN that are
121       just wrapping Data::Dumper with some configuration, like
122       Data::Dumper::Concise et al). It does not support dumping Perl code
123       that can recreate circular structures.
124
125       Of course, dumping to eval-able Perl code is slow (not to mention the
126       cost of re-loading the code back to in-memory data, via eval-ing)
127       compared to dumping to JSON, YAML, Sereal, or other format. So you need
128       to decide first whether this is the appropriate route you want to take.
129       (But note that there is also Data::Dumper::Limited and Data::Undump
130       which uses a format similar to Data::Dumper but lets you load the
131       serialized data without eval-ing them, thus achieving the speed
132       comparable to JSON::XS).
133
134   Is the output guaranteed to be single line dump?
135       No. Some things can still produce multiline dump, e.g. newline in
136       regular expression.
137

HOMEPAGE

139       Please visit the project's homepage at
140       <https://metacpan.org/release/Data-Dmp>.
141

SOURCE

143       Source repository is at <https://github.com/perlancar/perl-Data-Dmp>.
144

BUGS

146       Please report any bugs or feature requests on the bugtracker website
147       <https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Dmp>
148
149       When submitting a bug or request, please include a test-file or a patch
150       to an existing test-file that illustrates the bug or desired feature.
151

SEE ALSO

153       Data::Dump and other variations/derivate works in Data::Dump::*.
154
155       Data::Dumper and its variants.
156
157       Data::Printer.
158
159       YAML, JSON, Storable, Sereal, and other serialization formats.
160

AUTHOR

162       perlancar <perlancar@cpan.org>
163
165       This software is copyright (c) 2017 by perlancar@cpan.org.
166
167       This is free software; you can redistribute it and/or modify it under
168       the same terms as the Perl 5 programming language system itself.
169
170
171
172perl v5.30.0                      2019-07-26                      Data::Dmp(3)
Impressum