dragonchild has asked for the wisdom of the Perl Monks concerning the following question:
I'm working on getting DBM::Deep to properly handle a edgecase and I ran into an edgecase with overload and re-blessing objects. The code below demonstrates the problem.
What I'm seeing:{ package Null; use overload bool => sub { undef }, '""' => sub { undef }, '0+' => sub { undef }, fallback => 1, nomethod => 'AUTOLOAD'; sub AUTOLOAD { return; } } { package Foo; sub new { return bless { a => 'b' }, shift; } sub apple { 'pear' } } my %x = ( foo => Foo->new, ); my $y = $x{foo}; print "Y1: $y\n"; bless $x{foo}, 'Null'; %{$x{foo}} = (); print "Y2: $y\n"; my $z = $x{foo}; print "Z: $z\n";
I would expect Y2 and Z to be the same. It's as if the overloading doesn't happen unless the SV is created after the blessing. Reblessing doesn't seem to trigger the overloading. Am I missing something?Y1: Foo=HASH(0x1801234) Y2: Null=HASH(0x1801234) Z:
For the record, what I'm trying to do is fix the following edgecase:
If someone has an idea of how to fix the underlying issue, I'm all ears.$db->{foo} = { a => 'b' }; my $x = $db->{foo}; my $y = $db->{foo}; ok( $x == $y ); # This is broken in 1.0004 and before, but fixed in SV +N. delete $db->{foo}; is( $x, undef ); # This works is( $x + 0, 0 ); # This does not
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Overload + reblessing oddity
by kyle (Abbot) on Sep 29, 2007 at 02:41 UTC |