There's no need for _fix_metaclass_compatibility to return anything,
Dave Rolsky [Sun, 14 Sep 2008 02:48:21 +0000 (02:48 +0000)]
it can just alter the reference in place.

lib/Moose.pm
lib/Moose/Meta/Class.pm

index a70af07..cea9fa3 100644 (file)
@@ -61,7 +61,8 @@ sub extends {
     # this checks the metaclass to make sure
     # it is correct, sometimes it can get out
     # of sync when the classes are being built
-    my $meta = Moose::Meta::Class->initialize($class)->_fix_metaclass_incompatibility(@supers);
+    my $meta = Moose::Meta::Class->initialize($class);
+    $meta->_fix_metaclass_incompatibility(@supers);
     $meta->superclasses(@supers);
 }
 
index 321e3ad..5d397aa 100644 (file)
@@ -69,7 +69,7 @@ sub create {
     my $class = $self->SUPER::create($package_name, %options);
 
     if ( my @super = @{ $super || [] } ) {
-        $class = $class->_fix_metaclass_incompatibility(@super);
+        $class->_fix_metaclass_incompatibility(@super);
         $class->superclasses(@super);
     }
 
@@ -325,10 +325,8 @@ sub _fix_metaclass_incompatibility {
                     . ", it isn't pristine" );
         }
 
-        return $self->_reconcile_with_superclass_meta($super);
+        $self->_reconcile_with_superclass_meta($super);
     }
-
-    return $self;
 }
 
 sub _superclass_meta_is_compatible {
@@ -370,28 +368,30 @@ sub _reconcile_with_superclass_meta {
     # incompatibility that we just cannot fix (yet?).
     if ( $super_meta_name->isa( ref $self )
         && all { $super_meta->$_->isa( $self->$_ ) } @MetaClassTypes ) {
-        return $self->_reinitialize_with($super_meta);
+        $self->_reinitialize_with($super_meta);
     }
     elsif ( $self->_all_metaclasses_differ_by_roles_only($super_meta) ) {
-        return $self->_reconcile_role_differences($super_meta);
+        $self->_reconcile_role_differences($super_meta);
     }
-
-    return $self;
 }
 
 sub _reinitialize_with {
     my ( $self, $new_meta ) = @_;
 
-    $self = $new_meta->reinitialize(
+    my $new_self = $new_meta->reinitialize(
         $self->name,
         attribute_metaclass => $new_meta->attribute_metaclass,
         method_metaclass    => $new_meta->method_metaclass,
         instance_metaclass  => $new_meta->instance_metaclass,
     );
 
-    $self->$_( $new_meta->$_ ) for qw( constructor_class destructor_class );
+    $new_self->$_( $new_meta->$_ ) for qw( constructor_class destructor_class );
 
-    return $self;
+    %$self = %$new_self;
+
+    bless $self, ref $new_self;
+
+    Class::MOP::store_metaclass_by_name( $self->name, $self );
 }
 
 # In the more complex case, we share a common ancestor with our