Commit | Line | Data |
ae1d0652 |
1 | use Test::More tests=>1; { |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::Exception; |
7 | use MooseX::Types::Dependent qw(Depending); |
8 | use MooseX::Types::Moose qw(Int ArrayRef ); |
9 | use MooseX::Types -declare => [qw( |
10 | UniqueInt |
11 | )]; |
12 | |
13 | ## sugar for alternative syntax: depending {} TC,TC |
14 | sub depending(&@) { |
15 | my ($coderef, $dependent_tc, $constraining_tc, @args) = @_; |
16 | if(@args) { |
17 | return (Depending[$dependent_tc,$coderef,$constraining_tc],@args); |
18 | } else { |
19 | return Depending[$dependent_tc,$coderef,$constraining_tc]; |
20 | } |
21 | } |
22 | |
23 | ok subtype UniqueInt, |
24 | as depending { |
25 | my ($dependent_int, $constraining_arrayref) = @_; |
26 | (grep { $_ == $dependent_int} @$constraining_arrayref) ? undef:1 |
27 | } Int, ArrayRef[Int], |
28 | where { |
29 | my ($dependent_val, $constraining_value) = @$_; |
30 | return $dependent_val > 2 ? 1:undef; |
31 | }; |
32 | } |