more tests for union types
[gitmo/MooseX-Types.git] / t / lib / DecoratorLibrary.pm
index c99c189..6ad113c 100644 (file)
@@ -1,9 +1,6 @@
 package DecoratorLibrary;
 
-use warnings;
-use strict;
-
-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
@@ -12,6 +9,18 @@ use MooseX::Types
         MyHashRefOfInts
         MyHashRefOfStr
         StrOrArrayRef
+        AtLeastOneInt
+        Jobs
+        SubOfMyArrayRefInt01
+        BiggerInt
+        isFive
+        isTen
+        isFifteen
+        TwoEqualArrayRefs
+        VeryBigInt
+        FiveOrTenOrFifteen
+        WierdIntergersArrayRef1
+        WierdIntergersArrayRef2
     )];
 
 subtype MyArrayRefBase,
@@ -24,6 +33,13 @@ coerce MyArrayRefBase,
 subtype MyArrayRefInt01,
     as ArrayRef[Int];
 
+subtype BiggerInt,
+    as Int,
+    where {$_>10};
+    
+subtype SubOfMyArrayRefInt01,
+    as MyArrayRefInt01[BiggerInt];
+
 coerce MyArrayRefInt01,
     from Str,
     via {[split('\.',$_)]},
@@ -46,10 +62,41 @@ coerce MyArrayRefInt02,
     via {[sort values(%$_)]},
     from MyHashRefOfStr,
     via {[ sort map { length $_ } values(%$_) ]},
-    ### Can't do HashRef[ArrayRef] here, need to force precidence I guess???
-    from HashRef([ArrayRef]),
-    via {[ sort map { @$_ } values(%$_)] };
+    from HashRef[ArrayRef],
+    via {[ sort map { @$_ } values(%$_) ]};
 
 subtype StrOrArrayRef,
-    from Str|ArrayRef;
+    as Str|ArrayRef;
+
+subtype AtLeastOneInt,
+    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;