Version 1.04
[gitmo/Moose.git] / lib / Moose / Meta / Method / Destructor.pm
index 008ac58..81b70fc 100644 (file)
@@ -8,7 +8,7 @@ use Devel::GlobalDestruction ();
 use Scalar::Util 'blessed', 'weaken';
 use Try::Tiny ();
 
-our $VERSION   = '0.93';
+our $VERSION   = '1.04';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -81,10 +81,14 @@ sub _initialize_body {
     my @DEMOLISH_methods = $self->associated_metaclass->find_all_methods_by_name('DEMOLISH');
 
     my $source;
-    if ( @DEMOLISH_methods ) {
-        $source = 'sub {';
-        $source .= 'my $self = shift;' . "\n";
+    $source  = 'sub {' . "\n";
+    $source .= 'my $self = shift;' . "\n";
+    $source .= 'return $self->Moose::Object::DESTROY(@_)' . "\n";
+    $source .= '    if Scalar::Util::blessed($self) ne ';
+    $source .= "'" . $self->associated_metaclass->name . "'";
+    $source .= ';' . "\n";
 
+    if ( @DEMOLISH_methods ) {
         $source .= 'local $?;' . "\n";
 
         $source .= 'my $in_global_destruction = Devel::GlobalDestruction::in_global_destruction;' . "\n";
@@ -98,11 +102,10 @@ sub _initialize_body {
         $source .= q[ Try::Tiny::catch { no warnings 'misc'; die $_ };] . "\n";
         $source .= 'return;' . "\n";
 
-        $source .= '}';
-    } else {
-        $source = 'sub { }';
     }
 
+    $source .= '}';
+
     warn $source if $self->options->{debug};
 
     my ( $code, $e ) = $self->_compile_code(