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_ok('Moose::Util::TypeConstraints');
33 use Moose::Util::TypeConstraints;
34 use Declare::Constraints::Simple -All;
36 # define your own type ...
37 type 'HashOfArrayOfObjects'
40 -values => IsArrayRef( IsObject ));
44 isa => 'HashOfArrayOfObjects',
47 # inline the constraints as anon-subtypes
50 isa => subtype('ArrayRef' => IsArrayRef(IsInt)),
57 my $hash_of_arrays_of_objs = {
59 foo2 => [ Bar->new, Bar->new ],
62 my $array_of_ints = [ 1 .. 10 ];
67 'bar' => $hash_of_arrays_of_objs,
68 'baz' => $array_of_ints,
70 } '... construction succeeded';
73 is_deeply($foo->bar, $hash_of_arrays_of_objs, '... got our value correctly');
74 is_deeply($foo->baz, $array_of_ints, '... got our value correctly');
78 } '... validation failed correctly';
81 $foo->bar({ foo => 3 });
82 } '... validation failed correctly';
85 $foo->bar({ foo => [ 1, 2, 3 ] });
86 } '... validation failed correctly';
90 } '... validation failed correctly';
94 } '... validation failed correctly';