Depend less on $ANON_CLASS_PREFIX
[gitmo/Moose.git] / lib / Class / MOP / Class.pm
index 451744e..d33b978 100644 (file)
@@ -17,8 +17,6 @@ use Devel::GlobalDestruction 'in_global_destruction';
 use Try::Tiny;
 use List::MoreUtils 'all';
 
-our $AUTHORITY = 'cpan:STEVAN';
-
 use base 'Class::MOP::Module',
          'Class::MOP::Mixin::HasAttributes',
          'Class::MOP::Mixin::HasMethods';
@@ -450,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
+            if $self->is_anon_class;
+    }
+
+    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,
@@ -462,11 +464,12 @@ sub _remove_generated_metaobjects {
         my $current_meta = Class::MOP::get_metaclass_by_name($name);
         return if $current_meta ne $self;
 
-        my ($serial_id) = ($name =~ /^$ANON_CLASS_PREFIX(\d+)/o);
+        my ($first_fragments, $last_fragment) = ($name =~ /^(.*)::(.*)$/);
+
         no strict 'refs';
         @{$name . '::ISA'} = ();
         %{$name . '::'}    = ();
-        delete ${$ANON_CLASS_PREFIX}{$serial_id . '::'};
+        delete ${$first_fragments}{$last_fragment . '::'};
 
         Class::MOP::remove_metaclass_by_name($name);
     }