From: Tokuhiro Matsuno Date: Tue, 10 Mar 2009 23:28:23 +0000 (+0900) Subject: added Meta::Class->add_attribute_list for Moose compatibility X-Git-Tag: 0.20~36 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c68b41108207ca7568f6f99a66cb6d202623a236;p=gitmo%2FMouse.git added Meta::Class->add_attribute_list for Moose compatibility --- diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index f4a94e4..0e410a3 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -156,6 +156,10 @@ sub compute_all_applicable_attributes { sub get_attribute_map { $_[0]->{attributes} } sub has_attribute { exists $_[0]->{attributes}->{$_[1]} } sub get_attribute { $_[0]->{attributes}->{$_[1]} } +sub get_attribute_list { + my $self = shift; + keys %{$self->get_attribute_map}; +} sub linearized_isa { @{ get_linear_isa($_[0]->name) } } @@ -415,6 +419,12 @@ this class and its superclasses. Returns a mapping of attribute names to their corresponding L objects. +=head2 get_attribute_list -> { name => Mouse::Meta::Attribute } + +This returns a list of attribute names which are defined in the local +class. If you want a list of all applicable attributes for a class, +use the C method. + =head2 has_attribute Name -> Bool Returns whether we have a L with the given name. diff --git a/t/100-meta-class.t b/t/100-meta-class.t index b90c6ca..264a81e 100644 --- a/t/100-meta-class.t +++ b/t/100-meta-class.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 14; +use Test::More tests => 15; do { package Class; @@ -23,7 +23,7 @@ is_deeply([$meta->superclasses], ['Mouse::Object'], "correctly inherting from Mo my $meta2 = Class->meta; is($meta, $meta2, "same metaclass instance"); -can_ok($meta, 'name', 'get_attribute_map'); +can_ok($meta, 'name', 'get_attribute_map', 'get_attribute_list'); ok($meta->has_attribute('pawn')); my $attr = $meta->get_attribute('pawn'); @@ -33,6 +33,9 @@ is($attr->name, 'pawn', 'got the correct attribute'); my $map = $meta->get_attribute_map; is_deeply($map, { pawn => $attr }, "attribute map"); +my $list = [$meta->get_attribute_list]; +is_deeply($list, [ 'pawn' ], "attribute list"); + ok(!$meta->has_attribute('nonexistent_attribute')); eval "