UPDATE: I FOUND THE BUG!

I should not have called $class->SUPER::Dumper(@args);, but $class->SUPER::Dump(@args);, because Dumper() always blesses into a Data::Dumper object.

To my surprise, I found it more difficult to override _dump then expected. Maybe you can spot the error? I started like this:

package PpDumper; # PpDumper is a subclass of Data::Dumper, which provides # a custom _dump() method use Data::Dumper; our @ISA='Data::Dumper'; sub _dump { my ($self, $val, $name) = @_; print "my _dump called\n"; (ref($val) && $val->can('pp')) ? $val->pp($name) : $self->SUPER::_dump($val,$name); } sub PpDumper::Dumper { my ($class,@args) = @_; print "my own Dumper called\n"; $class->SUPER::Dumper(@args); } package main; .... my $h = { ... } { local $Data::Dumper::Useperl=1; print("3:\n",PpDumper->Dumper($h),"\n"); }
When I run this, I see in the output of course my own Dumper called, but I don't see my _dump called being printed. This means that my custom _dump routine has not been called. This is strange: I verified that Data::Dumper::new (which is eventually called by Data::Dumper::Dumper) uses the two-argument form of bless, so my object should be of type PpDumper. Also, setting Useperl to 1 should ensure that no compiled components get in my way (I don't know whether this is necessary for overriding methods, so I put it there for the safe side).

Where is the bug?

-- 
Ronald Fischer <ynnor@mm.st>

In reply to Re^2: Fine grain control over Data::Dumper by rovf
in thread Fine grain control over Data::Dumper by rovf

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.