.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Data::Dmp 3pm" .TH Data::Dmp 3pm "2022-11-19" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Data::Dmp \- Dump Perl data structures as Perl code .SH "VERSION" .IX Header "VERSION" This document describes version 0.242 of Data::Dmp (from Perl distribution Data-Dmp), released on 2022\-08\-28. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Data::Dmp; # exports dd() and dmp() \& dd [1, 2, 3]; # prints "[1,2,3]" \& $var = dmp({a => 1}); # \-> "{a=>1}" .Ve .PP Print truncated dump (capped at \*(L"$Data::Dmp::OPT_MAX_DUMP_LEN_BEFORE_ELLIPSIS\*(R" characters): .PP .Vb 2 \& use Data::Dmp qw(dd_ellipsis dmp_ellipsis); \& dd_ellipsis [1..100]; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Data::Dmp is a Perl dumper like Data::Dumper. It's compact (only about 200 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. .SH "VARIABLES" .IX Header "VARIABLES" .ie n .SS "$Data::Dmp::OPT_PERL_VERSION" .el .SS "\f(CW$Data::Dmp::OPT_PERL_VERSION\fP" .IX Subsection "$Data::Dmp::OPT_PERL_VERSION" String, default: 5.010. .PP Set target Perl version. If you set this to, say \f(CW5.010\fR, then the dumped code will keep compatibility with Perl 5.10.0. This is used in the following ways: .IP "\(bu" 4 passed to Regexp::Stringify .IP "\(bu" 4 when dumping code references .Sp For example, in perls earlier than 5.016, feature.pm does not understand: .Sp .Vb 1 \& no feature \*(Aq:all\*(Aq; .Ve .Sp so we replace it with: .Sp .Vb 1 \& no feature; .Ve .ie n .SS "$Data::Dmp::OPT_REMOVE_PRAGMAS" .el .SS "\f(CW$Data::Dmp::OPT_REMOVE_PRAGMAS\fP" .IX Subsection "$Data::Dmp::OPT_REMOVE_PRAGMAS" Bool, default: 0. .PP 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: .PP .Vb 1 \& sub { use feature \*(Aqcurrent_sub\*(Aq, \*(Aqevalbytes\*(Aq, \*(Aqfc\*(Aq, \*(Aqsay\*(Aq, \*(Aqstate\*(Aq, \*(Aqswitch\*(Aq, \*(Aqunicode_strings\*(Aq, \*(Aqunicode_eval\*(Aq; $a <=> $b } .Ve .PP 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: .PP .Vb 1 \& sub { $a <=> $b } .Ve .PP Note that without the pragmas, the dump might be incorrect. .ie n .SS "$Data::Dmp::OPT_DEPARSE" .el .SS "\f(CW$Data::Dmp::OPT_DEPARSE\fP" .IX Subsection "$Data::Dmp::OPT_DEPARSE" Bool, default: 1. .PP Can be set to 0 to skip deparsing code. Coderefs will be dumped as \&\f(CW\*(C`sub{"DUMMY"}\*(C'\fR instead, like in Data::Dump. .ie n .SS "$Data::Dmp::OPT_STRINGIFY_NUMBERS" .el .SS "\f(CW$Data::Dmp::OPT_STRINGIFY_NUMBERS\fP" .IX Subsection "$Data::Dmp::OPT_STRINGIFY_NUMBERS" Bool, default: 0. .PP If set to true, will dump numbers as quoted string, e.g. 123 as \*(L"123\*(R" instead of 123. This might be helpful if you want to compute the hash of or get a canonical representation of data structure. .ie n .SS "$Data::Dmp::OPT_MAX_DUMP_LEN_BEFORE_ELLIPSIS" .el .SS "\f(CW$Data::Dmp::OPT_MAX_DUMP_LEN_BEFORE_ELLIPSIS\fP" .IX Subsection "$Data::Dmp::OPT_MAX_DUMP_LEN_BEFORE_ELLIPSIS" Int, default: 70. .PP Used by \*(L"dd_ellipsis\*(R" and \*(L"dmp_ellipsis\*(R". .SH "BENCHMARKS" .IX Header "BENCHMARKS" .Vb 5 \& [1..10]: \& Rate/s Precision/s Data::Dump Data::Dumper Data::Dmp \& Data::Dump 24404 95 \-\- \-61.6% \-75.6% \& Data::Dumper 63580 210 160.5+\-1.3% \-\- \-36.4% \& Data::Dmp 99940 130 309.5+\-1.7% 57.18+\-0.55% \-\- \& \& [1..100]: \& Rate/s Precision/s Data::Dump Data::Dumper Data::Dmp \& Data::Dump 2934.3 7.8 \-\- \-75.3% \-76.2% \& Data::Dumper 11873 32 304.6+\-1.5% \-\- \-3.7% \& Data::Dmp 12323.4 4 320+\-1.1% 3.8+\-0.28% \-\- \& \& Some mixed structure: \& Rate/s Precision/s Data::Dump Data::Dmp Data::Dumper \& Data::Dump 7161 12 \-\- \-69.3% \-78.7% \& Data::Dmp 23303 29 225.43+\-0.7% \-\- \-30.6% \& Data::Dumper 33573 56 368.8+\-1.1% 44.07+\-0.3% \-\- .Ve .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "dd" .IX Subsection "dd" Usage: .PP .Vb 1 \& dd($data, ...); # returns $data .Ve .PP Exported by default. Like \f(CW\*(C`Data::Dump\*(C'\fR's \f(CW\*(C`dd\*(C'\fR (a.k.a. \f(CW\*(C`dump\*(C'\fR), print one or more data to \s-1STDOUT.\s0 Unlike \f(CW\*(C`Data::Dump\*(C'\fR's \f(CW\*(C`dd\*(C'\fR, it \fIalways\fR prints and return \fIthe original data\fR (like \s-1XXX\s0), making it convenient to insert into expressions. This also removes ambiguity and saves one \f(CW\*(C`wantarray()\*(C'\fR call. .SS "dmp" .IX Subsection "dmp" Usage: .PP .Vb 1 \& my $dump = dmp($data, ...); .Ve .PP Exported by default. Return dump result as string. Unlike \f(CW\*(C`Data::Dump\*(C'\fR's \f(CW\*(C`dd\*(C'\fR (a.k.a. \f(CW\*(C`dump\*(C'\fR), it \fInever\fR prints and only return the dump result. .SS "dd_ellipsis" .IX Subsection "dd_ellipsis" Usage: .PP .Vb 1 \& dd_ellipsis($data, ...); # returns data .Ve .PP Just like \*(L"dd\*(R", except will truncate its output to \&\*(L"$Data::Dmp::OPT_MAX_DUMP_LEN_BEFORE_ELLIPSIS\*(R" characters if dump is too long. Note that truncated dump will probably not be valid Perl code. .SS "dmp_ellipsis" .IX Subsection "dmp_ellipsis" Usage: .PP .Vb 1 \& my $dump = dd_ellipsis($data, ...); # returns data .Ve .PP Just like \*(L"dmp\*(R", except will truncate dump result to \&\*(L"$Data::Dmp::OPT_MAX_DUMP_LEN_BEFORE_ELLIPSIS\*(R" characters if dump is too long. Note that truncated dump will probably not be valid Perl code. .SH "FAQ" .IX Header "FAQ" .SS "When to use Data::Dmp? How does it compare to other dumper modules?" .IX Subsection "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 \*(L"more eval-able\*(R", e.g. it can recreate circular structure. .PP 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. .PP 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 \s-1CPAN\s0 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. .PP 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 \&\s-1JSON, YAML,\s0 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 \s-1JSON::XS\s0). .SS "Is the output guaranteed to be single line dump?" .IX Subsection "Is the output guaranteed to be single line dump?" No. Some things can still produce multiline dump, e.g. newline in regular expression. .SH "HOMEPAGE" .IX Header "HOMEPAGE" Please visit the project's homepage at . .SH "SOURCE" .IX Header "SOURCE" Source repository is at . .SH "SEE ALSO" .IX Header "SEE ALSO" Data::Dump and other variations/derivate works in Data::Dump::*. .PP Data::Dumper and its variants. .PP Data::Printer. .PP \&\s-1YAML\s0, \s-1JSON\s0, Storable, Sereal, and other serialization formats. .SH "AUTHOR" .IX Header "AUTHOR" perlancar .SH "CONTRIBUTING" .IX Header "CONTRIBUTING" To contribute, you can send patches by email/via \s-1RT,\s0 or send pull requests on GitHub. .PP Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via: .PP .Vb 1 \& % prove \-l .Ve .PP If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla\- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2022, 2021, 2020, 2017, 2016, 2015, 2014 by perlancar . .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests on the bugtracker website .PP 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.