More refactoring of immutable code to make it easy to integrate
Dave Rolsky [Thu, 19 Mar 2009 16:33:07 +0000 (11:33 -0500)]
refactoring with Moose.

lib/Class/MOP/Class.pm
t/010_self_introspection.t

index 24c4677..e6d3015 100644 (file)
@@ -975,18 +975,31 @@ sub is_immutable { 0 }
 sub immutable_transformer { $_[0]->{immutable_transformer} }
 sub _set_immutable_transformer { $_[0]->{immutable_transformer} = $_[1] }
 
+sub make_immutable {
+    my $self = shift;
+
+    return if $self->is_immutable;
+
+    my $transformer = $self->immutable_transformer
+        || $self->_make_immutable_transformer(@_);
+
+    $self->_set_immutable_transformer($transformer);
+
+    $transformer->make_metaclass_immutable;
+}
+
 {
     my %Default_Immutable_Options = (
         read_only   => [qw/superclasses/],
         cannot_call => [
-            qw/
+            qw(
                 add_method
                 alias_method
                 remove_method
                 add_attribute
                 remove_attribute
                 remove_package_symbol
-                /
+                )
         ],
         memoize => {
             class_precedence_list => 'ARRAY',
@@ -1019,22 +1032,19 @@ sub _set_immutable_transformer { $_[0]->{immutable_transformer} = $_[1] }
         },
     );
 
-    sub make_immutable {
-        my $self = shift;
-
-        return if $self->is_immutable;
-
-        my $transformer = $self->immutable_transformer
-            || Class::MOP::Immutable->new(
-            $self,
-            %Default_Immutable_Options,
-            @_
-            );
+    sub _default_immutable_transformer_options {
+        return %Default_Immutable_Options;
+    }
+}
 
-        $self->_set_immutable_transformer($transformer);
+sub _make_immutable_transformer {
+    my $self = shift;
 
-        $transformer->make_metaclass_immutable;
-    }
+    Class::MOP::Immutable->new(
+        $self,
+        $self->_default_immutable_transformer_options,
+        @_
+    );
 }
 
 sub make_mutable {
index c0f4d1b..2328b17 100644 (file)
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 244;
+use Test::More tests => 248;
 use Test::Exception;
 
 use Class::MOP;
@@ -80,6 +80,8 @@ my @class_mop_class_methods = qw(
 
     is_mutable is_immutable make_mutable make_immutable
     immutable_transformer _set_immutable_transformer
+    _make_immutable_transformer
+    _default_immutable_transformer_options
 
     DESTROY
 );