package DecoratorLibrary;
-use MooseX::Types::Moose qw( Str ArrayRef HashRef Int );
+use MooseX::Types::Moose qw( Str ArrayRef HashRef Int Object);
use MooseX::Types
-declare => [qw(
MyArrayRefBase
MyHashRefOfStr
StrOrArrayRef
AtLeastOneInt
+ Jobs
+ SubOfMyArrayRefInt01
+ BiggerInt
+ isFive
+ isTen
+ isFifteen
+ TwoEqualArrayRefs
+ VeryBigInt
+ FiveOrTenOrFifteen
+ WierdIntergersArrayRef1
+ WierdIntergersArrayRef2
)];
-## Some questionable messing around
- sub my_subtype {
- my ($subtype, $basetype, @rest) = @_;
- return subtype($subtype, $basetype, shift @rest, shift @rest);
- }
-
- sub my_from {
- return @_;
-
- }
- sub my_as {
- return @_;
- }
-## End
-
subtype MyArrayRefBase,
as ArrayRef;
subtype MyArrayRefInt01,
as ArrayRef[Int];
+subtype BiggerInt,
+ as Int,
+ where {$_>10};
+
+subtype SubOfMyArrayRefInt01,
+ as MyArrayRefInt01[BiggerInt];
+
coerce MyArrayRefInt01,
from Str,
via {[split('\.',$_)]},
via {[sort values(%$_)]},
from MyHashRefOfStr,
via {[ sort map { length $_ } values(%$_) ]},
- ## Can't do HashRef[ArrayRef] here since if I do HashRef get the via {}
- ## Stuff passed as args and the associated prototype messed with it. MST
- ## seems to have a line on it but might not fix fixable.
- from (HashRef[ArrayRef]),
+ from HashRef[ArrayRef],
via {[ sort map { @$_ } values(%$_) ]};
subtype StrOrArrayRef,
as Str|ArrayRef;
subtype AtLeastOneInt,
- ## Same problem as MyArrayRefInt02, see above. Another way to solve it by
- ## forcing some sort of context. Tried to fix this with method prototypes
- ## but just couldn't make it work.
- as (ArrayRef[Int]),
+ as ArrayRef[Int],
where { @$_ > 0 };
+
+enum Jobs,
+ (qw/Programming Teaching Banking/);
+
+subtype isFive,
+ as Int,
+ where { $_ == 5};
+
+subtype isTen,
+ as Int,
+ where { $_ == 10};
+
+subtype isFifteen,
+ as Int,
+ where { $_ == 15};
+
+subtype VeryBigInt,
+ as BiggerInt,
+ where {$_>100};
+
+subtype FiveOrTenOrFifteen,
+ as isFive|isTen|isFifteen;
+
+subtype WierdIntergersArrayRef1,
+ as ArrayRef[FiveOrTenOrFifteen|VeryBigInt];
+subtype WierdIntergersArrayRef2,
+ as ArrayRef[FiveOrTenOrFifteen|Object];
1;