fix up some immutability stuff
Jesse Luehrs [Fri, 16 Apr 2010 05:39:27 +0000 (00:39 -0500)]
lib/Class/MOP/Class.pm
t/041_metaclass_incompatibility.t

index 56951c3..17b5400 100644 (file)
@@ -384,7 +384,10 @@ sub _fix_class_metaclass_incompatibility {
     my ( $super_meta ) = @_;
 
     if ($self->_can_fix_class_metaclass_incompatibility_by_subclassing($super_meta)) {
-        $super_meta->meta->rebless_instance($self);
+        my $super_meta_name = $super_meta->is_immutable
+                                  ? $super_meta->_get_mutable_metaclass_name
+                                  : blessed($super_meta);
+        $super_meta_name->meta->rebless_instance($self);
     }
 }
 
index ac16bc1..da3b599 100644 (file)
@@ -193,4 +193,25 @@ isa_ok(Class::MOP::class_of('Foo::Reverse::Sub::Sub'), 'Foo::Meta::Class');
               "can't switch out the attribute metaclass of a class that already has attributes";
 }
 
+# immutability...
+
+{
+    my $foometa = Foo::Meta::Class->create(
+        'Foo::Immutable',
+    );
+    $foometa->make_immutable;
+    my $barmeta = Class::MOP::Class->create(
+        'Bar::Mutable',
+    );
+    my $bazmeta = Class::MOP::Class->create(
+        'Baz::Mutable',
+    );
+    $bazmeta->superclasses($foometa->name);
+    lives_ok { $bazmeta->superclasses($barmeta->name) }
+             "can still set superclasses";
+    ok(!$bazmeta->is_immutable,
+       "immutable superclass doesn't make this class immutable");
+    lives_ok { $bazmeta->make_immutable } "can still make immutable";
+}
+
 done_testing;