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