ugly proof of concept for parametrized types only
John Napiorkowski [Mon, 25 Aug 2008 14:41:39 +0000 (14:41 +0000)]
TODO
lib/MooseX/Types.pm
t/13_typedecorator.t
t/lib/DecoratorLibrary.pm

diff --git a/TODO b/TODO
index b261896..e66c97e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -7,6 +7,8 @@ Moose::TypeConstraint->create_base(%opt);
 Moose::TypeConstraint->create_structured(%opt, %signature_opts);
 Moose::TypeConstraint->create_parameterized(%opt, %);
 
+Or some sort of pattern for type constraints that accept args?
+
 then a ...->create(%opt) that chooses one of the above????
 
 
index f1dc7f5..5b64c50 100644 (file)
@@ -300,19 +300,21 @@ yet defined.
 
 =cut
 
+use Data::Dump qw/dump/;
+
 sub type_export_generator {
     my ($class, $type, $full) = @_;
     return sub {
-        my @args = @_;
-        #use Data::Dump qw/dump/; warn dump @args if @args;
+        ## todo, this needs to be some sort of ->process_args on the actual
+        ## containing type constraints.  This is ugly proof of concept
+        if(my $param = shift @_) {
+            #my @tc_args = map { find_type_constraint($full) } @args;
+            $full = $full .'['.  $param->[0]->name .']';
+        }
+        
         my $type_constraint = find_type_constraint($full)
          || MooseX::Types::UndefinedType->new($full);
-         
-        if(@args) {
-            my $tc = $args[0]->[0];
-           # warn dump $tc;
-           # $type_constraint->type_constraint($tc);
-        }
+
         return MooseX::Types::TypeDecorator->new(type_constraint=>$type_constraint);
     };
 }
index 79d95a1..396d616 100644 (file)
@@ -44,18 +44,24 @@ is_deeply $type->arrayrefbase, [qw(d e f)],
 
 ## test arrayrefint01 normal and coercion
 
-ok $type->arrayrefint01([qw(a b c)])
- => 'Assigned arrayrefbase qw(a b c)';
+ok $type->arrayrefint01([qw(1 2 3)])
+ => 'Assigned arrayrefbase qw(1 2 3)';
  
-is_deeply $type->arrayrefint01, [qw(a b c)],
+is_deeply $type->arrayrefint01, [qw(1 2 3)],
  => 'Assigment is correct';
 
-ok $type->arrayrefint01('d.e.f')
- => 'Assigned arrayrefbase d,e,f to test coercion';
+ok $type->arrayrefint01('4.5.6')
+ => 'Assigned arrayrefbase 4.5.6 to test coercion from Str';
  
-is_deeply $type->arrayrefint01, [qw(d e f)],
+is_deeply $type->arrayrefint01, [qw(4 5 6)],
  => 'Assigment and coercion is correct';
 
+ok $type->arrayrefint01({a=>7,b=>8})
+ => 'Assigned arrayrefbase {a=>7,b=>8} to test coercion from HashRef';
+is_deeply $type->arrayrefint01, [qw(7 8)],
+ => 'Assigment and coercion is correct';
 #use Data::Dump qw/dump/;
 #warn dump  MyArrayRefInt01;
 #warn dump MyArrayRefBase->validate('aaa,bbb,ccc');
index 7912331..ad3c6d2 100644 (file)
@@ -25,7 +25,7 @@ coerce MyArrayRefInt01,
     from Str,
     via {[split('\.',$_)]},
     from HashRef,
-    via {[values(%$_)]};
+    via {[sort values(%$_)]};
     
 subtype MyArrayRefInt02,
     as MyArrayRefBase[Int];