Fix a bug where a class made immutable and then mutable would end up
Dave Rolsky [Wed, 31 Dec 2008 16:23:50 +0000 (16:23 +0000)]
sharing an immutable transformer with other classes, leading to
bizarro bugs later.

Changes
lib/Class/MOP/Class.pm
t/073_make_mutable.t

diff --git a/Changes b/Changes
index 7a5ebfb..fc58fad 100644 (file)
--- 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
index b197e5e..5aa24df 100644 (file)
@@ -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};
index 1cc9311..7686031 100644 (file)
@@ -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' );
+}