0.49
[gitmo/Moose.git] / lib / Moose / Object.pm
index 409db5d..6426dd6 100644 (file)
@@ -9,7 +9,7 @@ use if ( not our $__mx_is_compiled ), metaclass => 'Moose::Meta::Class';
 
 use Carp 'confess';
 
-our $VERSION   = '0.09';
+our $VERSION   = '0.14';
 our $AUTHORITY = 'cpan:STEVAN';
 
 sub new {
@@ -37,22 +37,34 @@ sub BUILDALL {
     return unless $_[0]->can('BUILD');    
     my ($self, $params) = @_;
     foreach my $method (reverse $self->meta->find_all_methods_by_name('BUILD')) {
-        $method->{code}->($self, $params);
+        $method->{code}->body->($self, $params);
     }
 }
 
 sub DEMOLISHALL {
-    # 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;    
     foreach my $method ($self->meta->find_all_methods_by_name('DEMOLISH')) {
-        $method->{code}->($self);
-    }    
+        $method->{code}->body->($self);
+    }
 }
 
-sub DESTROY { goto &DEMOLISHALL }
+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');
+    # if we have an exception here ...
+    if ($@) {
+        # localize the $@ ...
+        local $@;
+        # run DEMOLISHALL ourselves, ...
+        $_[0]->DEMOLISHALL;
+        # and return ...
+        return;
+    }
+    # otherwise it is normal destruction
+    $_[0]->DEMOLISHALL;
+}
 
 # new does() methods will be created 
 # as approiate see Moose::Meta::Role
@@ -62,8 +74,9 @@ sub does {
         || confess "You much supply a role name to does()";
     my $meta = $self->meta;
     foreach my $class ($meta->class_precedence_list) {
+        my $m = $meta->initialize($class);
         return 1 
-            if $meta->initialize($class)->does_role($role_name);            
+            if $m->can('does_role') && $m->does_role($role_name);            
     }
     return 0;   
 }
@@ -80,7 +93,7 @@ sub does {
 sub dump { 
     my $self = shift;
     require Data::Dumper;
-    $Data::Dumper::Maxdepth = shift if @_;
+    local $Data::Dumper::Maxdepth = shift if @_;
     Data::Dumper::Dumper $self;
 }