9 'MooseX::Role::Parameterized' => 0.25,
14 use MooseX::Role::Parameterized 0.25;
15 use MooseX::ClassAttribute 0.24;
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 }, undef, 'attribute coercion ran' );
62 $instance->bar('baz');
64 }, undef, 'class attribute coercion ran' );
66 isnt( exception { $instance->baz('quux') }, undef, 'class attribute coercion did not run with coerce => 0' );
68 isnt( exception { $instance->quux('mtfnpy') }, undef, 'attribute coercion did not run with coerce => 0' );
71 $instance->uncoerced_attr(10);
72 is $instance->uncoerced_attr(10), 10;
73 }, undef, 'set attribute having type with no coercion and no coerce=0' );
76 $instance->uncoerced_class_attr(10);
77 is $instance->uncoerced_class_attr(10), 10;
78 }, undef, 'set class attribute having type with no coercion and no coerce=0' );
81 $instance->untyped_attr(10);
82 is $instance->untyped_attr, 10;
83 }, undef, 'set untyped attribute' );
86 $instance->untyped_class_attr(10);
87 is $instance->untyped_class_attr, 10;
88 }, undef, 'set untyped class attribute' );