9 'MooseX::Role::Parameterized' => 0.01,
14 use MooseX::Role::Parameterized;
15 use MooseX::ClassAttribute;
16 use MooseX::AlwaysCoerce;
17 use Moose::Util::TypeConstraints;
20 subtype 'MyType', as 'Int';
21 coerce 'MyType', from 'Str', via { length $_ };
23 subtype 'Uncoerced', as 'Int';
25 has foo => (is => 'rw', isa => 'MyType');
27 class_has bar => (is => 'rw', isa => 'MyType');
29 class_has baz => (is => 'rw', isa => 'MyType', coerce => 0);
31 has quux => (is => 'rw', isa => 'MyType', coerce => 0);
33 has uncoerced_attr => (is => 'rw', isa => 'Uncoerced');
35 class_has uncoerced_class_attr => (is => 'rw', isa => 'Uncoerced');
37 has untyped_attr => (is => 'rw');
39 class_has untyped_class_attr => (is => 'rw');
49 eval 'use Test::NoWarnings';
51 ok( (my $instance = MyClass->new), 'instance' );
54 local $TODO = 'waiting on Moose changes for role support, and ClassAttribute changes for paramterized role support';
57 $instance->foo('bar');
59 } 'attribute coercion ran';
62 $instance->bar('baz');
64 } 'class attribute coercion ran';
66 dies_ok { $instance->baz('quux') }
67 'class attribute coercion did not run with coerce => 0';
69 dies_ok { $instance->quux('mtfnpy') }
70 'attribute coercion did not run with coerce => 0';
73 $instance->uncoerced_attr(10);
74 is $instance->uncoerced_attr(10), 10;
75 } 'set attribute having type with no coercion and no coerce=0';
78 $instance->uncoerced_class_attr(10);
79 is $instance->uncoerced_class_attr(10), 10;
80 } 'set class attribute having type with no coercion and no coerce=0';
83 $instance->untyped_attr(10);
84 is $instance->untyped_attr, 10;
85 } 'set untyped attribute';
88 $instance->untyped_class_attr(10);
89 is $instance->untyped_class_attr, 10;
90 } 'set untyped class attribute';