Hi Monks!

I'm developing a web app, using Data::Dumper to write a kind of crash dump into the error log file. Unfortunately, the output becomes quite large, as one of the dumped variables contains lots of other objects. The internals of several of those objects (mostly not my code) are not interesting for the crash dump. Instead, I would like to see those objects stringified, while the other object (my stuff) should be dumped normally.

Some of the classes are:

Math::BigInt
I want to see the stringified number ("27"), not the internals 'bless({ "sign" => "+", "value" => [ 27 ]},"Math::BigInt")'
DateTime
like above, I want to see some date (iso8601, the default stringification, is ok), not a 35 line dump of DateTime internals
DateTime::TimeZone
like above, I don't need a dump of the entire TZ DB.
Classes inheriting from Rose::DB::Object::Metadata
All I need to see here is something like "My::App::DB::Foo::Bar::MetaData=HASH(0x12345678)"

It seems I would need a hook into Data::Dumper that is called when Data::Dumper attempts to dump a blessed reference. It would decide if the reference is dumped as usual or if the reference is stringified.

Something like

print Data::Dumper->new([$mystuff],['mystuff'])->objectFilter(sub { my $obj=shift; return "$obj" if (ref($obj) eq 'Math::BigInt') or $obj->isa('Rose::D +B::Object::Metadata'); return $obj; })->Dump();

Any hints how to realize this?

Thanks,
Tux2000


In reply to Data::Dumper too noisy by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.