From: John Napiorkowski Date: Sun, 29 Mar 2009 17:18:24 +0000 (+0000) Subject: Got the basic requirement in place! X-Git-Tag: 0.01~48 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9274c53e6cbcb7cac4a8ebd1ee7841a93c33fbe8;p=gitmo%2FMooseX-Dependent.git Got the basic requirement in place! --- diff --git a/lib/MooseX/Types/Dependent.pm b/lib/MooseX/Types/Dependent.pm index b4f10ef..3f45cf1 100644 --- a/lib/MooseX/Types/Dependent.pm +++ b/lib/MooseX/Types/Dependent.pm @@ -21,16 +21,16 @@ MooseX::Types::Dependent - L constraints that depend on values. as Depending[ Int, sub { - shift->not_exists(shift); + shift->exists(shift) ? 0:1; }, Set, ]; possible sugar options - Depending - as Depending sub :Set {} Int; - depending(Set $set) { $set->exists($Int) } Int; + as Depending { + shift->exists(shift) ? 0:1; + } [Int, Set]; May have some ready to go, such as as isGreaterThan[ diff --git a/t/01-basic.t b/t/01-basic.t index 611cb06..97dfdd9 100644 --- a/t/01-basic.t +++ b/t/01-basic.t @@ -15,7 +15,7 @@ use Test::More tests=>9; { my $dep_tc = MooseX::Meta::TypeConstraint::Dependent->new( name => "MooseX::Types::Dependent::Depending" , - parent => find_type_constraint('Int'), + parent => find_type_constraint('ArrayRef'), dependent_type_constraint=>$int, comparison_callback=>sub { my ($constraining_value, $check_value) = @_; @@ -31,9 +31,9 @@ use Test::More tests=>9; { isa_ok $dep_tc, 'MooseX::Meta::TypeConstraint::Dependent'; - ok !$dep_tc->check('a',10), "Fails, 'a' is not an Int."; - ok !$dep_tc->check(5,'b'), "Fails, 'b' is not an Int either."; - ok !$dep_tc->check([4,1]), "Fails, since this isn't an arrayref"; - ok !$dep_tc->check(5,10), "Fails, 5 is less than 10"; - ok $dep_tc->check(11,6), "Success, 11 is greater than 6."; + ok !$dep_tc->check(['a',10]), "Fails, 'a' is not an Int."; + ok !$dep_tc->check([5,'b']), "Fails, 'b' is not an Int either."; + ok !$dep_tc->check({4,1}), "Fails, since this isn't an arrayref"; + ok !$dep_tc->check([5,10]), "Fails, 5 is less than 10"; + ok $dep_tc->check([11,6]), "Success, 11 is greater than 6."; }