Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Data-Printer CPAN distribution.

Report information
The Basics
Id: 68595
Status: resolved
Priority: 0/
Queue: Data-Printer

People
Owner: Nobody in particular
Requestors: RANDIR [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 0.18



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: {
On Wed Jun 01 09:43:49 2011, RANDIR wrote: Show quoted text
> Attached patch makes empty array and hashes to occupy only a single > string in output. Affected tests are corrected.
Perfect. Applied and tested. I had to change the implementation a bit for hashes since %$hash doesn't always work (tied hashes can return false and still have keys). Version 0.18 should contain those changes. As soon as you confirm it, we can close this ticket. Thanks again for the patch!
Thanks, it looks good.