added a tags directory for releases
John Napiorkowski [Fri, 24 Oct 2008 20:16:55 +0000 (20:16 +0000)]
t/13_typedecorator.t
t/lib/DecoratorLibrary.pm

index 3f250e6..e22aca5 100644 (file)
@@ -2,7 +2,7 @@
 use warnings;
 use strict;
 
-use Test::More tests => 49;
+use Test::More tests => 52;
 use Test::Exception;
 use FindBin;
 use lib "$FindBin::Bin/lib";
@@ -16,7 +16,7 @@ use lib "$FindBin::Bin/lib";
     );
     use DecoratorLibrary qw(
         MyArrayRefBase MyArrayRefInt01 MyArrayRefInt02 StrOrArrayRef
-        AtLeastOneInt Jobs
+        AtLeastOneInt Jobs SubOfMyArrayRefInt01
     );
     
     has 'arrayrefbase' => (is=>'rw', isa=>MyArrayRefBase, coerce=>1);
@@ -29,6 +29,7 @@ use lib "$FindBin::Bin/lib";
     has 'deep' => (is=>'rw', isa=>ArrayRef[ArrayRef[HashRef[Int]]] );
     has 'deep2' => (is=>'rw', isa=>ArrayRef[Int|ArrayRef[HashRef[Int|Object]]] );
     has 'enum' => (is=>'rw', isa=>Jobs);
+    has 'SubOfMyArrayRefInt01_attr' => (is=>'rw', isa=>SubOfMyArrayRefInt01);
 }
 
 ## Make sure we have a 'create object sanity check'
@@ -213,3 +214,15 @@ ok $type->enum('Programming')
 throws_ok sub {
     $type->enum('ddddd');
 }, qr/Attribute \(enum\) does not pass the type constraint/ => 'Enum properly fails';
+
+## Test SubOfMyArrayRefInt01_attr
+
+ok $type->SubOfMyArrayRefInt01_attr([15,20,25])
+ => 'Assigned SubOfMyArrayRefInt01_attr to [15,20,25]';
+
+is_deeply $type->SubOfMyArrayRefInt01_attr, [15,20,25],
+ => 'Assignment is correct';
+throws_ok sub {
+    $type->SubOfMyArrayRefInt01_attr([15,5,20]);
+}, qr/Attribute \(SubOfMyArrayRefInt01_attr\) does not pass the type constraint/ => 'SubOfMyArrayRefInt01 Constraints properly fail';
\ No newline at end of file
index 0aef0cd..8361866 100644 (file)
@@ -11,6 +11,8 @@ use MooseX::Types
         StrOrArrayRef
         AtLeastOneInt
         Jobs
+        SubOfMyArrayRefInt01
+        BiggerInt
     )];
 
 subtype MyArrayRefBase,
@@ -23,6 +25,27 @@ coerce MyArrayRefBase,
 subtype MyArrayRefInt01,
     as ArrayRef[Int];
 
+subtype BiggerInt,
+    as Int,
+    where {$_>10};
+
+## We can change this when the .61 Moose comes out.  When that happens we will
+## have the correct patch to Moose::Meta::TypeConstraint::Parameterized to let
+## us support parameterizing parameterized subtypes.  When we get this we can
+## then replace the where clause with:
+
+    ##as MyArrayRefInt01[BiggerInt];
+
+subtype SubOfMyArrayRefInt01,
+    as MyArrayRefInt01,
+    where {
+        my $ok_or_not = 1;
+        foreach my $int (@$_) {
+            $ok_or_not = $int>10 ? 1:0
+             if $ok_or_not;
+        } $ok_or_not;
+    };
+
 coerce MyArrayRefInt01,
     from Str,
     via {[split('\.',$_)]},