From: Jesse Luehrs Date: Mon, 27 Sep 2010 06:59:52 +0000 (-0500) Subject: push this stuff back into HasMethods and HasAttributes X-Git-Tag: 1.09~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=78902d1df967dfe480294acbeb65e2e2bae4439e;p=gitmo%2FClass-MOP.git push this stuff back into HasMethods and HasAttributes --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index c361d76..2dbd9f2 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -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 { diff --git a/lib/Class/MOP/Mixin/HasAttributes.pm b/lib/Class/MOP/Mixin/HasAttributes.pm index 7b7daaf..b06db4a 100644 --- a/lib/Class/MOP/Mixin/HasAttributes.pm +++ b/lib/Class/MOP/Mixin/HasAttributes.pm @@ -85,6 +85,18 @@ sub get_attribute_list { keys %{ $self->_attribute_map }; } +sub _restore_metaattributes_from { + my $self = shift; + my ($old_meta) = @_; + + for my $attr (sort { $a->insertion_order <=> $b->insertion_order } + map { $old_meta->get_attribute($_) } + $old_meta->get_attribute_list) { + $attr->_make_compatible_with($self->attribute_metaclass); + $self->add_attribute($attr); + } +} + 1; __END__ diff --git a/lib/Class/MOP/Mixin/HasMethods.pm b/lib/Class/MOP/Mixin/HasMethods.pm index 50684a9..bd28e40 100644 --- a/lib/Class/MOP/Mixin/HasMethods.pm +++ b/lib/Class/MOP/Mixin/HasMethods.pm @@ -189,6 +189,16 @@ sub _get_local_methods { keys %{$namespace}; } +sub _restore_metamethods_from { + my $self = shift; + my ($old_meta) = @_; + + for my $method ($old_meta->_get_local_methods) { + $method->_make_compatible_with($self->method_metaclass); + $self->add_method($method->name => $method); + } +} + 1; __END__ diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index dd02209..7c0a962 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -79,8 +79,6 @@ my @class_mop_class_methods = qw( _class_metaclass_can_be_made_compatible _single_metaclass_can_be_made_compatible - _get_associated_single_metaclass - _make_metaobject_compatible _remove_generated_metaobjects _restore_metaobjects_from