7 die unless ref $_[0] && ref $_[0] eq 'ARRAY';
9 $Moo::HandleMoose::TYPE_MAP{$type} = sub {
10 require Moose::Util::TypeConstraints;
11 Moose::Util::TypeConstraints::find_type_constraint("ArrayRef");
17 package ClassWithTypes;
18 $INC{'ClassWithTypes.pm'} = __FILE__;
21 has split_comma => (is => 'ro', isa => ::ArrayRef, coerce => sub { [ split /,/, $_[0] ] } );
22 has split_space => (is => 'ro', isa => ::ArrayRef, coerce => sub { [ split / /, $_[0] ] } );
23 has bad_coerce => (is => 'ro', isa => ::ArrayRef, coerce => sub { $_[0] } );
26 my $o = ClassWithTypes->new(split_comma => 'a,b c,d', split_space => 'a,b c,d');
27 is_deeply $o->split_comma, ['a','b c','d'], 'coerce with prebuilt type works';
28 is_deeply $o->split_space, ['a,b','c,d'], ' ... and with different coercion on same type';
31 package MooseSubclassWithTypes;
33 extends 'ClassWithTypes';
36 my $o2 = MooseSubclassWithTypes->new(split_comma => 'a,b c,d', split_space => 'a,b c,d');
37 is_deeply $o2->split_comma, ['a','b c','d'], 'moose subclass has correct coercion';
38 is_deeply $o2->split_space, ['a,b','c,d'], ' ... and with different coercion on same type';
41 exception { MooseSubclassWithTypes->new(bad_coerce => 1) },
42 qr/Validation failed for 'ArrayRef' with value/,
43 'inflated type has correct name';