From: Stevan Little Date: Thu, 17 Apr 2008 20:13:29 +0000 (+0000) Subject: adding the applied_traits method to attr X-Git-Tag: 0_55~218 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=82a5b1a76df657fe15fcafd2119283a39df17984;p=gitmo%2FMoose.git adding the applied_traits method to attr --- diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 6ec176d..28b2488 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -46,6 +46,10 @@ __PACKAGE__->meta->add_attribute('documentation' => ( reader => 'documentation', predicate => 'has_documentation', )); +__PACKAGE__->meta->add_attribute('traits' => ( + reader => 'applied_traits', + predicate => 'has_applied_traits', +)); # NOTE: # we need to have a ->does method in here to diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 79ad4f9..bf13b12 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -471,7 +471,7 @@ sub _install_type_coercions ($$) { my $given = shift; my @rv; while ( $given =~ m{ \G (?: $op_union )? ($type) }gcx ) { - push @rv => $1; + push @rv => $1; } (pos($given) eq length($given)) || confess "'$given' didn't parse (parse-pos=" diff --git a/t/020_attributes/015_attribute_traits.t b/t/020_attributes/015_attribute_traits.t index 7eb265b..e83abc0 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 => 8; +use Test::More tests => 9; use Test::Exception; use Test::Moose; @@ -53,7 +53,9 @@ is($c->gorch, 10, '... got the right value for gorch'); can_ok($c, 'baz'); is($c->baz, 100, '... got the right value for baz'); -does_ok($c->meta->get_attribute('bar'), 'My::Attribute::Trait'); +my $bar_attr = $c->meta->get_attribute('bar'); +does_ok($bar_attr, 'My::Attribute::Trait'); +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');