more tests for union types
[gitmo/MooseX-Types.git] / t / lib / DecoratorLibrary.pm
index 880b456..6ad113c 100644 (file)
@@ -1,6 +1,6 @@
 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
@@ -11,23 +11,18 @@ use MooseX::Types
         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;
     
@@ -38,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('\.',$_)]},
@@ -73,4 +75,28 @@ subtype AtLeastOneInt,
 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;