From: Dave Rolsky Date: Mon, 6 Apr 2009 17:43:19 +0000 (-0500) Subject: Fix DEMOLISHALL to work even with the metaclass object is missing X-Git-Tag: 0.73_02~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8955a780f5f3052194ee84d60aa5558f93556136;p=gitmo%2FMoose.git Fix DEMOLISHALL to work even with the metaclass object is missing --- diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index 59d151a..658ab85 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -55,12 +55,21 @@ sub BUILDALL { } sub DEMOLISHALL { - my $self = shift; - # NOTE: we ask Perl if we even + my $self = shift; + + # NOTE: we ask Perl if we even # need to do this first, to avoid - # extra meta level calls + # extra meta level calls return unless $self->can('DEMOLISH'); - foreach my $method (Class::MOP::class_of($self)->find_all_methods_by_name('DEMOLISH')) { + + # This is a hack, because Moose::Meta::Class may not be the right + # metaclass, but class_of may return undef during global + # destruction, if the metaclass object has already been cleaned + # up. + my $meta = Class::MOP::class_of($self) + || Moose::Meta::Class->initialize( ref $self ); + + foreach my $method ( $meta->find_all_methods_by_name('DEMOLISH') ) { $method->{code}->execute($self); } }