9 'MooseX::Role::Parameterized' => 0.25,
13 use Test::NoWarnings 1.04 ':early';
17 use MooseX::Role::Parameterized 0.25;
18 use MooseX::ClassAttribute 0.24;
19 use MooseX::AlwaysCoerce;
20 use Moose::Util::TypeConstraints;
23 subtype 'MyType', as 'Int';
24 coerce 'MyType', from 'Str', via { length $_ };
26 subtype 'Uncoerced', as 'Int';
28 has foo => (is => 'rw', isa => 'MyType');
30 class_has bar => (is => 'rw', isa => 'MyType');
32 class_has baz => (is => 'rw', isa => 'MyType', coerce => 0);
34 has quux => (is => 'rw', isa => 'MyType', coerce => 0);
36 has uncoerced_attr => (is => 'rw', isa => 'Uncoerced');
38 class_has uncoerced_class_attr => (is => 'rw', isa => 'Uncoerced');
40 has untyped_attr => (is => 'rw');
42 class_has untyped_class_attr => (is => 'rw');
52 ok( (my $instance = MyClass->new), 'instance' );
55 local $TODO = 'waiting on Moose changes for role support, and ClassAttribute changes for paramterized role support';
58 $instance->foo('bar');
60 }, undef, 'attribute coercion ran' );
63 $instance->bar('baz');
65 }, undef, 'class attribute coercion ran' );
67 isnt( exception { $instance->baz('quux') }, undef, 'class attribute coercion did not run with coerce => 0' );
69 isnt( exception { $instance->quux('mtfnpy') }, undef, 'attribute coercion did not run with coerce => 0' );
72 $instance->uncoerced_attr(10);
73 is $instance->uncoerced_attr(10), 10;
74 }, undef, 'set attribute having type with no coercion and no coerce=0' );
77 $instance->uncoerced_class_attr(10);
78 is $instance->uncoerced_class_attr(10), 10;
79 }, undef, 'set class attribute having type with no coercion and no coerce=0' );
82 $instance->untyped_attr(10);
83 is $instance->untyped_attr, 10;
84 }, undef, 'set untyped attribute' );
87 $instance->untyped_class_attr(10);
88 is $instance->untyped_class_attr, 10;
89 }, undef, 'set untyped class attribute' );