make it less easy to want moose stringy types
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Action.pm
index 5ee38e9..b5e75d4 100644 (file)
@@ -92,6 +92,7 @@ has number_of_args_constraints => (
         } else {
           # Its a Reftype but we don't know the number of params it
           # actually validates.
+          warn "Your type constraint '$tc' is a reference type but I cannot determine its number of parameters in action ${\$self->private_path}";
           return undef;
         }
       } else {
@@ -211,8 +212,11 @@ has captures_constraints => (
 sub resolve_type_constraint {
   my ($self, $name) = @_;
   my @tc = eval "package ${\$self->class}; $name";
-  return @tc if $tc[0];
-  return Moose::Util::TypeConstraints::find_or_parse_type_constraint($name);
+  if($tc[0]) {
+    return map { ref($_) ? $_ : Moose::Util::TypeConstraints::find_or_parse_type_constraint($_) } @tc;
+  } else {
+    return;
+  }
 }
 
 has number_of_captures => (
@@ -271,8 +275,12 @@ sub execute {
 
 sub match {
     my ( $self, $c ) = @_;
+    return $self->match_args($c, $c->req->args);
+}
 
-    warn $self->reverse;
+sub match_args {
+    my ($self, $c, $args) = @_;
+    my @args = @{$args||[]};
 
     # If infinite args, we always match
     return 1 if $self->normalized_arg_number == ~0;
@@ -289,7 +297,7 @@ sub match {
           $self->args_constraints->[0]->is_a_type_of('ClassName')
         )
       ) {
-        return $self->args_constraints->[0]->check($c->req->args);
+        return $self->args_constraints->[0]->check($args);
         # Removing coercion stuff for the first go
         #if($self->args_constraints->[0]->coercion && $self->attributes->{Coerce}) {
         #  my $coerced = $self->args_constraints->[0]->coerce($c) || return 0;
@@ -299,16 +307,16 @@ sub match {
       } else {
         # Because of the way chaining works, we can expect args that are totally not
         # what you'd expect length wise.  When they don't match length, thats a fail
-        return 0 unless scalar( @{ $c->req->args } ) == $self->normalized_arg_number;
+        return 0 unless scalar( @args ) == $self->normalized_arg_number;
 
-        for my $i(0..$#{ $c->req->args }) {
-          $self->args_constraints->[$i]->check($c->req->args->[$i]) || return 0;
+        for my $i(0..$#args) {
+          $self->args_constraints->[$i]->check($args[$i]) || return 0;
         }
         return 1;
       }
     } else {
       # Otherwise, we just need to match the number of args.
-      return scalar( @{ $c->req->args } ) == $self->normalized_arg_number;
+      return scalar( @args ) == $self->normalized_arg_number;
     }
 }
 
@@ -402,6 +410,10 @@ of the captures for this action.
 Returning true from this method causes the chain match to continue, returning
 makes the chain not match (and alternate, less preferred chains will be attempted).
 
+=head2 match_args($c, $args)
+
+Does the Args match or not?
+
 =head2 resolve_type_constraint
 
 Trys to find a type constraint if you have on on a type constrained method.