X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F020_attributes%2F015_attribute_traits.t;h=428919ed8be9d680c72654786ab32a9434df9e86;hb=f785aad8b8e799322985d8acce2bcb88fadc24a0;hp=7eb265bc61200c5aa7da981208ee367000d0a5c3;hpb=587e457d858eb5130ec7b5a3fc5cda2e6170e643;p=gitmo%2FMoose.git diff --git a/t/020_attributes/015_attribute_traits.t b/t/020_attributes/015_attribute_traits.t index 7eb265b..428919e 100644 --- a/t/020_attributes/015_attribute_traits.t +++ b/t/020_attributes/015_attribute_traits.t @@ -3,24 +3,23 @@ use strict; use warnings; -use Test::More tests => 8; +use Test::More; use Test::Exception; use Test::Moose; -BEGIN { - use_ok('Moose'); -} { package My::Attribute::Trait; use Moose::Role; - + has 'alias_to' => (is => 'ro', isa => 'Str'); - + + has foo => ( is => "ro", default => "blah" ); + after 'install_accessors' => sub { my $self = shift; $self->associated_class->add_method( - $self->alias_to, + $self->alias_to, $self->get_read_method_ref ); }; @@ -29,19 +28,19 @@ BEGIN { { package My::Class; use Moose; - + has 'bar' => ( traits => [qw/My::Attribute::Trait/], is => 'ro', isa => 'Int', alias_to => 'baz', ); - + has 'gorch' => ( is => 'ro', isa => 'Int', default => sub { 10 } - ); + ); } my $c = My::Class->new(bar => 100); @@ -53,9 +52,15 @@ 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'); - -ok(!$c->meta->get_attribute('gorch')->does('My::Attribute::Trait'), '... gorch doesnt do the trait'); - +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'); +is($bar_attr->foo, "blah", "attr initialized"); +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'); +done_testing;