Don't destroy a metaclass that has an existing entry in the MOP cache
Dave Rolsky [Sun, 14 Sep 2008 21:09:14 +0000 (21:09 +0000)]
lib/Class/MOP/Class.pm

index 3908891..afa8212 100644 (file)
@@ -222,6 +222,13 @@ sub check_metaclass_compatability {
 
         no warnings 'uninitialized';
         return unless $self->name =~ /^$ANON_CLASS_PREFIX/;
+        # Moose does a weird thing where it replaces the metaclass for
+        # class when fixing metaclass incompatibility. In that case,
+        # we don't want to clean out the namespace now. We can detect
+        # that because Moose will explicitly update the singleton
+        # cache in Class::MOP.
+        return if Class::MOP::does_metaclass_exist($self->name);
+
         my ($serial_id) = ($self->name =~ /^$ANON_CLASS_PREFIX(\d+)/);
         no strict 'refs';
         foreach my $key (keys %{$ANON_CLASS_PREFIX . $serial_id}) {