- convert distribution from Module::Install to Distar; fixes RT#120856
- every module has a $VERSION now (RT#116427)
+ - add support for Trailingcomma option (RT#114609, Aaron Crane)
2.022 Mar 21 2014
- Fix repo metadata
sub DumperObject {
my $dd = Data::Dumper->new([]);
+ $dd->Trailingcomma(1) if $dd->can('Trailingcomma');
$dd->Terse(1)->Indent(1)->Useqq(1)->Deparse(1)->Quotekeys(0)->Sortkeys(1);
}
local $Data::Dumper::Deparse = 1;
local $Data::Dumper::Quotekeys = 0;
local $Data::Dumper::Sortkeys = 1;
+ local $Data::Dumper::Trailingcomma = 1;
warn Dumper($var);
}
use warnings;
use strict 'refs';
'fleem';
- }
+ },
}
instead of the default Data::Dumper output:
(note the tab indentation, oh joy ...)
+(The trailing comma on the last element of an array or hash is enabled by a new
+feature in Data::Dumper version 2.159, which was first released in Perl 5.24.
+Using Data::Dumper::Concise with an older version of Data::Dumper will still
+work, but you won't get those commas.)
+
If you need to get the underlying L<Dumper> object just call C<DumperObject>.
Also try out C<DumperF> which takes a C<CodeRef> as the first argument to
->Deparse(1)
->Quotekeys(0)
->Sortkeys(1);
+$dd->Trailingcomma(1) if $dd->can('Trailingcomma');
foreach my $to_dump (
[ { foo => "bar\nbaz", quux => sub { "fleem" } } ],
local $Data::Dumper::Deparse = 1;
local $Data::Dumper::Quotekeys = 0;
local $Data::Dumper::Sortkeys = 1;
+ no warnings 'once'; # in case Trailingcomma option is unknown in this DD
+ local $Data::Dumper::Trailingcomma = 1;
Data::Dumper::Dumper(@$to_dump);
};
my $out = DumperF { "arr: $_[0] str: $_[1]" } [qw(wut HALP)], "gnarl";
-is($out, qq{arr: [\n "wut",\n "HALP"\n]\n str: "gnarl"\n}, 'DumperF works!');
+like($out, qr{^arr: \[\n "wut",\n "HALP",?\n\]\n str: "gnarl"\n\z}, 'DumperF works!');
+
+like(Dumper([1..3]), qr/,\s*]\s*$/, 'trailing comma enabled')
+ if $dd->can('Trailingcomma');
DWARN_CODEREF: {
my $foo = ['warn', 'friend']->$Dwarn;
- is $warned_string,qq{[\n "warn",\n "friend"\n]\n}, 'Dwarn warns lists';
+ like $warned_string,qr{^\[\n "warn",\n "friend",?\n\]\n\z}, 'Dwarn warns lists';
ok eq_array($foo, ['warn','friend']), 'Dwarn passes lists through correctly';
}
DWARNF: {
my @foo = DwarnF { "arr: $_[0] str: $_[1]" } [qw(wut HALP)], "gnarl";
- is($warned_string, qq{arr: [\n "wut",\n "HALP"\n]\n str: "gnarl"\n}, 'DumperF works!');
+ like($warned_string, qr{^arr: \[\n "wut",\n "HALP",?\n\]\n str: "gnarl"\n\z}, 'DumperF works!');
ok eq_array($foo[0], ['wut','HALP']) && $foo[1] eq 'gnarl', 'DwarnF passes lists through correctly';
}
if ($loaded) {
my $x = [1];
my $foo = DwarnN $x;
- is $warned_string, qq{\$x => [\n 1\n]\n}, 'DwarnN warns';
+ like $warned_string, qr{^\$x => \[\n 1,?\n\]\n\z}, 'DwarnN warns';
ok eq_array($foo, [1]), 'DwarnN passes through correctly';
DwarnN [1];
- is $warned_string, qq{(anon) => [\n 1\n]\n}, 'DwarnN warns';
+ like $warned_string, qr{^\(anon\) => \[\n 1,?\n\]\n\z}, 'DwarnN warns';
}
}
eval {
DdieS [ 'k', 'bar' ];
};
- is $@, qq{[\n "k",\n "bar"\n]\n}, 'DwarnD dies output correctly';
+ like $@, qr{^\[\n "k",\n "bar",?\n\]\n\z}, 'DwarnD dies output correctly';
}