X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F020_attributes%2F016_attribute_traits_registered.t;h=91dc88aa41839bd7aad21d42ee89b2936223563b;hb=7543127e02af5649f377d0d4246be1188002f91f;hp=611d3d0a07ae640b0e08e03a4ea64fe5cfc38ff6;hpb=39d37838ef6f87c92004ae4d9e6a87cdba26e2b6;p=gitmo%2FMoose.git diff --git a/t/020_attributes/016_attribute_traits_registered.t b/t/020_attributes/016_attribute_traits_registered.t index 611d3d0..91dc88a 100644 --- a/t/020_attributes/016_attribute_traits_registered.t +++ b/t/020_attributes/016_attribute_traits_registered.t @@ -3,28 +3,28 @@ use strict; use warnings; -use Test::More tests => 13; +use Test::More tests => 23; 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 ); }; - + package Moose::Meta::Attribute::Custom::Trait::Aliased; sub register_implementation { 'My::Attribute::Trait' } } @@ -32,19 +32,21 @@ BEGIN { { package My::Other::Attribute::Trait; use Moose::Role; - + my $method = sub { 42; - }; - + }; + + has the_other_attr => ( isa => "Str", is => "rw", default => "oink" ); + after 'install_accessors' => sub { my $self = shift; $self->associated_class->add_method( - 'additional_method', + 'additional_method', $method ); }; - + package Moose::Meta::Attribute::Custom::Trait::Other; sub register_implementation { 'My::Other::Attribute::Trait' } } @@ -52,7 +54,7 @@ BEGIN { { package My::Class; use Moose; - + has 'bar' => ( traits => [qw/Aliased/], is => 'ro', @@ -61,7 +63,7 @@ BEGIN { ); } -{ +{ package My::Derived::Class; use Moose; @@ -80,7 +82,14 @@ is($c->bar, 100, '... got the right value for bar'); can_ok($c, 'baz') and 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($bar_attr->foo, "blah", "attr initialized"); + +ok(!$bar_attr->meta->does_role('Aliased'), "does_role ignores aliases for sanity"); +ok($bar_attr->does('Aliased'), "attr->does uses aliases"); +ok(!$bar_attr->meta->does_role('Fictional'), "does_role returns false for nonexistent roles"); +ok(!$bar_attr->does('Fictional'), "attr->does returns false for nonexistent roles"); my $quux = My::Derived::Class->new(bar => 1000); @@ -88,13 +97,21 @@ is($quux->bar, 1000, '... got the right value for bar'); can_ok($quux, 'baz'); is($quux->baz, 1000, '... got the right value for baz'); -ok($quux->meta->get_attribute('bar')->does('My::Attribute::Trait')); - -TODO: { - local $TODO = 'These do not pass - bug?'; - SKIP: { - skip 'no additional_method, so cannot test its value', 1 if !can_ok($quux, 'additional_method'); - is($quux->additional_method, 42, '... got the right value for additional_method'); - } - ok($quux->meta->get_attribute('bar')->does('My::Other::Attribute::Trait')); -} + +my $derived_bar_attr = $quux->meta->get_attribute("bar"); +does_ok($derived_bar_attr, 'My::Attribute::Trait' ); + +is( $derived_bar_attr->foo, "blah", "attr initialized" ); + +does_ok($derived_bar_attr, 'My::Other::Attribute::Trait' ); + +is($derived_bar_attr->the_other_attr, "oink", "attr initialized" ); + +ok(!$derived_bar_attr->meta->does_role('Aliased'), "does_role ignores aliases for sanity"); +ok($derived_bar_attr->does('Aliased'), "attr->does uses aliases"); +ok(!$derived_bar_attr->meta->does_role('Fictional'), "does_role returns false for nonexistent roles"); +ok(!$derived_bar_attr->does('Fictional'), "attr->does returns false for nonexistent roles"); + +can_ok($quux, 'additional_method'); +is(eval { $quux->additional_method }, 42, '... got the right value for additional_method'); +