changed code in anticipation of the new parameterize stuff in Moose/trunk, changed...
John Napiorkowski [Sat, 13 Sep 2008 02:05:37 +0000 (02:05 +0000)]
lib/MooseX/Types.pm
t/13_typedecorator.t

index c0f575b..364faa2 100644 (file)
@@ -377,11 +377,6 @@ sub type_export_generator {
          
         return $class->create_type_decorator($type_constraint);
         
-        #if(@_ && wantarray) {
-        #    return ($class->create_type_decorator($type_constraint), @_);  
-        #} else {
-        #    return $class->create_type_decorator($type_constraint);
-        #}
     };
 }
 
@@ -393,13 +388,8 @@ Given a String $name with @args find the matching typeconstraint.
 
 sub create_arged_type_constraint {
     my ($class, $name, @args) = @_;
-    ### This whole section is a real TODO :)  Ugly hack to get the base tests working.
-    my $fullname = $name."[$args[0]]";
-    
-    #use Data::Dump qw/dump/;
-    #my $tc = Moose::Util::TypeConstraints::find_or_create_type_constraint($name);
-    return Moose::Util::TypeConstraints::create_parameterized_type_constraint($fullname);
+    my $type_constraint = Moose::Util::TypeConstraints::find_or_create_type_constraint($name);
+       return $type_constraint->parameterize(@args)
 }
 
 =head2 create_base_type_constraint ($name)
index 89cc3a2..cf82377 100644 (file)
@@ -2,7 +2,7 @@
 use warnings;
 use strict;
 
-use Test::More tests => 39;
+use Test::More tests => 47;
 use Test::Exception;
 use FindBin;
 use lib "$FindBin::Bin/lib";
@@ -12,7 +12,7 @@ use lib "$FindBin::Bin/lib";
     
     use Moose;
     use MooseX::Types::Moose qw(
-        Int Str ArrayRef HashRef
+        Int Str ArrayRef HashRef Object
     );
     use DecoratorLibrary qw(
         MyArrayRefBase MyArrayRefInt01 MyArrayRefInt02 StrOrArrayRef
@@ -25,11 +25,9 @@ use lib "$FindBin::Bin/lib";
     has 'arrayrefint03' => (is=>'rw', isa=>MyArrayRefBase[Int]);
     has 'StrOrArrayRef' => (is=>'rw', isa=>StrOrArrayRef);
     has 'AtLeastOneInt' => (is=>'rw', isa=>AtLeastOneInt);
-    has 'pipeoverloading' => (is=>'rw', isa=>Int|Str);
-    #has 'deep' => (is=>'rw', isa=>ArrayRef([ArrayRef([HashRef([Int])])]));
-    
+    has 'pipeoverloading' => (is=>'rw', isa=>Int|Str);   
     has 'deep' => (is=>'rw', isa=>ArrayRef[ArrayRef[HashRef[Int]]] );
-    
+    has 'deep2' => (is=>'rw', isa=>ArrayRef[Int|ArrayRef[HashRef[Int|Object]]] );
 }
 
 ## Make sure we have a 'create object sanity check'
@@ -160,9 +158,9 @@ ok $type->pipeoverloading('a')
 
 throws_ok sub {
     $type->pipeoverloading({a=>1,b=>2});
-}, qr/Validation failed for 'Int | Str'/ => 'Union test corrected fails a HashRef';
+}, qr/Validation failed for 'Int|Str'/ => 'Union test corrected fails a HashRef';
 
-## test deep
+## test deep (ArrayRef[ArrayRef[HashRef[Int]]])
 
 ok $type->deep([[{a=>1,b=>2},{c=>3,d=>4}],[{e=>5}]])
  => 'Assigned deep to [[{a=>1,b=>2},{c=>3,d=>4}],[{e=>5}]]';
@@ -172,4 +170,35 @@ is_deeply $type->deep, [[{a=>1,b=>2},{c=>3,d=>4}],[{e=>5}]],
  
 throws_ok sub {
     $type->deep({a=>1,b=>2});
-}, qr/Attribute \(deep\) does not pass the type constraint/ => 'Deep Constraints properly fail';
\ No newline at end of file
+}, qr/Attribute \(deep\) does not pass the type constraint/ => 'Deep Constraints properly fail';
+
+# test deep2 (ArrayRef[Int|ArrayRef[HashRef[Int|Object]]])
+
+ok $type->deep2([[{a=>1,b=>2},{c=>3,d=>4}],[{e=>5}]])
+ => 'Assigned deep to [[{a=>1,b=>2},{c=>3,d=>4}],[{e=>5}]]';
+
+is_deeply $type->deep2, [[{a=>1,b=>2},{c=>3,d=>4}],[{e=>5}]],
+ => 'Assignment is correct';
+throws_ok sub {
+    $type->deep2({a=>1,b=>2});
+}, qr/Attribute \(deep2\) does not pass the type constraint/ => 'Deep Constraints properly fail';
+
+throws_ok sub {
+    $type->deep2([[{a=>1,b=>2},{c=>3,d=>'noway'}],[{e=>5}]]);
+}, qr/Attribute \(deep2\) does not pass the type constraint/ => 'Deep Constraints properly fail';
+
+
+ok $type->deep2([[{a=>1,b=>2},{c=>3,d=>$type}],[{e=>5}]])
+ => 'Assigned deep to [[{a=>1,b=>2},{c=>3,d=>4}],[{e=>5}]]';
+
+
+is_deeply $type->deep2, [[{a=>1,b=>2},{c=>3,d=>$type}],[{e=>5}]],
+ => 'Assignment is correct';
+ok $type->deep2([1,2,3])
+ => 'Assigned deep to [1,2,3]';
+
+
+is_deeply $type->deep2, [1,2,3],
+ => 'Assignment is correct';