6 use Test::More tests => 27;
13 This basically just makes sure that using +name
14 on role attributes works right.
25 default => sub { 10 },
34 has '+bar' => (default => sub { 100 });
35 } '... extended the attribute successfully';
41 is($foo->bar, 100, '... got the extended attribute');
62 } "... narrowed the role's type constraint successfully";
65 my $bar = Bar->new(foo => 42);
67 is($bar->foo, 42, '... got the extended attribute');
69 is($bar->foo, 100, "... can change the attribute's value to an Int");
71 throws_ok { $bar->foo("baz") } qr/^Attribute \(foo\) does not pass the type constraint because: Validation failed for 'Int' with value baz at /;
72 is($bar->foo, 100, "... still has the old Int value");
91 isa => 'Int | ClassName',
93 } "... narrowed the role's type constraint successfully";
96 my $baz = Baz->new(baz => 99);
98 is($baz->baz, 99, '... got the extended attribute');
100 is($baz->baz, 'Foo', "... can change the attribute's value to a ClassName");
102 throws_ok { $baz->baz("zonk") } qr/^Attribute \(baz\) does not pass the type constraint because: Validation failed for 'ClassName\|Int' with value zonk at /;
103 is_deeply($baz->baz, 'Foo', "... still has the old ClassName value");
112 isa => 'Str | Int | Ref',
117 use Mouse::Util::TypeConstraints;
127 isa => 'Positive | ArrayRef',
129 } "... narrowed the role's type constraint successfully";
132 my $quux = Quux->new(quux => 99);
133 isa_ok($quux, 'Quux');
134 is($quux->quux, 99, '... got the extended attribute');
136 is($quux->quux, 100, "... can change the attribute's value to an Int");
138 is_deeply($quux->quux, ["hi"], "... can change the attribute's value to an ArrayRef");
140 throws_ok { $quux->quux("quux") } qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' with value quux at /;
141 is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value");
143 throws_ok { $quux->quux({a => 1}) } qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' with value HASH\(\w+\) at /;
144 is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value");
164 has '+err1' => (isa => 'Defined');
165 } "can get less specific in the subclass";
168 has '+err2' => (isa => 'Bool');
169 } "or change the type completely";
172 has '+err3' => (isa => 'Str | ArrayRef');
173 } "or add new types to the union";