From: Dave Rolsky Date: Thu, 17 Dec 2009 17:22:56 +0000 (-0600) Subject: Don't call meta instance related methods unconditionally in HasAttributes. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2d413af5a93064413d7b005150623ab1d70bb25e;p=gitmo%2FClass-MOP.git Don't call meta instance related methods unconditionally in HasAttributes. Move get_all_attributes back to CMOP::Class, since it only makes sense for things with inheritance. --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 43eb8cd..3142f01 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -243,6 +243,7 @@ sub _check_metaclass_compatibility { no warnings 'uninitialized'; my $name = $self->name; return unless $name =~ /^$ANON_CLASS_PREFIX/o; + # Moose does a weird thing where it replaces the metaclass for # class when fixing metaclass incompatibility. In that case, # we don't want to clean out the namespace now. We can detect @@ -467,6 +468,13 @@ sub rebless_instance_away { # this intentionally does nothing, it is just a hook } +sub get_all_attributes { + my $self = shift; + my %attrs = map { %{ $self->initialize($_)->_attribute_map } } + reverse $self->linearized_isa; + return values %attrs; +} + # Inheritance sub superclasses { diff --git a/lib/Class/MOP/HasAttributes.pm b/lib/Class/MOP/HasAttributes.pm index 45c6021..f106e6b 100644 --- a/lib/Class/MOP/HasAttributes.pm +++ b/lib/Class/MOP/HasAttributes.pm @@ -40,7 +40,8 @@ sub add_attribute { $self->remove_attribute($attr_name); } else { - $self->invalidate_meta_instances(); + $self->invalidate_meta_instances() + if $self->can('invalidate_meta_instances'); } # get our count of previously inserted attributes and @@ -92,7 +93,8 @@ sub remove_attribute { return unless defined $removed_attribute; delete $self->_attribute_map->{$attribute_name}; - $self->invalidate_meta_instances(); + $self->invalidate_meta_instances() + if $self->can('invalidate_meta_instances'); $removed_attribute->remove_accessors(); $removed_attribute->detach_from_class(); @@ -104,13 +106,6 @@ sub get_attribute_list { keys %{ $self->_attribute_map }; } -sub get_all_attributes { - my $self = shift; - my %attrs = map { %{ $self->initialize($_)->_attribute_map } } - reverse $self->linearized_isa; - return values %attrs; -} - sub find_attribute_by_name { my ( $self, $attr_name ) = @_;