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 $@;
28 use Moose::Util::TypeConstraints;
29 use Declare::Constraints::Simple -All;
31 # define your own type ...
32 type( 'HashOfArrayOfObjects',
36 -values => IsArrayRef(IsObject)
42 isa => 'HashOfArrayOfObjects',
45 # inline the constraints as anon-subtypes
48 isa => subtype( { as => 'ArrayRef', where => IsArrayRef(IsInt) } ),
55 my $hash_of_arrays_of_objs = {
57 foo2 => [ Bar->new, Bar->new ],
60 my $array_of_ints = [ 1 .. 10 ];
65 'bar' => $hash_of_arrays_of_objs,
66 'baz' => $array_of_ints,
68 } '... construction succeeded';
71 is_deeply($foo->bar, $hash_of_arrays_of_objs, '... got our value correctly');
72 is_deeply($foo->baz, $array_of_ints, '... got our value correctly');
76 } '... validation failed correctly';
79 $foo->bar({ foo => 3 });
80 } '... validation failed correctly';
83 $foo->bar({ foo => [ 1, 2, 3 ] });
84 } '... validation failed correctly';
88 } '... validation failed correctly';
92 } '... validation failed correctly';