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: 68573
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.19



Subject: More customization for class output
I propose 2 new configuration parameters for more concise class output: 'methods' and 'parents', that allow to leave off at least 4 rows of output (when you're debugging your own structures, they're often unnecessary). Proposed patch (with tests) is attached. By default, their values are to retain current output.
Subject: data-printer.class.diff
diff --git a/lib/Data/Printer.pm b/lib/Data/Printer.pm index 1ca8784..35c8233 100644 --- a/lib/Data/Printer.pm +++ b/lib/Data/Printer.pm @@ -55,6 +55,8 @@ my $properties = { internals => 1, export => 1, sort_methods => 1, + parents => 1, + methods => 1, }, 'filters' => {}, }; @@ -489,7 +491,9 @@ sub _class { my $meta = Class::MOP::Class->initialize($ref); - if ( my @superclasses = $meta->superclasses ) { + if ( $p->{class}{parents} && + (my @superclasses = $meta->superclasses ) + ) { $string .= (' ' x $p->{_current_indent}) . 'Parents ' . join(', ', map { colored($_, $p->{color}->{'class'}) } @@ -503,7 +507,9 @@ sub _class { ) . $BREAK; } - $string .= _show_methods($ref, $meta, $p); + if ( $p->{class}{methods} ) { + $string .= _show_methods($ref, $meta, $p); + } if ( $p->{'class'}->{'internals'} ) { my $realtype = Scalar::Util::reftype $item; @@ -745,10 +751,15 @@ customization options available, as shown below (with default values): # and able to dump themselves. class => { + parents => 1, # show information about base class(es) + internals => 1, # show internal data structures of classes + methods => 1, # show class methods + inherited => 'none', # show inherited methods, # can also be 'all', 'private', or 'public'. + # not applicable, if 'methods' is set to 0 expand => 1, # how deep to traverse the object (in case # it contains other objects). Defaults to diff --git a/t/05-obj.t b/t/05-obj.t index 5db4aea..a2851c1 100644 --- a/t/05-obj.t +++ b/t/05-obj.t @@ -59,6 +59,24 @@ is( p($obj, class => { inherited => 0 }), 'Foo { }', 'testing objects (inherited => 0)' ); +is( p($obj, class => { parents => 0 }), 'Foo { + public methods (4) : baz, borg, foo, new + private methods (1) : _other + internals: { + test 42 + } +}', 'testing objects (parents => 0)' ); + + +is( p($obj, class => { methods => 0 }), 'Foo { + Parents Bar + Linear @ISA Foo, Bar + internals: { + test 42 + } +}', 'testing objects (methods => 0)' ); + + is( p($obj, class => { inherited => 'all' }), 'Foo { Parents Bar Linear @ISA Foo, Bar
On Tue May 31 12:51:19 2011, RANDIR wrote: Show quoted text
> I propose 2 new configuration parameters for more concise class output: > 'methods' and 'parents', that allow to leave off at least 4 rows of > output (when you're debugging your own structures, they're often > unnecessary). Proposed patch (with tests) is attached. By default, their > values are to retain current output.
Perfect. Again, thanks a lot for the patches. Keep 'em coming! :) 0.19 should have your changes. A couple of remarks, though: 1) I split the 'parents' option in 'parents' and 'linear_isa', to give even more granularity. 2) 'methods' became 'show_methods' since I already have 'sort_methods', to make things a bit consistent. Also, instead of 0 and 1, you can set it to 'all', 'none', 'public' or 'private'. Default is 'all', of course :) Hope you like it! Again, please let me know if you think the issue is resolved so we can close the ticket. Thanks again!
It seems OK now, thanks