1 package DecoratorLibrary;
3 use MooseX::Types::Moose qw( Str ArrayRef HashRef Int );
15 ## Some questionable messing around
17 my ($subtype, $basetype, @rest) = @_;
18 return subtype($subtype, $basetype, shift @rest, shift @rest);
30 subtype MyArrayRefBase,
33 coerce MyArrayRefBase,
35 via {[split(',', $_)]};
37 subtype MyArrayRefInt01,
40 coerce MyArrayRefInt01,
42 via {[split('\.',$_)]},
44 via {[sort values(%$_)]};
46 subtype MyArrayRefInt02,
47 as MyArrayRefBase[Int];
49 subtype MyHashRefOfInts,
52 subtype MyHashRefOfStr,
55 coerce MyArrayRefInt02,
57 via {[split(':',$_)]},
59 via {[sort values(%$_)]},
61 via {[ sort map { length $_ } values(%$_) ]},
62 ## Can't do HashRef[ArrayRef] here since if I do HashRef get the via {}
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]),
66 via {[ sort map { @$_ } values(%$_) ]};
68 subtype StrOrArrayRef,
71 subtype 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.