7 'MooseX::Role::Parameterized' => 0.25,
11 use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';
15 use MooseX::Role::Parameterized 0.25;
16 use MooseX::ClassAttribute 0.24;
17 use MooseX::AlwaysCoerce;
18 use Moose::Util::TypeConstraints;
21 subtype 'MyType', as 'Int';
22 coerce 'MyType', from 'Str', via { length $_ };
24 subtype 'Uncoerced', as 'Int';
26 has foo => (is => 'rw', isa => 'MyType');
28 class_has bar => (is => 'rw', isa => 'MyType');
30 class_has baz => (is => 'rw', isa => 'MyType', coerce => 0);
32 has quux => (is => 'rw', isa => 'MyType', coerce => 0);
34 has uncoerced_attr => (is => 'rw', isa => 'Uncoerced');
36 class_has uncoerced_class_attr => (is => 'rw', isa => 'Uncoerced');
38 has untyped_attr => (is => 'rw');
40 class_has untyped_class_attr => (is => 'rw');
50 ok( (my $instance = MyClass->new), 'instance' );
53 local $TODO = 'waiting on Moose changes for role support, and ClassAttribute changes for paramterized role support';
56 $instance->foo('bar');
58 }, undef, 'attribute coercion ran' );
61 $instance->bar('baz');
63 }, undef, 'class attribute coercion ran' );
65 isnt( exception { $instance->baz('quux') }, undef, 'class attribute coercion did not run with coerce => 0' );
67 isnt( exception { $instance->quux('mtfnpy') }, undef, 'attribute coercion did not run with coerce => 0' );
70 $instance->uncoerced_attr(10);
71 is $instance->uncoerced_attr(10), 10;
72 }, undef, 'set attribute having type with no coercion and no coerce=0' );
75 $instance->uncoerced_class_attr(10);
76 is $instance->uncoerced_class_attr(10), 10;
77 }, undef, 'set class attribute having type with no coercion and no coerce=0' );
80 $instance->untyped_attr(10);
81 is $instance->untyped_attr, 10;
82 }, undef, 'set untyped attribute' );
85 $instance->untyped_class_attr(10);
86 is $instance->untyped_class_attr, 10;
87 }, undef, 'set untyped class attribute' );