10 This tests how well Moose type constraints
11 play with Declare::Constraints::Simple.
13 Pretty well if I do say so myself :)
18 eval "use Declare::Constraints::Simple;";
19 plan skip_all => "Declare::Constraints::Simple is required for this test" if $@;
27 use Moose::Util::TypeConstraints;
28 use Declare::Constraints::Simple -All;
30 # define your own type ...
31 type( 'HashOfArrayOfObjects',
35 -values => IsArrayRef(IsObject)
41 isa => 'HashOfArrayOfObjects',
44 # inline the constraints as anon-subtypes
47 isa => subtype( { as => 'ArrayRef', where => IsArrayRef(IsInt) } ),
54 my $hash_of_arrays_of_objs = {
56 foo2 => [ Bar->new, Bar->new ],
59 my $array_of_ints = [ 1 .. 10 ];
64 'bar' => $hash_of_arrays_of_objs,
65 'baz' => $array_of_ints,
67 } '... construction succeeded';
70 is_deeply($foo->bar, $hash_of_arrays_of_objs, '... got our value correctly');
71 is_deeply($foo->baz, $array_of_ints, '... got our value correctly');
75 } '... validation failed correctly';
78 $foo->bar({ foo => 3 });
79 } '... validation failed correctly';
82 $foo->bar({ foo => [ 1, 2, 3 ] });
83 } '... validation failed correctly';
87 } '... validation failed correctly';
91 } '... validation failed correctly';