6 package ClassWithTypes;
7 $INC{'ClassWithTypes.pm'} = __FILE__;
9 use MooX::Types::MooseLike::Base qw(ArrayRef);
11 has split_comma => (is => 'ro', isa => ArrayRef, coerce => sub { [ split /,/, $_[0] ] } );
12 has split_space => (is => 'ro', isa => ArrayRef, coerce => sub { [ split / /, $_[0] ] } );
13 has bad_coerce => (is => 'ro', isa => ArrayRef, coerce => sub { $_[0] } );
16 my $o = ClassWithTypes->new(split_comma => 'a,b c,d', split_space => 'a,b c,d');
17 is_deeply $o->split_comma, ['a','b c','d'], 'coerce with prebuilt type works';
18 is_deeply $o->split_space, ['a,b','c,d'], ' ... and with different coercion on same type';
21 package MooseSubclassWithTypes;
23 extends 'ClassWithTypes';
26 my $o2 = MooseSubclassWithTypes->new(split_comma => 'a,b c,d', split_space => 'a,b c,d');
27 is_deeply $o2->split_comma, ['a','b c','d'], 'moose subclass has correct coercion';
28 is_deeply $o2->split_space, ['a,b','c,d'], ' ... and with different coercion on same type';
31 exception { MooseSubclassWithTypes->new(bad_coerce => 1) },
32 qr/Validation failed for 'ArrayRef' with value/,
33 'inflated type has correct name';