2 use Test::More tests=>8; {
7 use_ok 'MooseX::Meta::TypeConstraint::Dependent';
8 use_ok 'Moose::Util::TypeConstraints';
10 ## A sample dependent type constraint the requires two ints and see which
13 ok my $int = find_type_constraint('Int') => 'Got Int';
15 my $dep_tc = MooseX::Meta::TypeConstraint::Dependent->new(
16 name => "MooseX::Types::Dependent::Depending" ,
17 parent => find_type_constraint('ArrayRef'),
18 dependent_type_constraint=>$int,
19 comparision_callback=>sub {
20 my ($constraining_value, $check_value) = @_;
21 return $constraining_value > $check_value ? 0:1;
23 constraint_generator =>$int,
24 constraint_generator=> sub {
25 my ($callback, $constraining_value, $check_value) = @_;
26 return $callback->($constraining_value, $check_value) ? 1:0;
30 ## Does this work at all?
32 isa_ok $dep_tc, 'MooseX::Meta::TypeConstraint::Dependent';
34 ok !$dep_tc->check([5,10]), "Fails, 5 is less than 10";
35 ok !$dep_tc->check(['a',10]), "Fails, 'a' is not an Int.";
36 ok !$dep_tc->check([5,'b']), "Fails, 'b' is not an Int either.";
37 ok $dep_tc->check([10,5]), "Success, 10 is greater than 5.";