X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FDispatchType%2FChained.pm;h=b74c29d88edeb298ec7e7344ee6e783c33412d16;hb=e459bd036c9076bd7301ea2fbdd5d4ba9900ddf0;hp=b9d6d07a07a102d32b4e9c2a3585ab13948cdc47;hpb=130b45ec858db6863e3d6959f7a6e3b6908cd48e;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index b9d6d07..b74c29d 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -247,6 +247,8 @@ sub recurse_match { } my @try_actions = @{$children->{$try_part}}; TRY_ACTION: foreach my $action (@try_actions) { + + if (my $capture_attr = $action->attributes->{CaptureArgs}) { my $capture_count = $action->number_of_captures|| 0; @@ -290,6 +292,7 @@ sub recurse_match { next TRY_ACTION unless $action->match($c); } my $args_attr = $action->attributes->{Args}->[0]; + my $args_count = $action->normalized_arg_number; my @pathparts = split /\//, $action->attributes->{PathPart}->[0]; # No best action currently # OR This one matches with fewer parts left than the current best action, @@ -297,7 +300,6 @@ sub recurse_match { # OR No parts and this expects 0 # The current best action might also be Args(0), # but we couldn't chose between then anyway so we'll take the last seen - if ( !$best_action || @parts < @{$best_action->{parts}} || @@ -305,12 +307,12 @@ sub recurse_match { !@parts && defined($args_attr) && ( - $args_attr eq "0" && + $args_count eq "0" && ( ($c->config->{use_chained_args_0_special_case}||0) || ( - exists($best_action->{args_attr}) && defined($best_action->{args_attr}) ? - ($best_action->{args_attr} ne 0) : 1 + exists($best_action->{args_count}) && defined($best_action->{args_count}) ? + ($best_action->{args_count} ne 0) : 1 ) ) ) @@ -320,7 +322,7 @@ sub recurse_match { actions => [ $action ], captures=> [], parts => \@parts, - args_attr => $args_attr, + args_count => $args_count, n_pathparts => scalar(@pathparts), }; } @@ -727,6 +729,10 @@ custom type constraints and import them into the controller namespace: sub int_priority_chain :Chained(chain_base) PathPart('') Args(Int) { } +If you use a reference type constraint in CaptureArgs, it must be a type +like Tuple in L that allows us to determine the number of +args to match. Otherwise this will raise an error during startup. + See L for more. =item Args @@ -747,6 +753,9 @@ Just as with C<:CaptureArgs>, the arguments get passed to the action in C<@_> after the context object. They can also be reached through C<$c-Erequest-Earguments>. +You should see 'Args' in L for more details on using +type constraints in your Args declarations. + =back =head2 Auto actions, dispatching and forwarding