summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/Data/Dumper.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Master/tlpkg/tlperl/lib/Data/Dumper.pm')
-rw-r--r--Master/tlpkg/tlperl/lib/Data/Dumper.pm26
1 files changed, 22 insertions, 4 deletions
diff --git a/Master/tlpkg/tlperl/lib/Data/Dumper.pm b/Master/tlpkg/tlperl/lib/Data/Dumper.pm
index e884298d746..13be89d8fbd 100644
--- a/Master/tlpkg/tlperl/lib/Data/Dumper.pm
+++ b/Master/tlpkg/tlperl/lib/Data/Dumper.pm
@@ -10,7 +10,7 @@
package Data::Dumper;
BEGIN {
- $VERSION = '2.158'; # Don't forget to set version and release
+ $VERSION = '2.160'; # Don't forget to set version and release
} # date in POD below!
#$| = 1;
@@ -41,6 +41,7 @@ my $IS_ASCII = ord 'A' == 65;
# module vars and their defaults
$Indent = 2 unless defined $Indent;
+$Trailingcomma = 0 unless defined $Trailingcomma;
$Purity = 0 unless defined $Purity;
$Pad = "" unless defined $Pad;
$Varname = "VAR" unless defined $Varname;
@@ -76,6 +77,7 @@ sub new {
my($s) = {
level => 0, # current recursive depth
indent => $Indent, # various styles of indenting
+ trailingcomma => $Trailingcomma, # whether to add comma after last elem
pad => $Pad, # all lines prefixed by this string
xpad => "", # padding-per-level
apad => "", # added padding for hash keys n such
@@ -413,7 +415,9 @@ sub _dump {
$out .= $pad . $ipad . '#' . $i
if $s->{indent} >= 3;
$out .= $pad . $ipad . $s->_dump($v, $sname);
- $out .= "," if $i++ < $#$val;
+ $out .= ","
+ if $i++ < $#$val
+ || ($s->{trailingcomma} && $s->{indent} >= 1);
}
$out .= $pad . ($s->{xpad} x ($s->{level} - 1)) if $i;
$out .= ($name =~ /^\@/) ? ')' : ']';
@@ -473,7 +477,7 @@ sub _dump {
if $s->{indent} >= 2;
}
if (substr($out, -1) eq ',') {
- chop $out;
+ chop $out if !$s->{trailingcomma} || !$s->{indent};
$out .= $pad . ($s->{xpad} x ($s->{level} - 1));
}
$out .= ($name =~ /^\%/) ? ')' : '}';
@@ -633,6 +637,11 @@ sub Indent {
}
}
+sub Trailingcomma {
+ my($s, $v) = @_;
+ defined($v) ? (($s->{trailingcomma} = $v), return $s) : $s->{trailingcomma};
+}
+
sub Pair {
my($s, $v) = @_;
defined($v) ? (($s->{pair} = $v), return $s) : $s->{pair};
@@ -1032,6 +1041,15 @@ consumes twice the number of lines). Style 2 is the default.
=item *
+$Data::Dumper::Trailingcomma I<or> I<$OBJ>->Trailingcomma(I<[NEWVAL]>)
+
+Controls whether a comma is added after the last element of an array or
+hash. Even when true, no comma is added between the last element of an array
+or hash and a closing bracket when they appear on the same line. The default
+is false.
+
+=item *
+
$Data::Dumper::Purity I<or> I<$OBJ>->Purity(I<[NEWVAL]>)
Controls the degree to which the output can be C<eval>ed to recreate the
@@ -1454,7 +1472,7 @@ modify it under the same terms as Perl itself.
=head1 VERSION
-Version 2.158 (March 13 2015)
+Version 2.160 (January 12 2016)
=head1 SEE ALSO