2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
10 $TODO = q{Mouse is not yet completed};
16 This basically just makes sure that using +name
17 on role attributes works right.
28 default => sub { 10 },
37 has '+bar' => (default => sub { 100 });
38 } '... extended the attribute successfully';
44 is($foo->bar, 100, '... got the extended attribute');
65 } "... narrowed the role's type constraint successfully";
68 my $bar = Bar->new(foo => 42);
70 is($bar->foo, 42, '... got the extended attribute');
72 is($bar->foo, 100, "... can change the attribute's value to an Int");
74 throws_ok { $bar->foo("baz") } qr/^Attribute \(foo\) does not pass the type constraint because: Validation failed for 'Int' with value baz at /;
75 is($bar->foo, 100, "... still has the old Int value");
94 isa => 'Int | ClassName',
96 } "... narrowed the role's type constraint successfully";
99 my $baz = Baz->new(baz => 99);
101 is($baz->baz, 99, '... got the extended attribute');
103 is($baz->baz, 'Foo', "... can change the attribute's value to a ClassName");
105 throws_ok { $baz->baz("zonk") } qr/^Attribute \(baz\) does not pass the type constraint because: Validation failed for 'ClassName\|Int' with value zonk at /;
106 is_deeply($baz->baz, 'Foo', "... still has the old ClassName value");
115 isa => 'Str | Int | Ref',
120 use Mouse::Util::TypeConstraints;
130 isa => 'Positive | ArrayRef',
132 } "... narrowed the role's type constraint successfully";
135 my $quux = Quux->new(quux => 99);
136 isa_ok($quux, 'Quux');
137 is($quux->quux, 99, '... got the extended attribute');
139 is($quux->quux, 100, "... can change the attribute's value to an Int");
141 is_deeply($quux->quux, ["hi"], "... can change the attribute's value to an ArrayRef");
143 throws_ok { $quux->quux("quux") } qr/^Attribute \(quux\) does not pass the type constraint because: Validation failed for 'ArrayRef\|Positive' with value quux at /;
144 is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value");
146 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 /;
147 is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value");
167 has '+err1' => (isa => 'Defined');
168 } "can get less specific in the subclass";
171 has '+err2' => (isa => 'Bool');
172 } "or change the type completely";
175 has '+err3' => (isa => 'Str | ArrayRef');
176 } "or add new types to the union";
180 package Role::With::PlusAttr;
186 has '+bar' => ( is => 'ro' );
187 } qr/has '\+attr' is not supported in roles/,
188 "Test has '+attr' in roles explodes";