Commit | Line | Data |
20b6a7d1 |
1 | package DecoratorLibrary; |
2 | |
20b6a7d1 |
3 | use MooseX::Types::Moose qw( Str ArrayRef HashRef Int ); |
4 | use MooseX::Types |
5 | -declare => [qw( |
6 | MyArrayRefBase |
7 | MyArrayRefInt01 |
8 | MyArrayRefInt02 |
a706b0f2 |
9 | MyHashRefOfInts |
10 | MyHashRefOfStr |
cf1a8bfa |
11 | StrOrArrayRef |
e088dd03 |
12 | AtLeastOneInt |
686e5888 |
13 | Jobs |
48a2379b |
14 | SubOfMyArrayRefInt01 |
15 | BiggerInt |
20b6a7d1 |
16 | )]; |
17 | |
18 | subtype MyArrayRefBase, |
19 | as ArrayRef; |
20 | |
21 | coerce MyArrayRefBase, |
22 | from Str, |
23 | via {[split(',', $_)]}; |
24 | |
25 | subtype MyArrayRefInt01, |
26 | as ArrayRef[Int]; |
27 | |
48a2379b |
28 | subtype BiggerInt, |
29 | as Int, |
30 | where {$_>10}; |
31 | |
32 | ## We can change this when the .61 Moose comes out. When that happens we will |
33 | ## have the correct patch to Moose::Meta::TypeConstraint::Parameterized to let |
34 | ## us support parameterizing parameterized subtypes. When we get this we can |
35 | ## then replace the where clause with: |
36 | |
37 | ##as MyArrayRefInt01[BiggerInt]; |
38 | |
39 | subtype SubOfMyArrayRefInt01, |
40 | as MyArrayRefInt01, |
41 | where { |
42 | my $ok_or_not = 1; |
43 | foreach my $int (@$_) { |
44 | $ok_or_not = $int>10 ? 1:0 |
45 | if $ok_or_not; |
46 | } $ok_or_not; |
47 | }; |
48 | |
20b6a7d1 |
49 | coerce MyArrayRefInt01, |
50 | from Str, |
51 | via {[split('\.',$_)]}, |
52 | from HashRef, |
54f5d4e6 |
53 | via {[sort values(%$_)]}; |
20b6a7d1 |
54 | |
55 | subtype MyArrayRefInt02, |
56 | as MyArrayRefBase[Int]; |
a706b0f2 |
57 | |
58 | subtype MyHashRefOfInts, |
59 | as HashRef[Int]; |
60 | |
61 | subtype MyHashRefOfStr, |
62 | as HashRef[Str]; |
20b6a7d1 |
63 | |
64 | coerce MyArrayRefInt02, |
65 | from Str, |
a706b0f2 |
66 | via {[split(':',$_)]}, |
67 | from MyHashRefOfInts, |
68 | via {[sort values(%$_)]}, |
69 | from MyHashRefOfStr, |
70 | via {[ sort map { length $_ } values(%$_) ]}, |
d9002a85 |
71 | from HashRef[ArrayRef], |
e088dd03 |
72 | via {[ sort map { @$_ } values(%$_) ]}; |
cf1a8bfa |
73 | |
74 | subtype StrOrArrayRef, |
e088dd03 |
75 | as Str|ArrayRef; |
475bbd1d |
76 | |
e088dd03 |
77 | subtype AtLeastOneInt, |
d9002a85 |
78 | as ArrayRef[Int], |
e088dd03 |
79 | where { @$_ > 0 }; |
686e5888 |
80 | |
81 | enum Jobs, |
82 | (qw/Programming Teaching Banking/); |
83 | |
20b6a7d1 |
84 | 1; |