Commit | Line | Data |
20b6a7d1 |
1 | package DecoratorLibrary; |
2 | |
905ff8f2 |
3 | use MooseX::Types::Moose qw( Str ArrayRef HashRef Int Object); |
20b6a7d1 |
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 |
905ff8f2 |
16 | isFive |
17 | isTen |
18 | isFifteen |
19 | TwoEqualArrayRefs |
20 | VeryBigInt |
21 | FiveOrTenOrFifteen |
22 | WierdIntergersArrayRef1 |
23 | WierdIntergersArrayRef2 |
20b6a7d1 |
24 | )]; |
25 | |
26 | subtype MyArrayRefBase, |
27 | as ArrayRef; |
28 | |
29 | coerce MyArrayRefBase, |
30 | from Str, |
31 | via {[split(',', $_)]}; |
32 | |
33 | subtype MyArrayRefInt01, |
34 | as ArrayRef[Int]; |
35 | |
48a2379b |
36 | subtype BiggerInt, |
37 | as Int, |
38 | where {$_>10}; |
af976fb2 |
39 | |
48a2379b |
40 | subtype SubOfMyArrayRefInt01, |
af976fb2 |
41 | as MyArrayRefInt01[BiggerInt]; |
48a2379b |
42 | |
20b6a7d1 |
43 | coerce MyArrayRefInt01, |
44 | from Str, |
45 | via {[split('\.',$_)]}, |
46 | from HashRef, |
54f5d4e6 |
47 | via {[sort values(%$_)]}; |
20b6a7d1 |
48 | |
49 | subtype MyArrayRefInt02, |
50 | as MyArrayRefBase[Int]; |
a706b0f2 |
51 | |
52 | subtype MyHashRefOfInts, |
53 | as HashRef[Int]; |
54 | |
55 | subtype MyHashRefOfStr, |
56 | as HashRef[Str]; |
20b6a7d1 |
57 | |
58 | coerce MyArrayRefInt02, |
59 | from Str, |
a706b0f2 |
60 | via {[split(':',$_)]}, |
61 | from MyHashRefOfInts, |
62 | via {[sort values(%$_)]}, |
63 | from MyHashRefOfStr, |
64 | via {[ sort map { length $_ } values(%$_) ]}, |
d9002a85 |
65 | from HashRef[ArrayRef], |
e088dd03 |
66 | via {[ sort map { @$_ } values(%$_) ]}; |
cf1a8bfa |
67 | |
68 | subtype StrOrArrayRef, |
e088dd03 |
69 | as Str|ArrayRef; |
475bbd1d |
70 | |
e088dd03 |
71 | subtype AtLeastOneInt, |
d9002a85 |
72 | as ArrayRef[Int], |
e088dd03 |
73 | where { @$_ > 0 }; |
686e5888 |
74 | |
75 | enum Jobs, |
76 | (qw/Programming Teaching Banking/); |
77 | |
905ff8f2 |
78 | subtype isFive, |
79 | as Int, |
80 | where { $_ == 5}; |
81 | |
82 | subtype isTen, |
83 | as Int, |
84 | where { $_ == 10}; |
85 | |
86 | subtype isFifteen, |
87 | as Int, |
88 | where { $_ == 15}; |
89 | |
90 | subtype VeryBigInt, |
91 | as BiggerInt, |
92 | where {$_>100}; |
93 | |
94 | subtype FiveOrTenOrFifteen, |
95 | as isFive|isTen|isFifteen; |
96 | |
97 | subtype WierdIntergersArrayRef1, |
98 | as ArrayRef[FiveOrTenOrFifteen|VeryBigInt]; |
99 | |
100 | subtype WierdIntergersArrayRef2, |
101 | as ArrayRef[FiveOrTenOrFifteen|Object]; |
20b6a7d1 |
102 | 1; |