comment out coerce stuff for now
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Action.pm
index ca4996a..37582e5 100644 (file)
@@ -59,7 +59,7 @@ has number_of_args => (
       scalar(@{$self->attributes->{Args}}) == 1 &&
       looks_like_number($self->attributes->{Args}[0])
     ) {
-      # 'Old school' numberd args (is allowed to be undef as well)
+      # 'Old school' numbered args (is allowed to be undef as well)
       return $self->attributes->{Args}[0];
     } else {
       # New hotness named arg constraints
@@ -100,13 +100,19 @@ has args_constraints => (
       return \@args;
     } else {
       @args =
-        map { Moose::Util::TypeConstraints::find_or_parse_type_constraint($_) || die "$_ is not a constraint!" } 
+        map {  $self->resolve_type_constraint($_) || die "$_ is not a constraint!" }
         @arg_protos;
     }
 
     return \@args;
   }
 
+sub resolve_type_constraint {
+  my ($self, $name) = @_;
+  my $tc = eval "package ${\$self->class}; $name" || undef;
+  return $tc || Moose::Util::TypeConstraints::find_or_parse_type_constraint($name);
+}
+
 use overload (
 
     # Stringify to reverse for debug output etc.
@@ -145,11 +151,20 @@ sub match {
       # That means we expect a reference, so use the full args arrayref.
       if(
         $self->number_of_args_constraints == 1 &&
-        $self->args_constraints->[0]->is_a_type_of('Ref')
+        (
+          $self->args_constraints->[0]->is_a_type_of('Ref') ||
+          $self->args_constraints->[0]->is_a_type_of('ClassName')
+        )
       ) {
-        return $self->args_constraints->[0]->check($c->req->args);
+        return 1 if $self->args_constraints->[0]->check($c->req->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;
+        #  $c->req->args([$coerced]);
+        #  return 1;
+        #}
       } else {
-        for my $i($#{ $c->req->args }) {
+        for my $i(0..$#{ $c->req->args }) {
           $self->args_constraints->[$i]->check($c->req->args->[$i]) || return 0;
         }
         return 1;
@@ -232,6 +247,9 @@ 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 resolve_type_constraint
+
+Trys to find a type constraint if you have on on a type constrained method.
 
 =head2 compare