Factor out a free_anon_class method to minimize the logic in DESTROY
Shawn M Moore [Sat, 19 Feb 2011 04:06:54 +0000 (23:06 -0500)]
lib/Class/MOP/Class.pm

index 247a734..ec803e4 100644 (file)
@@ -448,9 +448,13 @@ sub _remove_generated_metaobjects {
 
         return if in_global_destruction(); # it'll happen soon anyway and this just makes things more complicated
 
-        no warnings 'uninitialized';
+        $self->free_anon_class
+            unless $name =~ /^$ANON_CLASS_PREFIX/o;
+    }
+
+    sub free_anon_class {
+        my $self = shift;
         my $name = $self->name;
-        return unless $name =~ /^$ANON_CLASS_PREFIX/o;
 
         # Moose does a weird thing where it replaces the metaclass for
         # class when fixing metaclass incompatibility. In that case,