App-SimpleBackuper
view release on metacpan or search on metacpan
local/lib/perl5/Data/Dump.pm view on Meta::CPAN
if (/^(.)\1\1\1/s) {
# seems to be a repeating sequence, let's check if it really is
# without backtracking
unless (/[^\Q$1\E]/) {
my $base = quote($1);
my $repeat = length;
return "($base x $repeat)"
}
}
# Length protection because the RE engine will blow the stack [RT#33520]
if (length($_) < 16 * 1024 && /^(.{2,5}?)\1*\z/s) {
my $base = quote($1);
my $repeat = length($_)/length($1);
return "($base x $repeat)";
}
}
}
local $_ = "e;
if (length($_) > 40 && !/\\x\{/ && length($_) > (length($_[0]) * 2)) {
# too much binary data, better to represent as a hex/base64 string
# Base64 is more compact than hex when string is longer than
# 17 bytes (not counting any require statement needed).
# But on the other hand, hex is much more readable.
if ($TRY_BASE64 && length($_[0]) > $TRY_BASE64 &&
(defined &utf8::is_utf8 && !utf8::is_utf8($_[0])) &&
eval { require MIME::Base64 })
{
$require{"MIME::Base64"}++;
return "MIME::Base64::decode(\"" .
MIME::Base64::encode($_[0],"") .
"\")";
}
return "pack(\"H*\",\"" . unpack("H*", $_[0]) . "\")";
}
return $_;
}
my %esc = (
"\a" => "\\a",
"\b" => "\\b",
"\t" => "\\t",
"\n" => "\\n",
"\f" => "\\f",
"\r" => "\\r",
"\e" => "\\e",
);
# put a string value in double quotes
sub quote {
local($_) = $_[0];
# If there are many '"' we might want to use qq() instead
s/([\\\"\@\$])/\\$1/g;
return qq("$_") unless /[^\040-\176]/; # fast exit
s/([\a\b\t\n\f\r\e])/$esc{$1}/g;
# no need for 3 digits in escape for these
s/([\0-\037])(?!\d)/sprintf('\\%o',ord($1))/eg;
s/([\0-\037\177-\377])/sprintf('\\x%02X',ord($1))/eg;
s/([^\040-\176])/sprintf('\\x{%X}',ord($1))/eg;
return qq("$_");
}
1;
__END__
=head1 NAME
Data::Dump - Pretty printing of data structures
=head1 SYNOPSIS
use Data::Dump qw(dump);
$str = dump(@list);
@copy_of_list = eval $str;
# or use it for easy debug printout
use Data::Dump; dd localtime;
=head1 DESCRIPTION
This module provides a few functions that traverse their
argument list and return a string containing Perl code that,
when C<eval>ed, produces a deep copy of the original arguments.
The main feature of the module is that it strives to produce output
that is easy to read. Example:
@a = (1, [2, 3], {4 => 5});
dump(@a);
Produces:
"(1, [2, 3], { 4 => 5 })"
If you dump just a little data, it is output on a single line. If
you dump data that is more complex or there is a lot of it, line breaks
are automatically added to keep it easy to read.
The following functions are provided (only the dd* functions are exported by default):
=over
=item dump( ... )
=item pp( ... )
Returns a string containing a Perl expression. If you pass this
string to Perl's built-in eval() function it should return a copy of
the arguments you passed to dump().
If you call the function with multiple arguments then the output will
be wrapped in parenthesis "( ..., ... )". If you call the function with a
( run in 1.418 second using v1.01-cache-2.11-cpan-39bf76dae61 )