[Moose-commits] r7825 - MooseX-Types-Structured/trunk/t

jnapiorkowski at code2.0beta.co.uk jnapiorkowski at code2.0beta.co.uk
Thu Mar 5 21:57:28 GMT 2009


Author: jnapiorkowski
Date: 2009-03-05 13:57:28 -0800 (Thu, 05 Mar 2009)
New Revision: 7825

Modified:
   MooseX-Types-Structured/trunk/t/11-overflow.t
Log:
created sugar method for merging, with examples

Modified: MooseX-Types-Structured/trunk/t/11-overflow.t
===================================================================
--- MooseX-Types-Structured/trunk/t/11-overflow.t	2009-03-05 21:07:45 UTC (rev 7824)
+++ MooseX-Types-Structured/trunk/t/11-overflow.t	2009-03-05 21:57:28 UTC (rev 7825)
@@ -8,14 +8,21 @@
 use MooseX::Types::Structured qw(Dict Tuple);
 use MooseX::Types::Moose qw(Int Str ArrayRef HashRef);
 
+
+sub merge(&$) {
+    my ($code, $tc) = @_;
+    return sub {
+        my @tail_args = @_;
+        $tc->check($code->(@tail_args));
+    }
+}
+
 my $array_tailed_tuple =
     subtype 'array_tailed_tuple',
      as Tuple[
         Int,
         Str,
-        sub {
-            (ArrayRef[Int])->check([@_]);
-        },
+        merge {[@_]} ArrayRef[Int],
      ];
   
 ok !$array_tailed_tuple->check(['ss',1]), 'correct fail';
@@ -29,9 +36,7 @@
      as Tuple[
        Int,
        Str,
-       sub {
-        (HashRef[Int])->check({@_});
-       },
+       merge {+{@_}} HashRef[Int],
      ];
 
 ok !$hash_tailed_tuple->check(['ss',1]), 'correct fail';
@@ -45,9 +50,7 @@
     as Dict[
       name=>Str,
       age=>Int,
-      sub {
-        (HashRef[Int])->check({@_});        
-      }
+       merge {+{@_}} HashRef[Int],
     ];
     
 ok !$hash_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail';
@@ -61,9 +64,7 @@
     as Dict[
       name=>Str,
       age=>Int,
-      sub {
-        (ArrayRef[Int])->check([@_]);       
-      }
+      merge {[@_]} ArrayRef[Int],
     ];
     
 ok !$array_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail';




More information about the Moose-commits mailing list