From: Dave Rolsky Date: Thu, 19 Mar 2009 16:33:07 +0000 (-0500) Subject: More refactoring of immutable code to make it easy to integrate X-Git-Tag: 0.78_02~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=61747843d1cd7484c4d8059a24929189fb470458;p=gitmo%2FClass-MOP.git More refactoring of immutable code to make it easy to integrate refactoring with Moose. --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 24c4677..e6d3015 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -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 { diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index c0f4d1b..2328b17 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -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 );