Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow BREAKWIDTH to be set #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/Data/Dump.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ $VERSION = "1.22";
$DEBUG = 0;

use overload ();
use vars qw(%seen %refcnt @dump @fixup %require $TRY_BASE64 @FILTERS $INDENT);
use vars qw(%seen %refcnt @dump @fixup %require $TRY_BASE64 @FILTERS $INDENT $BREAKWIDTH);

$TRY_BASE64 = 50 unless defined $TRY_BASE64;
$INDENT = " " unless defined $INDENT;
$BREAKWIDTH = 60 unless defined $BREAKWIDTH;

sub dump
{
Expand Down Expand Up @@ -326,7 +327,7 @@ sub _dump
my $nl = "";
my $klen_pad = 0;
my $tmp = "@keys @vals";
if (length($tmp) > 60 || $tmp =~ /\n/ || $tied) {
if (length($tmp) > $BREAKWIDTH || $tmp =~ /\n/ || $tied) {
$nl = "\n";

# Determine what padding to add
Expand Down Expand Up @@ -466,7 +467,7 @@ sub format_list
}
}
my $tmp = "@_";
if ($comment || (@_ > $indent_lim && (length($tmp) > 60 || $tmp =~ /\n/))) {
if ($comment || (@_ > $indent_lim && (length($tmp) > $BREAKWIDTH || $tmp =~ /\n/))) {
my @elem = @_;
for (@elem) { s/^/$INDENT/gm; }
return "\n" . ($comment ? "$INDENT# $comment\n" : "") .
Expand Down Expand Up @@ -668,6 +669,12 @@ 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::BREAKWIDTH

How long can a string get before we add a carriage return. The default is 60.

It can be useful to set this to 1 to force all pairs to be on their own lines.

=item $Data::Dump::TRY_BASE64

How long must a binary string be before we try to use the base64 encoding
Expand Down