X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FClass.pm;h=51c7d76b892178121b914c9d1caca63f94523b42;hb=e8ad67f0a28dcb7eb4550009e6ef579975ebafec;hp=2ab14cb5d297935d38852c81e24bbd9b4636b904;hpb=43c1bb1ad8ebe5534248ddc761a9bbbc95044643;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index 2ab14cb..51c7d76 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -154,7 +154,7 @@ sub _collect_roles { } -sub find_method_by_name{ +sub find_method_by_name { my($self, $method_name) = @_; defined($method_name) or $self->throw_error('You must define a method name to find'); @@ -179,14 +179,14 @@ sub get_all_method_names { $self->linearized_isa; } -sub find_attribute_by_name{ +sub find_attribute_by_name { my($self, $name) = @_; - my $attr; - foreach my $class($self->linearized_isa){ - my $meta = Mouse::Util::get_metaclass_by_name($class) or next; - $attr = $meta->get_attribute($name) and last; + defined($name) + or $self->throw_error('You must define an attribute name to find'); + foreach my $attr($self->get_all_attributes) { + return $attr if $attr->name eq $name; } - return $attr; + return undef; } sub add_attribute { @@ -231,8 +231,9 @@ sub add_attribute { $attr->install_accessors(); # then register the attribute to the metaclass - $attr->{insertion_order} = keys %{ $self->{attributes} }; - $self->{attributes}{$attr->name} = $attr; + $attr->{insertion_order} = keys %{ $self->{attributes} }; + $self->{attributes}{$name} = $attr; + delete $self->{_mouse_cache}; # clears internal cache if(!$attr->{associated_methods} && ($attr->{is} || '') ne 'bare'){ Carp::carp(qq{Attribute ($name) of class }.$self->name @@ -241,6 +242,21 @@ sub add_attribute { return $attr; } +sub _calculate_all_attributes { + my($self) = @_; + my %seen; + my @all_attrs; + foreach my $class($self->linearized_isa) { + my $meta = Mouse::Util::get_metaclass_by_name($class) or next; + my @attrs = grep { !$seen{$_->name}++ } values %{$meta->{attributes}}; + @attrs = sort { + $b->{insertion_order} <=> $a->{insertion_order} + } @attrs; + push @all_attrs, @attrs; + } + return [reverse @all_attrs]; +} + sub linearized_isa; sub new_object; @@ -445,7 +461,7 @@ Mouse::Meta::Class - The Mouse class metaclass =head1 VERSION -This document describes Mouse version 0.71 +This document describes Mouse version 0.73 =head1 DESCRIPTION