X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FObject.pm;h=6426dd644f777bf35484d5a2ee7811aac9ca1361;hb=4cf89c74c7bfc634dd2b3f884eb062ea7691e121;hp=d018d27be36a3fecf535d8d2b29337689154c86c;hpb=ac0824eea01ff70157850ce849303cd3c53054f4;p=gitmo%2FMoose.git diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index d018d27..6426dd6 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -9,7 +9,7 @@ use if ( not our $__mx_is_compiled ), metaclass => 'Moose::Meta::Class'; use Carp 'confess'; -our $VERSION = '0.12'; +our $VERSION = '0.14'; our $AUTHORITY = 'cpan:STEVAN'; sub new { @@ -42,21 +42,30 @@ sub BUILDALL { } sub DEMOLISHALL { + my $self = shift; + foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) { + $method->{code}->body->($self); + } +} + +sub DESTROY { # NOTE: we ask Perl if we even # need to do this first, to avoid # extra meta level calls - return unless $_[0]->can('DEMOLISH'); - my $self = shift; - { + return unless $_[0]->can('DEMOLISH'); + # if we have an exception here ... + if ($@) { + # localize the $@ ... local $@; - foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) { - $method->{code}->body->($self); - } - } + # run DEMOLISHALL ourselves, ... + $_[0]->DEMOLISHALL; + # and return ... + return; + } + # otherwise it is normal destruction + $_[0]->DEMOLISHALL; } -sub DESTROY { goto &DEMOLISHALL } - # new does() methods will be created # as approiate see Moose::Meta::Role sub does {