return @attrs;
}
+sub find_attribute_by_name {
+ my ($self, $attr_name) = @_;
+ # keep a record of what we have seen
+ # here, this will handle all the
+ # inheritence issues because we are
+ # using the &class_precedence_list
+ my %seen_class;
+ foreach my $class ($self->class_precedence_list()) {
+ next if $seen_class{$class};
+ $seen_class{$class}++;
+ # fetch the meta-class ...
+ my $meta = $self->initialize($class);
+ return $meta->get_attribute($attr_name)
+ if $meta->has_attribute($attr_name);
+ }
+ return;
+}
+
# Class attributes
sub add_package_variable {
that same information is discoverable through the attribute
meta-object itself.
+=item B<find_attribute_by_name ($attr_name)>
+
+This method will traverse the inheritance heirachy and find the
+first attribute whose name matches C<$attr_name>, then return it.
+It will return undef if nothing is found.
+
=back
=head2 Package Variables
use strict;
use warnings;
-use Test::More tests => 40;
+use Test::More tests => 43;
use Test::Exception;
BEGIN {
my $meta = Baz->meta;
isa_ok($meta, 'Class::MOP::Class');
+ is($meta->find_attribute_by_name('$bar'), $BAR_ATTR, '... got the right attribute for "bar"');
+ is($meta->find_attribute_by_name('$baz'), $BAZ_ATTR, '... got the right attribute for "baz"');
+ is($meta->find_attribute_by_name('$foo'), $FOO_ATTR, '... got the right attribute for "foo"');
+
is_deeply(
[ sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ],
[
use strict;
use warnings;
-use Test::More tests => 134;
+use Test::More tests => 136;
use Test::Exception;
BEGIN {
add_before_method_modifier add_after_method_modifier add_around_method_modifier
has_attribute get_attribute add_attribute remove_attribute
- get_attribute_list get_attribute_map compute_all_applicable_attributes
+ get_attribute_list get_attribute_map compute_all_applicable_attributes find_attribute_by_name
add_package_variable get_package_variable has_package_variable remove_package_variable
);