better handling of method arg validation, more docs and internal questions (hoping...
[gitmo/MooseX-Types.git] / t / lib / DecoratorLibrary.pm
CommitLineData
20b6a7d1 1package DecoratorLibrary;
2
3use warnings;
4use strict;
5
6use MooseX::Types::Moose qw( Str ArrayRef HashRef Int );
7use MooseX::Types
8 -declare => [qw(
9 MyArrayRefBase
10 MyArrayRefInt01
11 MyArrayRefInt02
a706b0f2 12 MyHashRefOfInts
13 MyHashRefOfStr
cf1a8bfa 14 StrOrArrayRef
e088dd03 15 AtLeastOneInt
20b6a7d1 16 )];
17
18subtype MyArrayRefBase,
19 as ArrayRef;
20
21coerce MyArrayRefBase,
22 from Str,
23 via {[split(',', $_)]};
24
25subtype MyArrayRefInt01,
26 as ArrayRef[Int];
27
28coerce MyArrayRefInt01,
29 from Str,
30 via {[split('\.',$_)]},
31 from HashRef,
54f5d4e6 32 via {[sort values(%$_)]};
20b6a7d1 33
34subtype MyArrayRefInt02,
35 as MyArrayRefBase[Int];
a706b0f2 36
37subtype MyHashRefOfInts,
38 as HashRef[Int];
39
40subtype MyHashRefOfStr,
41 as HashRef[Str];
20b6a7d1 42
43coerce MyArrayRefInt02,
44 from Str,
a706b0f2 45 via {[split(':',$_)]},
46 from MyHashRefOfInts,
47 via {[sort values(%$_)]},
48 from MyHashRefOfStr,
49 via {[ sort map { length $_ } values(%$_) ]},
e088dd03 50 ## Can't do HashRef[ArrayRef] here since if I do HashRef get the via {}
51 ## Stuff passed as args.
a706b0f2 52 from HashRef([ArrayRef]),
e088dd03 53 via {[ sort map { @$_ } values(%$_) ]};
cf1a8bfa 54
55subtype StrOrArrayRef,
e088dd03 56 as Str|ArrayRef;
57
58subtype AtLeastOneInt,
59 ## Same problem as MyArrayRefInt02, see above. Another way to solve it by
60 ## forcing some sort of context. Tried to fix this with method prototypes
61 ## but just couldn't make it work.
62 as (ArrayRef[Int]),
63 where { @$_ > 0 };
20b6a7d1 641;