12 This basically just makes sure that using +name
13 on role attributes works right.
24 default => sub { 10 },
33 has '+bar' => (default => sub { 100 });
34 } '... extended the attribute successfully';
40 is($foo->bar, 100, '... got the extended attribute');
61 } "... narrowed the role's type constraint successfully";
64 my $bar = Bar->new(foo => 42);
66 is($bar->foo, 42, '... got the extended attribute');
68 is($bar->foo, 100, "... can change the attribute's value to an Int");
70 throws_ok { $bar->foo("baz") } qr/^Attribute \(foo\) does not pass the type constraint because: Validation failed for 'Int' with value baz at /;
71 is($bar->foo, 100, "... still has the old Int value");
90 isa => 'Int | ClassName',
92 } "... narrowed the role's type constraint successfully";
95 my $baz = Baz->new(baz => 99);
97 is($baz->baz, 99, '... got the extended attribute');
99 is($baz->baz, 'Foo', "... can change the attribute's value to a ClassName");
101 throws_ok { $baz->baz("zonk") } qr/^Attribute \(baz\) does not pass the type constraint because: Validation failed for 'ClassName\|Int' with value zonk at /;
102 is_deeply($baz->baz, 'Foo', "... still has the old ClassName value");
111 isa => 'Str | Int | Ref',
116 use Moose::Util::TypeConstraints;
126 isa => 'Positive | ArrayRef',
128 } "... narrowed the role's type constraint successfully";
131 my $quux = Quux->new(quux => 99);
132 isa_ok($quux, 'Quux');
133 is($quux->quux, 99, '... got the extended attribute');
135 is($quux->quux, 100, "... can change the attribute's value to an Int");
137 is_deeply($quux->quux, ["hi"], "... can change the attribute's value to an ArrayRef");
139 throws_ok { $quux->quux("quux") } qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' with value quux at /;
140 is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value");
142 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 /;
143 is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value");
163 has '+err1' => (isa => 'Defined');
164 } "can get less specific in the subclass";
167 has '+err2' => (isa => 'Bool');
168 } "or change the type completely";
171 has '+err3' => (isa => 'Str | ArrayRef');
172 } "or add new types to the union";
176 package Role::With::PlusAttr;
182 has '+bar' => ( is => 'ro' );
183 } qr/has '\+attr' is not supported in roles/,
184 "Test has '+attr' in roles explodes";