Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
good chemistry is complicated,
and a little bit messy -LW

Re: Object Browser for Perl?

by rjt (Chaplain)
on Jul 08, 2013 at 10:32 UTC ( #1043065=note: print w/ replies, xml ) Need Help??

in reply to Object Browser for Perl?

I'm afraid I'm not really sure what it is you're after. You say you want to look at changes in an object, perhaps in a debugger session, but then you say "a debugger is problematic". What am I missing?

At the risk of offering advice that's too general for your query, I have found the likes of Data::Dumper (or more recently Data::Dump) to be more than sufficient for my data inspection needs, from the simple to the arcane. Both are extensible enough to flex to almost any whim. Depending on the type of application or module, and its stage of development, where I actually send those dumps changes. Usually (and this includes headless serial terminals), I can find a way to snag Perl's output in a shell, log, or web output, which is good enough for me.

And usually, my tests hit the mark reasonably well, so typically my "live" debugging is rather minimal.

What is it in particular about your current project that renders all of this impossible or prohibitively inconvenient? Perhaps I can offer more specific advice with a better description.

Comment on Re: Object Browser for Perl?
Re^2: Object Browser for Perl?
by QM (Vicar) on Jul 08, 2013 at 13:54 UTC
    Examining objects, especially changes to objects between runs, is problematic because:

    (1) There is a lot of data in an object, so complete Data::Dumper output runs hundreds or thousands of lines. I can reduce this with 'depth', but then runs may not be so easily compared, as truncated object trees end with 'key' => 'Blah::Foo::Bar=HASH(0xdeadbeef)'. (Not such a big win anyway, since internal pointers dump as $VAR1->{blah}.) I could also give a list of interesting keys to dump, which requires another iteration.

    (2) I'm using a large library, that I'm only superficially acquainted with, that adds lots of uninteresting data to the objects in many places. It would probably be easier if the library added stuff under a top-level key like 'internal_machinations', where I seldom need to access anything from my code.

    (3) There's a shared resource key at many levels, pre-arranged so that $self->{'resource'} points to the same instance, regardless of $self. So in some cases I have to worry about clobbering existing data there, etc.

    (4) There are very few accessors in the large library, and only for specific, often-used attributes.

    Quantum Mechanics: The dreams stuff is made of

      ++ 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


      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};
        ++ 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.

        Quantum Mechanics: The dreams stuff is made of

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043065]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-03-15 19:00 GMT
Find Nodes?
    Voting Booth?

    Have you used a cryptocurrency?

    Results (321 votes), past polls