X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FDispatchType%2FChained.pm;h=3b7b0c4cd66a4061372b97a6723f30ad74d5b6ba;hp=9c32258debeef9b423f0a73ae6f3f156ea5458e0;hb=d0a02856666b38a92f5905e86e11fd053dff91bd;hpb=9d286ef65c75378a7dc46a6ddbe1c7fe445890db diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index 9c32258..3b7b0c4 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -201,9 +201,10 @@ sub recurse_match { my @try_actions = @{$children->{$try_part}}; TRY_ACTION: foreach my $action (@try_actions) { if (my $capture_attr = $action->attributes->{CaptureArgs}) { + $capture_attr ||= 0; # Short-circuit if not enough remaining parts - next TRY_ACTION unless @parts >= ($capture_attr->[0]||0); + next TRY_ACTION unless @parts >= $capture_attr->[0]; my @captures; my @parts = @parts; # localise @@ -211,6 +212,9 @@ sub recurse_match { # strip CaptureArgs into list push(@captures, splice(@parts, 0, $capture_attr->[0])); + # check if the action may fit, depending on a given test by the app + if ($action->can('match_captures')) { next TRY_ACTION unless $action->match_captures($c, \@captures) } + # try the remaining parts against children of this action my ($actions, $captures, $action_parts, $n_pathparts) = $self->recurse_match( $c, '/'.$action->reverse, \@parts @@ -357,7 +361,7 @@ sub uri_for_action { my $curr = $action; while ($curr) { if (my $cap = $curr->attributes->{CaptureArgs}) { - return undef unless @captures >= $cap->[0]; # not enough captures + return undef unless @captures >= ($cap->[0]||0); # not enough captures if ($cap->[0]) { unshift(@parts, splice(@captures, -$cap->[0])); } @@ -404,6 +408,7 @@ sub expand_action { } __PACKAGE__->meta->make_immutable; +1; =head1 USAGE @@ -673,6 +678,13 @@ The Cing to other actions does just what you would expect. But if you C out of a chain, the rest of the chain will not get called after the C. +=head2 match_captures + +A method which can optionally be implemented by actions to +stop chain matching. + +See L for further details. + =head1 AUTHORS Catalyst Contributors, see Catalyst.pm