use Devel::GlobalDestruction to avoid destroying anon classes at GD
Yuval Kogman [Sun, 10 Aug 2008 05:19:30 +0000 (05:19 +0000)]
Makefile.PL
lib/Class/MOP/Class.pm

index d94015d..4fdf335 100644 (file)
@@ -28,9 +28,10 @@ my %prereqs = (
     'Sub::Identify' => '0.03',
     'MRO::Compat'   => '0.05',
     'Carp'          => 0,
+    'Devel::GlobalDestruction' => 0,
 );
 
-delete $prereqs{'Sub::Name'}
+delete @prereqs{qw(Sub::Name Devel::GlobalDestruction)}
     unless $has_compiler;
 
 write_makefile();
index a3eacb1..0266f4d 100644 (file)
@@ -209,6 +209,15 @@ sub check_metaclass_compatability {
         return $class->create($package_name, %options);
     }
 
+    BEGIN {
+        local $@;
+        eval {
+            require Devel::GlobalDestruction;
+            Devel::GlobalDestruction->import("in_global_destruction");
+            1;
+        } or *in_global_destruction = sub () { '' };
+    }
+
     # NOTE:
     # this will only get called for
     # anon-classes, all other calls
@@ -217,6 +226,9 @@ sub check_metaclass_compatability {
     # really need to be handled explicitly
     sub DESTROY {
         my $self = shift;
+
+        return if in_global_destruction; # it'll happen soon anyway and this just makes things more complicated
+
         no warnings 'uninitialized';
         return unless $self->name =~ /^$ANON_CLASS_PREFIX/;
         my ($serial_id) = ($self->name =~ /^$ANON_CLASS_PREFIX(\d+)/);