From: Shawn M Moore Date: Thu, 27 Mar 2008 04:54:14 +0000 (+0000) Subject: Instead of belaboring the point, make sure that "Type" => "Subtype A | Subtype B... X-Git-Tag: 0_55~252 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b78357312fea47a162d5f8c4bf83767f4591946a;p=gitmo%2FMoose.git Instead of belaboring the point, make sure that "Type" => "Subtype A | Subtype B" works --- diff --git a/t/030_roles/017_extending_role_attrs.t b/t/030_roles/017_extending_role_attrs.t index 55d1410..35138b6 100644 --- a/t/030_roles/017_extending_role_attrs.t +++ b/t/030_roles/017_extending_role_attrs.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 29; +use Test::More tests => 28; use Test::Exception; BEGIN { @@ -42,6 +42,7 @@ isa_ok($foo, 'Foo'); is($foo->bar, 100, '... got the extended attribute'); + { package Bar::Role; use Moose::Role; @@ -63,7 +64,6 @@ is($foo->bar, 100, '... got the extended attribute'); } "... narrowed the role's type constraint successfully"; } - my $bar = Bar->new(foo => 42); isa_ok($bar, 'Bar'); is($bar->foo, 42, '... got the extended attribute'); @@ -73,13 +73,14 @@ is($bar->foo, 100, "... can change the attribute's value to an Int"); throws_ok { $bar->foo("baz") } qr/^Attribute \(foo\) does not pass the type constraint because: Validation failed for 'Int' failed with value baz at /; is($bar->foo, 100, "... still has the old Int value"); + { package Baz::Role; use Moose::Role; has 'baz' => ( is => 'rw', - isa => 'Str | Int | ArrayRef', + isa => 'Value', ); package Baz; @@ -89,22 +90,20 @@ is($bar->foo, 100, "... still has the old Int value"); ::lives_ok { has '+baz' => ( - isa => 'Int | ArrayRef', + isa => 'Int | ClassName', ) } "... narrowed the role's type constraint successfully"; } - my $baz = Baz->new(baz => 99); isa_ok($baz, 'Baz'); is($baz->baz, 99, '... got the extended attribute'); -$baz->baz(100); -is($baz->baz, 100, "... can change the attribute's value to an Int"); -$baz->baz(["hi"]); -is_deeply($baz->baz, ["hi"], "... can change the attribute's value to an ArrayRef"); +$baz->baz('Foo'); +is($baz->baz, 'Foo', "... can change the attribute's value to a ClassName"); + +throws_ok { $baz->baz("zonk") } qr/^Attribute \(baz\) does not pass the type constraint because: Validation failed for 'Int \| ClassName' failed with value zonk at /; +is_deeply($baz->baz, 'Foo', "... still has the old ClassName value"); -throws_ok { $baz->baz("quux") } qr/^Attribute \(baz\) does not pass the type constraint because: Validation failed for 'Int \| ArrayRef' failed with value quux at /; -is_deeply($baz->baz, ["hi"], "... still has the old ArrayRef value"); { package Quux::Role; @@ -132,7 +131,6 @@ is_deeply($baz->baz, ["hi"], "... still has the old ArrayRef value"); } "... narrowed the role's type constraint successfully"; } - my $quux = Quux->new(quux => 99); isa_ok($quux, 'Quux'); is($quux->quux, 99, '... got the extended attribute'); @@ -147,6 +145,7 @@ is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value"); throws_ok { $quux->quux({a => 1}) } qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'Positive \| ArrayRef' failed with value HASH\(\w+\) at /; is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value"); + { package Err::Role; use Moose::Role;