From: Stevan Little Date: Thu, 17 Apr 2008 20:20:24 +0000 (+0000) Subject: cleaning up stuff; X-Git-Tag: 0_55~217 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=88f2397731d9dc7da456b70b1c1c452bc4b396e2;p=gitmo%2FMoose.git cleaning up stuff; --- diff --git a/Changes b/Changes index 41b0682..440997e 100644 --- a/Changes +++ b/Changes @@ -46,6 +46,9 @@ Revision history for Perl extension Moose - when an attribute property is malformed (such as lazy without a default), give the name of the attribute in the error message (Sartak) + - added the &applied_traits and &has_applied_traits methods + to allow introspection of traits + - added tests for this * Moose::Object - localize $@ inside DEMOLISHALL to avoid it diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 28b2488..01cc66f 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -708,6 +708,15 @@ in some kind of automated documentation system perhaps. Returns true if this meta-attribute has any documentation. +=item B + +This will return the ARRAY ref of all the traits applied to this +attribute, or if no traits have been applied, it returns C. + +=item B + +Returns true if this meta-attribute has any traits applied. + =back =head1 BUGS diff --git a/t/020_attributes/015_attribute_traits.t b/t/020_attributes/015_attribute_traits.t index e83abc0..ed7f4fe 100644 --- a/t/020_attributes/015_attribute_traits.t +++ b/t/020_attributes/015_attribute_traits.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 9; +use Test::More tests => 12; use Test::Exception; use Test::Moose; @@ -55,9 +55,13 @@ is($c->baz, 100, '... got the right value for baz'); my $bar_attr = $c->meta->get_attribute('bar'); does_ok($bar_attr, 'My::Attribute::Trait'); +ok($bar_attr->has_applied_traits, '... got the applied traits'); is_deeply($bar_attr->applied_traits, [qw/My::Attribute::Trait/], '... got the applied traits'); -ok(!$c->meta->get_attribute('gorch')->does('My::Attribute::Trait'), '... gorch doesnt do the trait'); +my $gorch_attr = $c->meta->get_attribute('gorch'); +ok(!$gorch_attr->does('My::Attribute::Trait'), '... gorch doesnt do the trait'); +ok(!$gorch_attr->has_applied_traits, '... no traits applied'); +is($gorch_attr->applied_traits, undef, '... no traits applied');