From: Dave Rolsky Date: Wed, 31 Dec 2008 16:23:50 +0000 (+0000) Subject: Fix a bug where a class made immutable and then mutable would end up X-Git-Tag: 0.75~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d89108ab6145d29d7edeb9b06509ed2d8f8c5f44;p=gitmo%2FClass-MOP.git Fix a bug where a class made immutable and then mutable would end up sharing an immutable transformer with other classes, leading to bizarro bugs later. --- diff --git a/Changes b/Changes index 7a5ebfb..fc58fad 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,12 @@ Revision history for Perl extension Class-MOP. +0.75 Tue, December 31, 2008 + * Class::MOP::Class + - A class that was made immutable and then mutable could end up + sharing an immutable transformer object + (Class::MOP::Immutable) with other classes, leading to all + sorts of odd bugs. Reported by t0m. (Dave Rolsky) + 0.74 Tue, December 25, 2008 * MOP.xs - Add an xs implementation of Class::MOP::is_class_loaded (closes diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index b197e5e..5aa24df 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -1055,8 +1055,7 @@ sub is_immutable { 0 } sub get_immutable_transformer { my $self = shift; if( $self->is_mutable ){ - my $class = ref $self || $self; - return $IMMUTABLE_TRANSFORMERS{$class} ||= $self->create_immutable_transformer; + return $IMMUTABLE_TRANSFORMERS{$self->name} ||= $self->create_immutable_transformer; } confess "unable to find transformer for immutable class" unless exists $IMMUTABLE_OPTIONS{$self->name}; diff --git a/t/073_make_mutable.t b/t/073_make_mutable.t index 1cc9311..7686031 100644 --- a/t/073_make_mutable.t +++ b/t/073_make_mutable.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 113; +use Test::More tests => 114; use Test::Exception; use Scalar::Util; @@ -228,3 +228,12 @@ use Class::MOP; for qw(get_meta_instance compute_all_applicable_attributes class_precedence_list get_method_map ); } + +{ + Foo->meta->make_immutable; + Bar->meta->make_immutable; + Bar->meta->make_mutable; + + isnt( Foo->meta->get_immutable_transformer, Bar->meta->get_immutable_transformer, + 'Foo and Bar should have different immutable transformer objects' ); +}