From: Dave Rolsky Date: Mon, 26 Apr 2010 18:03:39 +0000 (-0500) Subject: Refactor code to replace $self with a new object into its own method X-Git-Tag: 1.05~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6a52b083252adecd5049dc7dde4a2b8f1e13ddd1;p=gitmo%2FMoose.git Refactor code to replace $self with a new object into its own method --- diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index d23de0f..1e2cb86 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -544,13 +544,8 @@ sub _fix_class_metaclass_incompatibility { my $new_self = $class_meta_subclass_meta->name->reinitialize( $self->name, ); - %$self = %$new_self; - bless $self, $class_meta_subclass_meta->name; - # We need to replace the cached metaclass instance or else when it - # goes out of scope Class::MOP::Class destroy's the namespace for - # the metaclass's class, causing much havoc. - Class::MOP::store_metaclass_by_name( $self->name, $self ); - Class::MOP::weaken_metaclass( $self->name ) if $self->is_anon_class; + + $self->_replace_self( $new_self, $class_meta_subclass_meta->name ); } } @@ -570,16 +565,26 @@ sub _fix_single_metaclass_incompatibility { $self->name, $metaclass_type => $class_specific_meta_subclass_meta->name, ); - %$self = %$new_self; - bless $self, blessed($super_meta); - # We need to replace the cached metaclass instance or else when it - # goes out of scope Class::MOP::Class destroy's the namespace for - # the metaclass's class, causing much havoc. - Class::MOP::store_metaclass_by_name( $self->name, $self ); - Class::MOP::weaken_metaclass( $self->name ) if $self->is_anon_class; + + $self->_replace_self( $new_self, blessed($super_meta) ); } } + +sub _replace_self { + my $self = shift; + my ( $new_self, $new_class) = @_; + + %$self = %$new_self; + bless $self, $new_class; + + # We need to replace the cached metaclass instance or else when it goes + # out of scope Class::MOP::Class destroy's the namespace for the + # metaclass's class, causing much havoc. + Class::MOP::store_metaclass_by_name( $self->name, $self ); + Class::MOP::weaken_metaclass( $self->name ) if $self->is_anon_class; +} + sub _process_attribute { my ( $self, $name, @args ) = @_;