Support the global destruction flag in DEMOLISH()
[gitmo/Mouse.git] / lib / Mouse / Meta / Method / Destructor.pm
index 28e260f..d083a6b 100644 (file)
@@ -1,5 +1,5 @@
 package Mouse::Meta::Method::Destructor;
-use Mouse::Util; # enables strict and warnings
+use Mouse::Util qw(:meta); # enables strict and warnings
 
 sub _empty_DESTROY{ }
 
@@ -12,9 +12,9 @@ sub _generate_destructor{
 
     my $demolishall = '';
     for my $class ($metaclass->linearized_isa) {
-        no strict 'refs';
-        if (*{$class . '::DEMOLISH'}{CODE}) {
-            $demolishall .= "${class}::DEMOLISH(\$self);\n";
+        if (Mouse::Util::get_code_ref($class, 'DEMOLISH')) {
+            $demolishall .= sprintf "%s::DEMOLISH(\$self, \$Mouse::Util::in_global_destruction);\n",
+                $class,
         }
     }
 
@@ -47,3 +47,17 @@ sub _generate_destructor{
 
 1;
 __END__
+
+=head1 NAME
+
+Mouse::Meta::Method::Destructor - A Mouse method generator for destructors
+
+=head1 VERSION
+
+This document describes Mouse version 0.50
+
+=head1 SEE ALSO
+
+L<Moose::Meta::Method::Destructor>
+
+=cut