in reply to Re^2: Object Browser for Perl?
in thread Object Browser for Perl?

++ and thanks for the additional details, QM. It sounds like Data::Dump (and Data::Dump::Filtered) will do what you want, if you give it a bit of help. Here's a documented example that should get you going:

Full example source

#!/usr/bin/env perl use 5.012; use warnings; use Data::Dump qw/dump dumpf/; # This simulates the "resource" key you mentioned in (3) my $singleton = bless({ note => 'Defined outside $hairy_object', 1..20 # To really drive the point home :-) }, 'Singleton::Resource'); # A reasonably complex object, just enough to illustrate. my $hairy_object = bless { attr1 => 'val1', resource => $singleton, unwanted => bless({ thing => 'We want to ignore' }, 'Unwanted'), however => { this => { unwanted => bless({ is => 'actually wanted' }, 'Unwanted'), }}, Silly => { complex => { references => 'can be mangled', so => "they make more sense.", } } }, 'Hairy::Object'; # Throw in a couple of circular references $hairy_object->{circular_ref} = $hairy_object; $hairy_object->{internal_ref} = $hairy_object->{however}{this}; say "Before:"; say '-' x 76; say dump($hairy_object); say "\nAfter:"; say '-' x 76; $Data::Dump::INDENT = ' '; # Edit to taste. '| ' is nice, too. # Set up callback; called for every node in the $hairy_object tree # This is the heart of the logic that controls the dumpf() output my $dump = dumpf($hairy_object, sub { no warnings 'uninitialized'; my ($ctx, $obj) = @_; my %r; if ($ctx->depth == 0) { $r{hide_keys} = [ grep { ref($obj->{$_}) =~ /^(Unwanted|Something::Else)$/; } keys %$obj ]; }); # Munge the resulting dump a bit to remove extraneous bits $dump =~ s/^\Q$Data::Dump::INDENT\E//mg; # Remove one indent $dump =~ s/\Ado \{.+?my \$a = bless\(\{\n//s; $dump =~ s/\$a;\n\}//ms; say "\$a = bless( {\n$dump";

Output:

Before: ---------------------------------------------------------------------- +------ do { my $a = bless({ attr1 => "val1", circular_ref => 'fix', however => { this => { unwanted => bless({ is => "actually wa +nted" }, "Unwanted") }, }, internal_ref => 'fix', resource => bless({ 1 => 2, 11 => 12, 13 => 14, 15 => 16, 17 => 18, 19 => 20, 3 => 4, 5 => 6, 7 => 8, 9 => 10, note => "Defined outside \$hairy_object", }, "Singleton::Resource"), Silly => { complex => { references => "can be mangled", so +=> "they make more sense." }, }, unwanted => bless({ thing => "We want to ignore" }, "Unwanted" +), }, "Hairy::Object"); $a->{circular_ref} = $a; $a->{internal_ref} = $a->{however}{this}; $a; } After: ---------------------------------------------------------------------- +------ $a = bless( { attr1 => "val1", circular_ref => 'fix', however => # Here, there be dragons { this => { unwanted => bless({ is => "actually wanted" }, "Unwant +ed") }, }, internal_ref => 'fix', resource => $singleton, Silly => "references can be mangled so they make more sense.", }, "Hairy::Object"); $a->{circular_ref} = $a; $a->{internal_ref} = $a->{however}{this};

Replies are listed 'Best First'.
Re^4: Object Browser for Perl?
by QM (Parson) on Jul 09, 2013 at 08:48 UTC
    ++ Thank you for taking the time to write up a great example!

    Seriously, this is why I love Seekers of Perl Wisdom, for such timely, clear, and precise responses.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of