8 use Moose::Util::TypeConstraints;
9 use Moose::Meta::TypeConstraint::Parameterized;
11 my $r = Moose::Util::TypeConstraints->get_type_constraint_registry;
15 my $array_of_ints = Moose::Meta::TypeConstraint::Parameterized->new(
16 name => 'ArrayRef[Int]',
17 parent => find_type_constraint('ArrayRef'),
18 type_parameter => find_type_constraint('Int'),
20 isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint::Parameterized');
21 isa_ok($array_of_ints, 'Moose::Meta::TypeConstraint');
23 $r->add_type_constraint($array_of_ints);
25 is(find_type_constraint('ArrayRef[Int]'), $array_of_ints, '... found the type we just added');
29 my $hash_of_ints = Moose::Meta::TypeConstraint::Parameterized->new(
30 name => 'HashRef[Int]',
31 parent => find_type_constraint('HashRef'),
32 type_parameter => find_type_constraint('Int'),
34 isa_ok($hash_of_ints, 'Moose::Meta::TypeConstraint::Parameterized');
35 isa_ok($hash_of_ints, 'Moose::Meta::TypeConstraint');
37 $r->add_type_constraint($hash_of_ints);
39 is(find_type_constraint('HashRef[Int]'), $hash_of_ints, '... found the type we just added');
41 ## now attempt a coercion
46 use Moose::Util::TypeConstraints;
48 coerce 'ArrayRef[Int]'
49 => from 'HashRef[Int]'
50 => via { [ values %$_ ] };
54 isa => 'ArrayRef[Int]',
60 my $foo = Foo->new(bar => { one => 1, two => 2, three => 3 });
63 is_deeply([ sort @{$foo->bar} ], [ 1, 2, 3 ], '... our coercion worked!');