From: Yuval Kogman Date: Sun, 10 Aug 2008 05:19:30 +0000 (+0000) Subject: use Devel::GlobalDestruction to avoid destroying anon classes at GD X-Git-Tag: 0_64_01~59 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9ad4163c74cdbbaf9d1026ab3c0de31baaff32dd;p=gitmo%2FClass-MOP.git use Devel::GlobalDestruction to avoid destroying anon classes at GD --- diff --git a/Makefile.PL b/Makefile.PL index d94015d..4fdf335 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -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(); diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index a3eacb1..0266f4d 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -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+)/);