From: Matt S Trout <mst@shadowcat.co.uk>
Date: Thu, 26 Apr 2012 18:44:40 +0000 (+0000)
Subject: Devel::GlobalDestruction
X-Git-Tag: v0.091000~7
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6b90ff030fd72db106f8f5e2151f49de310ab69d;p=gitmo%2FMoo.git

Devel::GlobalDestruction
---

diff --git a/Changes b/Changes
index d7c2242..d48047c 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,6 @@
+  - provide 'no Moo::sification' to forcibly disable metaclass inflation
+  - switch to Devel::GlobalDestruction to correctly disarm the
+    Moo::sification trigger under threads
   - make extends after has work
   - name subs if Sub::Name is available for better stracktraces
   - undefer all subs before creating a concrete Moose metaclass
diff --git a/Makefile.PL b/Makefile.PL
index 5a45ec3..09ca973 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -14,6 +14,7 @@ my %RUN_DEPS = (
   'strictures' => 1.001001,
   'Module::Runtime' => 0.013,
   'Role::Tiny' => 1.000900,
+  'Devel::GlobalDestruction' => '0.0401',
 );
 
 # have to do this since old EUMM dev releases miss the eval $VERSION line
diff --git a/lib/Method/Generate/DemolishAll.pm b/lib/Method/Generate/DemolishAll.pm
index 0ad1f58..3d499cc 100644
--- a/lib/Method/Generate/DemolishAll.pm
+++ b/lib/Method/Generate/DemolishAll.pm
@@ -2,6 +2,7 @@ package Method::Generate::DemolishAll;
 
 use strictures 1;
 use base qw(Moo::Object);
+use Devel::GlobalDestruction ();
 use Sub::Quote;
 use Moo::_Utils;
 use B qw(perlstring);
@@ -20,7 +21,7 @@ sub generate_method {
       local $@;
       require Moo::_Utils;
       eval {
-        $self->DEMOLISHALL($Moo::_Utils::_in_global_destruction);
+        $self->DEMOLISHALL(Devel::GlobalDestruction::in_global_destruction);
       };
       $@;
     };
diff --git a/lib/Moo/_Utils.pm b/lib/Moo/_Utils.pm
index 047f6ca..6db4dac 100644
--- a/lib/Moo/_Utils.pm
+++ b/lib/Moo/_Utils.pm
@@ -10,6 +10,7 @@ use constant can_haz_subname => eval { require Sub::Name };
 
 use strictures 1;
 use Module::Runtime qw(require_module);
+use Devel::GlobalDestruction;
 use base qw(Exporter);
 use Moo::_mro;
 
@@ -69,9 +70,6 @@ sub _name_coderef {
   can_haz_subname ? Sub::Name::subname(@_) : $_[1];
 }
 
-our $_in_global_destruction = 0;
-END { $_in_global_destruction = 1 }
-
 sub STANDARD_DESTROY {
   my $self = shift;
 
@@ -79,7 +77,7 @@ sub STANDARD_DESTROY {
     local $?;
     local $@;
     eval {
-      $self->DEMOLISHALL($_in_global_destruction);
+      $self->DEMOLISHALL(in_global_destruction);
     };
     $@;
   };
diff --git a/lib/Moo/sification.pm b/lib/Moo/sification.pm
index 6f42dfa..2f94663 100644
--- a/lib/Moo/sification.pm
+++ b/lib/Moo/sification.pm
@@ -1,11 +1,12 @@
 package Moo::sification;
 
 use strictures 1;
+use Devel::GlobalDestruction;
 
-END { our $sky_falling = 1 }
+sub unimport { our $disarmed = 1 }
 
 sub Moo::HandleMoose::AuthorityHack::DESTROY {
-  unless (our $sky_falling) {
+  unless (our $disarmed or in_global_destruction) {
     require Moo::HandleMoose;
     Moo::HandleMoose->import;
   }