incremented version and updated changelog, fixed bug that created extra coercions...
[gitmo/MooseX-Types.git] / t / lib / DecoratorLibrary.pm
CommitLineData
20b6a7d1 1package DecoratorLibrary;
2
20b6a7d1 3use MooseX::Types::Moose qw( Str ArrayRef HashRef Int );
4use MooseX::Types
5 -declare => [qw(
6 MyArrayRefBase
7 MyArrayRefInt01
8 MyArrayRefInt02
a706b0f2 9 MyHashRefOfInts
10 MyHashRefOfStr
cf1a8bfa 11 StrOrArrayRef
e088dd03 12 AtLeastOneInt
20b6a7d1 13 )];
14
475bbd1d 15## Some questionable messing around
16 sub my_subtype {
17 my ($subtype, $basetype, @rest) = @_;
18 return subtype($subtype, $basetype, shift @rest, shift @rest);
19 }
20
21 sub my_from {
22 return @_;
23
24 }
25 sub my_as {
26 return @_;
27 }
28## End
29
20b6a7d1 30subtype MyArrayRefBase,
31 as ArrayRef;
32
33coerce MyArrayRefBase,
34 from Str,
35 via {[split(',', $_)]};
36
37subtype MyArrayRefInt01,
38 as ArrayRef[Int];
39
40coerce MyArrayRefInt01,
41 from Str,
42 via {[split('\.',$_)]},
43 from HashRef,
54f5d4e6 44 via {[sort values(%$_)]};
20b6a7d1 45
46subtype MyArrayRefInt02,
47 as MyArrayRefBase[Int];
a706b0f2 48
49subtype MyHashRefOfInts,
50 as HashRef[Int];
51
52subtype MyHashRefOfStr,
53 as HashRef[Str];
20b6a7d1 54
55coerce MyArrayRefInt02,
56 from Str,
a706b0f2 57 via {[split(':',$_)]},
58 from MyHashRefOfInts,
59 via {[sort values(%$_)]},
60 from MyHashRefOfStr,
61 via {[ sort map { length $_ } values(%$_) ]},
e088dd03 62 ## Can't do HashRef[ArrayRef] here since if I do HashRef get the via {}
475bbd1d 63 ## Stuff passed as args and the associated prototype messed with it. MST
64 ## seems to have a line on it but might not fix fixable.
65 from (HashRef[ArrayRef]),
e088dd03 66 via {[ sort map { @$_ } values(%$_) ]};
cf1a8bfa 67
68subtype StrOrArrayRef,
e088dd03 69 as Str|ArrayRef;
475bbd1d 70
e088dd03 71subtype AtLeastOneInt,
72 ## Same problem as MyArrayRefInt02, see above. Another way to solve it by
73 ## forcing some sort of context. Tried to fix this with method prototypes
74 ## but just couldn't make it work.
75 as (ArrayRef[Int]),
76 where { @$_ > 0 };
475bbd1d 77
20b6a7d1 781;