On Thu Dec 07 23:36:20 2006, COLLIN wrote:
Show quoted text> The cleanup machinery in Class::BuildMethods does not deal with classes
> that inherit Class::BuildMethods-based accessors from their parents.
> This results in situations like this:
>
> # A inherits the b() accessor from a parent class
> {
> my $a = A->new();
> $a->b(5);
> }
> # $a has gone away
>
> {
> my $a = A->new();
> print $a->b; # prints 5
> }
>
> Because the new $a received the same address as the old $a and because
> A's DESTROY machinery does not wipe the value store for A's parent
> classes, $a->b appears to stick around.
Collin,
I'm trying to replicate this and the problem I've found is that I can
only replicate this with class data. However, DESTROY only works with
an instance, not classes and I can't remove that class data when an
instance of a class goes out of scope because that would break all other
instances.
For example:
{
package Universe;
use Class::BuildMethods pi => { class_data => 1 };
sub new { bless {}, shift }
package Other::Universe;
use base 'Universe';
}
package main;
my $u1 = Other::Universe->new;
my $u2 = Other::Universe->new;
$u1->pi(3.1415);
undef $u1; # DESTROY should be triggered
my $u3 = Other::Universe->new;
print $u2->pi; # should print 3.1415
print $u3->pi; # should print 3.1415
That's an example of how wiping out class data on DESTROY would be bad.
If this happens on instance data or if I have misunderstood the problem,
please send me a complete code sample and I can look into this.
Cheers,
Ovid