0.49
[gitmo/Moose.git] / lib / Moose / Object.pm
index d018d27..6426dd6 100644 (file)
@@ -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 {