From: Jesse Luehrs Date: Mon, 27 Sep 2010 00:12:56 +0000 (-0500) Subject: reorder these methods into a more "proper" order X-Git-Tag: 1.09~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e6e93343be33a87d193739755ee4dc0d71be65c3;p=gitmo%2FClass-MOP.git reorder these methods into a more "proper" order --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index be340e5..8a7473f 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -235,18 +235,6 @@ sub _check_metaclass_compatibility { } } -sub _class_metaclass_is_compatible { - my $self = shift; - my ( $superclass_name ) = @_; - - my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name) - || return 1; - - my $super_meta_type = $super_meta->_real_ref_name; - - return $self->isa($super_meta_type); -} - sub _check_class_metaclass_compatibility { my $self = shift; my ( $superclass_name ) = @_; @@ -263,24 +251,16 @@ sub _check_class_metaclass_compatibility { } } -sub _single_metaclass_is_compatible { +sub _class_metaclass_is_compatible { my $self = shift; - my ( $metaclass_type, $superclass_name ) = @_; + my ( $superclass_name ) = @_; my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name) || return 1; - # for instance, Moose::Meta::Class has a error_class attribute, but - # Class::MOP::Class doesn't - this shouldn't be an error - return 1 unless $super_meta->can($metaclass_type); - # for instance, Moose::Meta::Class has a destructor_class, but - # Class::MOP::Class doesn't - this shouldn't be an error - return 1 unless defined $super_meta->$metaclass_type; - # if metaclass is defined in superclass but not here, it's not compatible - # this is a really odd case - return 0 unless defined $self->$metaclass_type; + my $super_meta_type = $super_meta->_real_ref_name; - return $self->$metaclass_type->isa($super_meta->$metaclass_type); + return $self->isa($super_meta_type); } sub _check_single_metaclass_compatibility { @@ -301,53 +281,24 @@ sub _check_single_metaclass_compatibility { } } -sub _can_fix_class_metaclass_incompatibility_by_subclassing { - my $self = shift; - my ($super_meta) = @_; - - my $super_meta_type = $super_meta->_real_ref_name; - - return $super_meta_type ne blessed($self) - && $super_meta->isa(blessed($self)); -} - -sub _can_fix_single_metaclass_incompatibility_by_subclassing { +sub _single_metaclass_is_compatible { my $self = shift; - my ($metaclass_type, $super_meta) = @_; + my ( $metaclass_type, $superclass_name ) = @_; - my $specific_meta = $self->$metaclass_type; - return unless $super_meta->can($metaclass_type); - my $super_specific_meta = $super_meta->$metaclass_type; + my $super_meta = Class::MOP::get_metaclass_by_name($superclass_name) + || return 1; + # for instance, Moose::Meta::Class has a error_class attribute, but + # Class::MOP::Class doesn't - this shouldn't be an error + return 1 unless $super_meta->can($metaclass_type); # for instance, Moose::Meta::Class has a destructor_class, but # Class::MOP::Class doesn't - this shouldn't be an error - return unless defined $super_specific_meta; - - # if metaclass is defined in superclass but not here, it's fixable + return 1 unless defined $super_meta->$metaclass_type; + # if metaclass is defined in superclass but not here, it's not compatible # this is a really odd case - return 1 unless defined $specific_meta; - - return $specific_meta ne $super_specific_meta - && $super_specific_meta->isa($specific_meta); -} - -sub _can_fix_metaclass_incompatibility_by_subclassing { - my $self = shift; - my ($super_meta) = @_; - - return 1 if $self->_can_fix_class_metaclass_incompatibility_by_subclassing($super_meta); - - my %base_metaclass = $self->_base_metaclasses; - for my $metaclass_type (keys %base_metaclass) { - return 1 if $self->_can_fix_single_metaclass_incompatibility_by_subclassing($metaclass_type, $super_meta); - } - - return; -} + return 0 unless defined $self->$metaclass_type; -sub _can_fix_metaclass_incompatibility { - my $self = shift; - return $self->_can_fix_metaclass_incompatibility_by_subclassing(@_); + return $self->$metaclass_type->isa($super_meta->$metaclass_type); } sub _fix_metaclass_incompatibility { @@ -379,6 +330,55 @@ sub _fix_metaclass_incompatibility { } } +sub _can_fix_metaclass_incompatibility { + my $self = shift; + return $self->_can_fix_metaclass_incompatibility_by_subclassing(@_); +} + +sub _can_fix_metaclass_incompatibility_by_subclassing { + my $self = shift; + my ($super_meta) = @_; + + return 1 if $self->_can_fix_class_metaclass_incompatibility_by_subclassing($super_meta); + + my %base_metaclass = $self->_base_metaclasses; + for my $metaclass_type (keys %base_metaclass) { + return 1 if $self->_can_fix_single_metaclass_incompatibility_by_subclassing($metaclass_type, $super_meta); + } + + return; +} + +sub _can_fix_class_metaclass_incompatibility_by_subclassing { + my $self = shift; + my ($super_meta) = @_; + + my $super_meta_type = $super_meta->_real_ref_name; + + return $super_meta_type ne blessed($self) + && $super_meta->isa(blessed($self)); +} + +sub _can_fix_single_metaclass_incompatibility_by_subclassing { + my $self = shift; + my ($metaclass_type, $super_meta) = @_; + + my $specific_meta = $self->$metaclass_type; + return unless $super_meta->can($metaclass_type); + my $super_specific_meta = $super_meta->$metaclass_type; + + # for instance, Moose::Meta::Class has a destructor_class, but + # Class::MOP::Class doesn't - this shouldn't be an error + return unless defined $super_specific_meta; + + # if metaclass is defined in superclass but not here, it's fixable + # this is a really odd case + return 1 unless defined $specific_meta; + + return $specific_meta ne $super_specific_meta + && $super_specific_meta->isa($specific_meta); +} + sub _fix_class_metaclass_incompatibility { my $self = shift; my ( $super_meta ) = @_; @@ -409,46 +409,29 @@ sub _fix_single_metaclass_incompatibility { } } -sub _get_associated_single_metaclass { +sub _restore_metaobjects_from { my $self = shift; - my ($single_meta_name) = @_; + my ($old_meta) = @_; - 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."; + for my $method ($old_meta->_get_local_methods) { + $self->_make_metaobject_compatible($method); + $self->add_method($method->name => $method); } - return $current_single_meta_name; -} - -sub _get_compatible_single_metaclass_by_subclassing { - my $self = shift; - my ($single_meta_name) = @_; - - my $current_single_meta_name = $self->_get_associated_single_metaclass($single_meta_name); - - if ($single_meta_name->isa($current_single_meta_name)) { - return $single_meta_name; - } - elsif ($current_single_meta_name->isa($single_meta_name)) { - return $current_single_meta_name; + 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); } - - return; } -sub _get_compatible_single_metaclass { +sub _remove_generated_metaobjects { my $self = shift; - my ($single_meta_name) = @_; - return $self->_get_compatible_single_metaclass_by_subclassing($single_meta_name); + for my $attr (map { $self->get_attribute($_) } $self->get_attribute_list) { + $attr->remove_accessors; + } } sub _make_metaobject_compatible { @@ -470,29 +453,46 @@ sub _make_metaobject_compatible { return $object; } -sub _restore_metaobjects_from { +sub _get_associated_single_metaclass { my $self = shift; - my ($old_meta) = @_; + my ($single_meta_name) = @_; - for my $method ($old_meta->_get_local_methods) { - $self->_make_metaobject_compatible($method); - $self->add_method($method->name => $method); + my $current_single_meta_name; + if ($single_meta_name->isa('Class::MOP::Method')) { + $current_single_meta_name = $self->method_metaclass; } - - 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); + 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; } -sub _remove_generated_metaobjects { +sub _get_compatible_single_metaclass { my $self = shift; + my ($single_meta_name) = @_; - for my $attr (map { $self->get_attribute($_) } $self->get_attribute_list) { - $attr->remove_accessors; + return $self->_get_compatible_single_metaclass_by_subclassing($single_meta_name); +} + +sub _get_compatible_single_metaclass_by_subclassing { + my $self = shift; + my ($single_meta_name) = @_; + + my $current_single_meta_name = $self->_get_associated_single_metaclass($single_meta_name); + + if ($single_meta_name->isa($current_single_meta_name)) { + return $single_meta_name; + } + elsif ($current_single_meta_name->isa($single_meta_name)) { + return $current_single_meta_name; } + + return; } ## ANON classes