10 This tests how well Moose type constraints
11 play with Declare::Constraints::Simple.
13 Pretty well if I do say so myself :)
18 'Declare::Constraints::Simple' => '0.01', # skip all if not installed
26 use Moose::Util::TypeConstraints;
27 use Declare::Constraints::Simple -All;
29 # define your own type ...
30 type( 'HashOfArrayOfObjects',
34 -values => IsArrayRef(IsObject)
40 isa => 'HashOfArrayOfObjects',
43 # inline the constraints as anon-subtypes
46 isa => subtype( { as => 'ArrayRef', where => IsArrayRef(IsInt) } ),
53 my $hash_of_arrays_of_objs = {
55 foo2 => [ Bar->new, Bar->new ],
58 my $array_of_ints = [ 1 .. 10 ];
63 'bar' => $hash_of_arrays_of_objs,
64 'baz' => $array_of_ints,
66 } '... construction succeeded';
69 is_deeply($foo->bar, $hash_of_arrays_of_objs, '... got our value correctly');
70 is_deeply($foo->baz, $array_of_ints, '... got our value correctly');
74 } '... validation failed correctly';
77 $foo->bar({ foo => 3 });
78 } '... validation failed correctly';
81 $foo->bar({ foo => [ 1, 2, 3 ] });
82 } '... validation failed correctly';
86 } '... validation failed correctly';
90 } '... validation failed correctly';