From: Matt S Trout Date: Thu, 22 Jun 2006 14:51:53 +0000 (+0000) Subject: Captures required, Args not X-Git-Tag: 5.7099_04~491 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=7a7ac23cbfaba1c66a454132313ceb7e885ab98b Captures required, Args not r10065@cain (orig r4396): matthewt | 2006-06-17 20:25:07 +0000 --- diff --git a/lib/Catalyst/DispatchType/ChildOf.pm b/lib/Catalyst/DispatchType/ChildOf.pm index 9b58d85..f54e322 100644 --- a/lib/Catalyst/DispatchType/ChildOf.pm +++ b/lib/Catalyst/DispatchType/ChildOf.pm @@ -127,21 +127,13 @@ sub recurse_match { } my @try_actions = @{$children->{$try_part}}; TRY_ACTION: foreach my $action (@try_actions) { - if (my $args_attr = $action->attributes->{Args}) { - # XXX alternative non-Args way to identify an endpoint? - { - local $c->req->{arguments} = [ @{$c->req->args}, @parts ]; - next TRY_ACTION unless $action->match($c); - } - push(@{$c->req->args}, @parts); - return [ $action ], [ ]; - } else { + if (my $capture_attr = $action->attributes->{Captures}) { my @captures; my @parts = @parts; # localise - if (my $capture_attr = $action->attributes->{Captures}) { - # strip Captures into list - push(@captures, splice(@parts, 0, $capture_attr->[0])); - } + + # strip Captures into list + push(@captures, splice(@parts, 0, $capture_attr->[0])); + # try the remaining parts against children of this action my ($actions, $captures) = $self->recurse_match( $c, '/'.$action->reverse, \@parts @@ -149,6 +141,13 @@ sub recurse_match { if ($actions) { return [ $action, @$actions ], [ @captures, @$captures ]; } + } else { + { + local $c->req->{arguments} = [ @{$c->req->args}, @parts ]; + next TRY_ACTION unless $action->match($c); + } + push(@{$c->req->args}, @parts); + return [ $action ], [ ]; } } } @@ -206,7 +205,7 @@ sub register { ($self->{actions} ||= {})->{'/'.$action->reverse} = $action; - if ($action->attributes->{Args}) { + unless ($action->attributes->{Captures}) { unshift(@{ $self->{endpoints} ||= [] }, $action); } diff --git a/t/lib/TestApp/Controller/Action/ChildOf.pm b/t/lib/TestApp/Controller/Action/ChildOf.pm index 5f91d88..a244a98 100644 --- a/t/lib/TestApp/Controller/Action/ChildOf.pm +++ b/t/lib/TestApp/Controller/Action/ChildOf.pm @@ -22,7 +22,7 @@ sub endpoint2 :PathPart('end2') :ChildOf('/action/childof/foo2') :Args(2) { } # # Relative specification of parent action # -sub bar :PathPart('childof/bar') :ChildOf('/') { } +sub bar :PathPart('childof/bar') :ChildOf('/') :Captures(0) { } sub finale :ChildOf('bar') :Args { } #