first pass at constraints on uri_for
[catagits/Catalyst-Runtime.git] / lib / Catalyst.pm
index 03acccc..576f0c4 100644 (file)
@@ -1491,20 +1491,36 @@ sub uri_for {
                          : ()) ];
 
         my $action = $path;
+        my $expanded_action = $c->dispatcher->expand_action( $action );
+         my $num_captures = $expanded_action->number_of_captures;
+
         # ->uri_for( $action, \@captures_and_args, \%query_values? )
         if( !@encoded_args && $action->number_of_args ) {
-            my $expanded_action = $c->dispatcher->expand_action( $action );
-            my $num_captures = $expanded_action->number_of_captures;
-            unshift @encoded_args, splice @$captures, $num_captures;
+          unshift @encoded_args, splice @$captures, $num_captures;
+        }
+
+        if($num_captures) {
+          unless($expanded_action->match_captures($c, $captures)) {
+            carp "captures [@{$captures}] do not match the type constraints in action '$action'";
+            return;
+          }
         }
 
-       $path = $c->dispatcher->uri_for_action($action, $captures);
+        $path = $c->dispatcher->uri_for_action($action, $captures);
         if (not defined $path) {
             $c->log->debug(qq/Can't find uri_for action '$action' @$captures/)
                 if $c->debug;
             return undef;
         }
         $path = '/' if $path eq '';
+
+        # At this point @encoded_args is the remaining Args (all captures removed).
+        if($expanded_action->has_args_constraints) {
+          unless($expanded_action->match_args($c,\@encoded_args)) {
+             carp "args [@encoded_args] do not match the type constraints in action '$expanded_action'";
+             return;
+          }
+        }
     }
 
     unshift(@encoded_args, $path);
@@ -1567,6 +1583,9 @@ sub uri_for {
       } @keys);
     }
 
+    #warn $base;
+    #warn $args;
+    
     my $res = bless(\"${base}${args}${query}", $class);
     $res;
 }