10 use_ok("Moose::Util::TypeConstraints");
14 subtype 'MyCollections' => as 'ArrayRef | HashRef';
15 }, undef, '... created the subtype special okay' );
18 my $t = find_type_constraint('MyCollections');
19 isa_ok($t, 'Moose::Meta::TypeConstraint');
21 is($t->name, 'MyCollections', '... name is correct');
24 isa_ok($p, 'Moose::Meta::TypeConstraint::Union');
25 isa_ok($p, 'Moose::Meta::TypeConstraint');
27 is($p->name, 'ArrayRef|HashRef', '... parent name is correct');
29 ok($t->check([]), '... validated it correctly');
30 ok($t->check({}), '... validated it correctly');
31 ok(!$t->check(1), '... validated it correctly');
35 subtype 'MyCollectionsExtended'
36 => as 'ArrayRef|HashRef'
38 if (ref($_) eq 'ARRAY') {
39 return if scalar(@$_) < 2;
41 elsif (ref($_) eq 'HASH') {
42 return if scalar(keys(%$_)) < 2;
46 }, undef, '... created the subtype special okay' );
49 my $t = find_type_constraint('MyCollectionsExtended');
50 isa_ok($t, 'Moose::Meta::TypeConstraint');
52 is($t->name, 'MyCollectionsExtended', '... name is correct');
55 isa_ok($p, 'Moose::Meta::TypeConstraint::Union');
56 isa_ok($p, 'Moose::Meta::TypeConstraint');
58 is($p->name, 'ArrayRef|HashRef', '... parent name is correct');
60 ok(!$t->check([]), '... validated it correctly');
61 ok($t->check([1, 2]), '... validated it correctly');
63 ok(!$t->check({}), '... validated it correctly');
64 ok($t->check({ one => 1, two => 2 }), '... validated it correctly');
66 ok(!$t->check(1), '... validated it correctly');