From: Jesse Luehrs Date: Fri, 16 Apr 2010 05:39:27 +0000 (-0500) Subject: fix up some immutability stuff X-Git-Tag: 1.02~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3a9318e632e429eb76e16b22c3f0960abe1ccbd7;p=gitmo%2FClass-MOP.git fix up some immutability stuff --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 56951c3..17b5400 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -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); } } diff --git a/t/041_metaclass_incompatibility.t b/t/041_metaclass_incompatibility.t index ac16bc1..da3b599 100644 --- a/t/041_metaclass_incompatibility.t +++ b/t/041_metaclass_incompatibility.t @@ -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;