8 unless (eval { require MooseX::Role::Parameterized }) {
9 plan skip_all => 'This test needs MooseX::Role::Parameterized';
14 use MooseX::Role::Parameterized;
15 use MooseX::AlwaysCoerce;
16 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');
45 'MooseX::ClassAttribute is currently incompatible with MooseX::Role::Parameterized';
50 eval 'use Test::NoWarnings';
52 ok( (my $instance = MyClass->new), 'instance' );
54 lives_ok { $instance->foo('bar') } 'attribute coercion ran';
56 lives_ok { $instance->bar('baz') } 'class attribute coercion ran';
58 dies_ok { $instance->baz('quux') }
59 'class attribute coercion did not run with coerce => 0';
61 dies_ok { $instance->quux('mtfnpy') }
62 'attribute coercion did not run with coerce => 0';
64 lives_ok { $instance->uncoerced_attr(10) }
65 'set attribute having type with no coercion and no coerce=0';
67 lives_ok { $instance->uncoerced_class_attr(10) }
68 'set class attribute having type with no coercion and no coerce=0';