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'
35 -values => IsArrayRef( IsObject ));
39 isa => 'HashOfArrayOfObjects',
42 # inline the constraints as anon-subtypes
45 isa => subtype('ArrayRef' => IsArrayRef(IsInt)),
52 my $hash_of_arrays_of_objs = {
54 foo2 => [ Bar->new, Bar->new ],
57 my $array_of_ints = [ 1 .. 10 ];
62 'bar' => $hash_of_arrays_of_objs,
63 'baz' => $array_of_ints,
65 } '... construction succeeded';
68 is_deeply($foo->bar, $hash_of_arrays_of_objs, '... got our value correctly');
69 is_deeply($foo->baz, $array_of_ints, '... got our value correctly');
73 } '... validation failed correctly';
76 $foo->bar({ foo => 3 });
77 } '... validation failed correctly';
80 $foo->bar({ foo => [ 1, 2, 3 ] });
81 } '... validation failed correctly';
85 } '... validation failed correctly';
89 } '... validation failed correctly';