07304aae14e48c597f555a98f957a7a48741ec98
[gitmo/MooseX-Types.git] / t / lib / DecoratorLibrary.pm
1 <<<<<<< .working
2 package DecoratorLibrary;
3
4 use MooseX::Types::Moose qw( Str ArrayRef HashRef Int );
5 use MooseX::Types
6     -declare => [qw(
7         MyArrayRefBase
8         MyArrayRefInt01
9         MyArrayRefInt02
10         MyHashRefOfInts
11         MyHashRefOfStr
12         StrOrArrayRef
13         AtLeastOneInt
14         Jobs
15         SubOfMyArrayRefInt01
16         BiggerInt
17     )];
18
19 subtype MyArrayRefBase,
20     as ArrayRef;
21     
22 coerce MyArrayRefBase,
23     from Str,
24     via {[split(',', $_)]};
25     
26 subtype MyArrayRefInt01,
27     as ArrayRef[Int];
28
29 subtype BiggerInt,
30     as Int,
31     where {$_>10};
32
33 ## We can change this when the .61 Moose comes out.  When that happens we will
34 ## have the correct patch to Moose::Meta::TypeConstraint::Parameterized to let
35 ## us support parameterizing parameterized subtypes.  When we get this we can
36 ## then replace the where clause with:
37
38     ##as MyArrayRefInt01[BiggerInt];
39
40 subtype SubOfMyArrayRefInt01,
41     as MyArrayRefInt01,
42     where {
43         my $ok_or_not = 1;
44         foreach my $int (@$_) {
45             $ok_or_not = $int>10 ? 1:0
46              if $ok_or_not;
47         } $ok_or_not;
48     };
49
50 coerce MyArrayRefInt01,
51     from Str,
52     via {[split('\.',$_)]},
53     from HashRef,
54     via {[sort values(%$_)]};
55     
56 subtype MyArrayRefInt02,
57     as MyArrayRefBase[Int];
58     
59 subtype MyHashRefOfInts,
60     as HashRef[Int];
61     
62 subtype MyHashRefOfStr,
63     as HashRef[Str];
64
65 coerce MyArrayRefInt02,
66     from Str,
67     via {[split(':',$_)]},
68     from MyHashRefOfInts,
69     via {[sort values(%$_)]},
70     from MyHashRefOfStr,
71     via {[ sort map { length $_ } values(%$_) ]},
72     from HashRef[ArrayRef],
73     via {[ sort map { @$_ } values(%$_) ]};
74
75 subtype StrOrArrayRef,
76     as Str|ArrayRef;
77
78 subtype AtLeastOneInt,
79     as ArrayRef[Int],
80     where { @$_ > 0 };
81     
82 enum Jobs,
83     (qw/Programming Teaching Banking/);
84     
85 1;
86 =======
87 package DecoratorLibrary;
88
89 use MooseX::Types::Moose qw( Str ArrayRef HashRef Int );
90 use MooseX::Types
91     -declare => [qw(
92         MyArrayRefBase
93         MyArrayRefInt01
94         MyArrayRefInt02
95         MyHashRefOfInts
96         MyHashRefOfStr
97         StrOrArrayRef
98         AtLeastOneInt
99         Jobs
100         SubOfMyArrayRefInt01
101         BiggerInt
102     )];
103
104 subtype MyArrayRefBase,
105     as ArrayRef;
106     
107 coerce MyArrayRefBase,
108     from Str,
109     via {[split(',', $_)]};
110     
111 subtype MyArrayRefInt01,
112     as ArrayRef[Int];
113
114 subtype BiggerInt,
115     as Int,
116     where {$_>10};
117     
118 subtype SubOfMyArrayRefInt01,
119     as MyArrayRefInt01[BiggerInt];
120
121 coerce MyArrayRefInt01,
122     from Str,
123     via {[split('\.',$_)]},
124     from HashRef,
125     via {[sort values(%$_)]};
126     
127 subtype MyArrayRefInt02,
128     as MyArrayRefBase[Int];
129     
130 subtype MyHashRefOfInts,
131     as HashRef[Int];
132     
133 subtype MyHashRefOfStr,
134     as HashRef[Str];
135
136 coerce MyArrayRefInt02,
137     from Str,
138     via {[split(':',$_)]},
139     from MyHashRefOfInts,
140     via {[sort values(%$_)]},
141     from MyHashRefOfStr,
142     via {[ sort map { length $_ } values(%$_) ]},
143     from HashRef[ArrayRef],
144     via {[ sort map { @$_ } values(%$_) ]};
145
146 subtype StrOrArrayRef,
147     as Str|ArrayRef;
148
149 subtype AtLeastOneInt,
150     as ArrayRef[Int],
151     where { @$_ > 0 };
152     
153 enum Jobs,
154     (qw/Programming Teaching Banking/);
155     
156 1;
157 >>>>>>> .merge-right.r6407