5 use Test::More tests => 3;
10 use MooseX::AlwaysCoerce;
11 use Moose::Util::TypeConstraints;
13 subtype 'MyType', as 'Int';
14 coerce 'MyType', from 'Str', via { length $_ };
16 has foo => (is => 'rw', isa => 'MyType');
18 class_has bar => (is => 'rw', isa => 'MyType');
21 ok( (my $instance = MyClass->new), 'instance' );
23 eval { $instance->foo('bar') };
24 ok( (!$@), 'attribute coercion ran' );
26 eval { $instance->bar('baz') };
27 ok( (!$@), 'class attribute coercion ran' );