Subject: | Issue With DEMOLISH and lazy attributes |
I am running into issues where attributes are not defined during global object destruction:
(in cleanup) Can't call method "initialize" on an undefined value at
.../Class/MOP/Method/Meta.pm line 48 during global destruction.
This seems to only happen for objects with lazy attributes that are being accessed during the
DEMOLISH method. It does not happen in normal Moose objects. There are cases where no error
appears as well, but this may be non-determinism on the part of the GC when the DEMOLISH
method is running...
Perl: This is perl 5, version 12, subversion 3 (v5.12.3) built for darwin-thread-multi-2level
MooseX::Singleton: 0.29
Moose: 2.0602
OS: OS X Lion (10.7.3) (Darwin Kernel Version 11.3.0: Thu Jan 12 18:47:41 PST 2012)
Subject: | basic.pl |
#!/usr/bin/perl
use strict;
use warnings;
{
package SingleDefault;
use MooseX::Singleton;
has x => ( is => 'ro', isa => 'Str', default => 'Hello SingleDefault!' );
sub DEMOLISH {
my ($self) = @_;
warn $self->x;
}
1;
}
{
package SingleLazyBuilder;
use MooseX::Singleton;
has x => ( is => 'ro', isa => 'Str', builder => '_build2', lazy => 1 );
sub _build2 {
return 'Hello SingleLazyBuilder!';
}
sub DEMOLISH {
my ($self) = @_;
warn $self->x;
}
1;
}
{
my $t = SingleDefault->instance;
$t = undef;
}
{
my $t = SingleLazyBuilder->instance;
$t = undef;
}