Data-Dump-SortKeys

 view release on metacpan or  search on metacpan

lib/Data/Dump/SortKeys.pm  view on Meta::CPAN


It differs from C<dump($string)> in that it will quote even numbers and
not try to come up with clever expressions that might shorten the
output.  If a non-scalar argument is provided then it's just stringified
instead of traversed.

=item dd( ... )

=item ddx( ... )

These functions will call dump() on their argument and print the
result to STDOUT (actually, it's the currently selected output handle, but
STDOUT is the default for that).

The difference between them is only that ddx() will prefix the lines
it prints with "# " and mark the first line with the file and line
number where it was called.  This is meant to be useful for debug
printouts of state within programs.

=item dumpf( ..., \&filter )

Short hand for calling the dump_filtered() function of L<Data::Dump::Filtered>.
This works like dump(), but the last argument should be a filter callback
function.  As objects are visited the filter callback is invoked and it
can modify how the objects are dumped.

=back

=for Pod::Coverage ^(.+)$

=head1 CONFIGURATION

There are a few global variables that can be set to modify the output
generated by the dump functions.  It's wise to localize the setting of
these.

=over

=item $Data::Dump::SortKeys::INDENT

This holds the string that's used for indenting multiline data structures.
It's default value is "  " (two spaces).  Set it to "" to suppress indentation.
Setting it to "| " makes for nice visuals even if the dump output then fails to
be valid Perl.

=item $Data::Dump::SortKeys::TRY_BASE64

How long must a binary string be before we try to use the base64 encoding
for the dump output.  The default is 50.  Set it to 0 to disable base64 dumps.

=item $Data::Dump::SortKeys::SORT_KEYS

A custom hook which is called with ($hashref) when dumping a hash, to get the
sorted hash keys. It should return a list containing the sorted keys.

=item $Data::Dump::SortKeys::REMOVE_PRAGMAS

If set to 1, then pragmas at the start of coderef dump will be removed. Coderef
dump is produced by L<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.

=back

=head1 LIMITATIONS

Code references will be dumped as C<< sub { ... } >>. Thus, C<eval>ing them will
not reproduce the original routine.  The C<...>-operator used will also require
perl-5.12 or better to be evaled.

If you forget to explicitly import the C<dump> function, your code will
core dump. That's because you just called the builtin C<dump> function
by accident, which intentionally dumps core.  Because of this you can
also import the same function as C<pp>, mnemonic for "pretty-print".

=head1 HISTORY

The C<Data::Dump> module grew out of frustration with Sarathy's
in-most-cases-excellent C<Data::Dumper>.  Basic ideas and some code
are shared with Sarathy's module.

The C<Data::Dump> module provides a much simpler interface than
C<Data::Dumper>.  No OO interface is available and there are fewer
configuration options to worry about.  The other benefit is
that the dump produced does not try to set any variables.  It only
returns what is needed to produce a copy of the arguments.  This means
that C<dump("foo")> simply returns C<'"foo"'>, and C<dump(1..3)> simply
returns C<'(1, 2, 3)'>.

=head1 SEE ALSO

L<Data::Dump::Filtered>, L<Data::Dump::Trace>, L<Data::Dumper>, L<JSON>,
L<Storable>

L<https://rt.cpan.org/Public/Bug/Display.html?id=110515>

=head1 Data::Dump AUTHORS

The C<Data::Dump> module is written by Gisle Aas <gisle@aas.no>, based
on C<Data::Dumper> by Gurusamy Sarathy <gsar@umich.edu>.

 Copyright 1998-2010 Gisle Aas.
 Copyright 1996-1998 Gurusamy Sarathy.

This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/Data-Dump-SortKeys>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-Data-Dump-SortKeys>.



( run in 0.548 second using v1.01-cache-2.11-cpan-df04353d9ac )