2 use Test::More tests=>14; {
7 use MooseX::Dependent::Types qw(Dependent);
8 use MooseX::Types::Moose qw(Int Str HashRef ArrayRef);
10 use MooseX::Types -declare=>[qw(
17 defined $_->{older_than};
18 }), 'Created InfoHash Set (reduce need to depend on Dict type';
20 ok InfoHash->check({older_than=>25}), 'Good InfoHash';
21 ok !InfoHash->check({older_than=>'aaa'}), 'Bad InfoHash';
22 ok !InfoHash->check({at_least=>25}), 'Bad InfoHash';
24 ok subtype( OlderThanAge,
25 as Dependent[Int, InfoHash],
27 my ($value, $dict) = @_;
28 return $value > $dict->{older_than} ? 1:0;
29 }), 'Created the OlderThanAge subtype';
31 ok OlderThanAge([{older_than=>25}])->check(39), '39 is older than 25';
32 ok OlderThanAge([older_than=>1])->check(9), '9 is older than 1';
33 ok !OlderThanAge([older_than=>1])->check('aaa'), '"aaa" not an int';
34 ok !OlderThanAge([older_than=>10])->check(9), '9 is not older than 10';
36 my $a = OlderThanAge([older_than=>1]);
41 my ($arrayref, $constraining_value) = @_;
43 $age += $_ for @$arrayref;
47 is $a->coerce([1,2,3]), 6, 'Got expected Value';
52 my ($hashref, $constraining_value) = @_;
53 return keys %$hashref;
56 coerce OlderThanAge([older_than=>5]),
59 my ($arrayref, $constraining_value) = @_;
61 $age += $_ for @$arrayref;
65 is OlderThanAge->name, 'main::OlderThanAge',
66 'Got corect name for OlderThanAge';
67 is OlderThanAge([older_than=>5])->coerce([1..10]), 55,
69 like OlderThanAge([older_than=>2])->name, qr/main::OlderThanAge\[/,
70 'Got correct name for OlderThanAge([older_than=>2])';
71 is OlderThanAge([older_than=>2])->coerce({a=>1,b=>2,c=>3,d=>4}), 4,
72 'inherited Coerce works';