9 use_ok('Moose::Util::TypeConstraints');
10 use_ok('Moose::Meta::TypeConstraint::Parameterized');
13 my $r = Moose::Util::TypeConstraints->get_type_constraint_registry;
17 my $array_of_ints = Moose::Meta::TypeConstraint::Parameterized->new(
18 name => 'ArrayRef[Int]',
19 parent => find_type_constraint('ArrayRef'),
20 type_parameter => find_type_constraint('Int'),
22 isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint::Parameterized');
23 isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint');
25 $r->add_type_constraint($array_of_ints);
27 is(find_type_constraint('ArrayRef[Int]'), $array_of_ints, '... found the type we just added');
31 my $hash_of_ints = Moose::Meta::TypeConstraint::Parameterized->new(
32 name => 'HashRef[Int]',
33 parent => find_type_constraint('HashRef'),
34 type_parameter => find_type_constraint('Int'),
36 isa_ok($hash_of_ints, 'Moose::Meta::TypeConstraint::Parameterized');
37 isa_ok($hash_of_ints, 'Moose::Meta::TypeConstraint');
39 $r->add_type_constraint($hash_of_ints);
41 is(find_type_constraint('HashRef[Int]'), $hash_of_ints, '... found the type we just added');
43 ## now attempt a coercion
48 use Moose::Util::TypeConstraints;
50 coerce 'ArrayRef[Int]'
51 => from 'HashRef[Int]'
52 => via { [ values %$_ ] };
56 isa => 'ArrayRef[Int]',
62 my $foo = Foo->new(bar => { one => 1, two => 2, three => 3 });
65 is_deeply([ sort @{$foo->bar} ], [ 1, 2, 3 ], '... our coercion worked!');