Subject: | More concise output for empty data structures |
Attached patch makes empty array and hashes to occupy only a single
string in output. Affected tests are corrected.
Subject: | data-printer.empty.diff |
--- lib/Data/Printer.pm
+++ lib/Data/Printer.pm
@@ -351,6 +351,9 @@
if ( $p->{max_depth} and $p->{_depth} > $p->{max_depth} ) {
$string .= '[ ... ]';
}
+ elsif ( !@$item ) {
+ $string .= "[]";
+ }
else {
$string .= "[$BREAK";
$p->{_current_indent} += $p->{indent};
@@ -396,6 +399,9 @@
if ( $p->{max_depth} and $p->{_depth} > $p->{max_depth} ) {
$string .= '{ ... }';
}
+ elsif ( !keys %$item ) {
+ $string .= "{}";
+ }
else {
$string .= "{$BREAK";
$p->{_current_indent} += $p->{indent};
--- t/01-p.t
+++ t/01-p.t
@@ -32,13 +32,11 @@
my @array = ();
is( p(@array),
-'[
-]', 'empty array' );
+'[]', 'empty array' );
undef @array;
is( p(@array),
-'[
-]', 'undefined array' );
+'[]', 'undefined array' );
@array = (1 .. 3);
is( p(@array),
@@ -101,13 +99,11 @@
my %hash = ();
is( p(%hash),
-'{
-}', 'empty hash');
+'{}', 'empty hash');
undef %hash;
is( p(%hash),
-'{
-}', 'undefined hash');
+'{}', 'undefined hash');
# the "%hash = 1" code below is wrong and issues
# an "odd number of elements in hash assignment"
--- t/06-obj2.t
+++ t/06-obj2.t
@@ -35,8 +35,7 @@
'FooArray {
public methods (2) : foo, new
private methods (0)
- internals: [
- ]
+ internals: []
}', 'testing blessed array' );
SKIP: {