move this back to HasMethods, since moose roles will need it too
[gitmo/Class-MOP.git] / lib / Class / MOP / Class.pm
index c361d76..96ecf9d 100644 (file)
@@ -408,17 +408,8 @@ sub _restore_metaobjects_from {
     my $self = shift;
     my ($old_meta) = @_;
 
-    for my $method ($old_meta->_get_local_methods) {
-        $self->_make_metaobject_compatible($method);
-        $self->add_method($method->name => $method);
-    }
-
-    for my $attr (sort { $a->insertion_order <=> $b->insertion_order }
-                       map { $old_meta->get_attribute($_) }
-                           $old_meta->get_attribute_list) {
-        $self->_make_metaobject_compatible($attr);
-        $self->add_attribute($attr);
-    }
+    $self->_restore_metamethods_from($old_meta);
+    $self->_restore_metaattributes_from($old_meta);
 }
 
 sub _remove_generated_metaobjects {
@@ -429,32 +420,6 @@ sub _remove_generated_metaobjects {
     }
 }
 
-sub _make_metaobject_compatible {
-    my $self = shift;
-    my ($object) = @_;
-    my $current_single_meta_name = $self->_get_associated_single_metaclass($object);
-    $object->_make_compatible_with($current_single_meta_name);
-}
-
-sub _get_associated_single_metaclass {
-    my $self = shift;
-    my ($single_meta_name) = @_;
-
-    my $current_single_meta_name;
-    if ($single_meta_name->isa('Class::MOP::Method')) {
-        $current_single_meta_name = $self->method_metaclass;
-    }
-    elsif ($single_meta_name->isa('Class::MOP::Attribute')) {
-        $current_single_meta_name = $self->attribute_metaclass;
-    }
-    else {
-        confess "Can't make $single_meta_name compatible, it isn't an "
-              . "attribute or method metaclass.";
-    }
-
-    return $current_single_meta_name;
-}
-
 ## ANON classes
 
 {
@@ -553,18 +518,7 @@ sub create {
 
     $meta->_instantiate_module( $options{version}, $options{authority} );
 
-    # FIXME totally lame
-    $meta->add_method('meta' => sub {
-        if (Class::MOP::DEBUG_NO_META()) {
-            my ($self) = @_;
-            if (my $meta = try { $self->SUPER::meta }) {
-                return $meta if $meta->isa('Class::MOP::Class');
-            }
-            confess "'meta' method called by MOP internals"
-                if caller =~ /Class::MOP|metaclass/;
-        }
-        $class->initialize(ref($_[0]) || $_[0]);
-    }) unless $options{no_meta};
+    $meta->_add_meta_method unless $options{no_meta};
 
     $meta->superclasses(@{$options{superclasses}})
         if exists $options{superclasses};