10 use_ok('Moose::Util::TypeConstraints');
11 use_ok('Moose::Meta::TypeConstraint::Parameterized');
14 my $r = Moose::Util::TypeConstraints->get_type_constraint_registry;
18 my $array_of_ints = Moose::Meta::TypeConstraint::Parameterized->new(
19 name => 'ArrayRef[Int]',
20 parent => find_type_constraint('ArrayRef'),
21 type_parameter => find_type_constraint('Int'),
23 isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint::Parameterized');
24 isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint');
26 $r->add_type_constraint($array_of_ints);
28 is(find_type_constraint('ArrayRef[Int]'), $array_of_ints, '... found the type we just added');
32 my $hash_of_ints = Moose::Meta::TypeConstraint::Parameterized->new(
33 name => 'HashRef[Int]',
34 parent => find_type_constraint('HashRef'),
35 type_parameter => find_type_constraint('Int'),
37 isa_ok($hash_of_ints, 'Moose::Meta::TypeConstraint::Parameterized');
38 isa_ok($hash_of_ints, 'Moose::Meta::TypeConstraint');
40 $r->add_type_constraint($hash_of_ints);
42 is(find_type_constraint('HashRef[Int]'), $hash_of_ints, '... found the type we just added');
44 ## now attempt a coercion
49 use Moose::Util::TypeConstraints;
51 coerce 'ArrayRef[Int]'
52 => from 'HashRef[Int]'
53 => via { [ values %$_ ] };
57 isa => 'ArrayRef[Int]',
63 my $foo = Foo->new(bar => { one => 1, two => 2, three => 3 });
66 is_deeply([ sort @{$foo->bar} ], [ 1, 2, 3 ], '... our coercion worked!');