From: Jesse Luehrs Date: Thu, 10 Sep 2009 01:47:11 +0000 (-0500) Subject: save immutable options across make_mutable/make_immutable X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8f4c10691e10c149e6a4f96462e605613722626a;p=gitmo%2FClass-MOP.git save immutable options across make_mutable/make_immutable --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 4d4d6f7..a0b4e39 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -939,7 +939,7 @@ sub is_immutable { 0 } sub _immutable_options { my ( $self, @args ) = @_; - return ( + $self->{_immutable_options} ||= { inline_accessors => 1, inline_constructor => 1, inline_destructor => 0, @@ -948,16 +948,22 @@ sub _immutable_options { constructor_name => $self->constructor_name, constructor_class => $self->constructor_class, destructor_class => $self->destructor_class, + }; + $self->{_immutable_options} = { + %{ $self->{_immutable_options} }, @args, - ); + }; + + return %{ $self->{_immutable_options} }; } sub make_immutable { my ( $self, @args ) = @_; if ( $self->is_mutable ) { - $self->_initialize_immutable( $self->_immutable_options(@args) ); - $self->_rebless_as_immutable(@args); + $self->_immutable_options(@args); + $self->_initialize_immutable; + $self->_rebless_as_immutable; return $self; } else { @@ -981,11 +987,13 @@ sub make_mutable { } sub _rebless_as_immutable { - my ( $self, @args ) = @_; + my ( $self ) = @_; $self->{__immutable}{original_class} = ref $self; - bless $self => $self->_immutable_metaclass(@args); + bless $self => $self->_immutable_metaclass( + %{ $self->{_immutable_options} } + ); } sub _immutable_metaclass { @@ -1067,10 +1075,10 @@ sub _add_inlined_method { } sub _initialize_immutable { - my ( $self, %args ) = @_; + my ( $self ) = @_; - $self->{__immutable}{options} = \%args; - $self->_install_inlined_code(%args); + $self->{__immutable}{options} = $self->{_immutable_options}; + $self->_install_inlined_code(%{ $self->{_immutable_options} }); } sub _install_inlined_code { diff --git a/t/075_immutable_options_saved.t b/t/075_immutable_options_saved.t index ba5e2af..d5b2ae3 100644 --- a/t/075_immutable_options_saved.t +++ b/t/075_immutable_options_saved.t @@ -15,9 +15,7 @@ ok(!$meta->has_method('new'), $meta->make_mutable; $meta->make_immutable; -{ local $TODO = "make_immutable doesn't save options yet"; ok($meta->has_method('foo'), "constructor is generated with correct name by default after roundtrip"); ok(!$meta->has_method('new'), "constructor is not generated with incorrect name by default after roundtrip"); -}