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=d55d22db8048e4568303238c04b83efc65416a26;hp=f7af2b2cd07ae179bc7ced885cff01fb910f9781;hb=f505df49a4707ce6962d8a9ebcf5280430a801cf;hpb=67869327e1bf1a4855724d732ce28c089340afe5 diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index f7af2b2..d55d22d 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -141,6 +141,10 @@ sub recurse_match { my @try_actions = @{$children->{$try_part}}; TRY_ACTION: foreach my $action (@try_actions) { if (my $capture_attr = $action->attributes->{CaptureArgs}) { + + # Short-circuit if not enough remaining parts + next TRY_ACTION unless @parts >= $capture_attr->[0]; + my @captures; my @parts = @parts; # localise @@ -192,7 +196,11 @@ sub register { if ($parent eq '.') { $parent = '/'.$action->namespace; } elsif ($parent !~ m/^\//) { - $parent = '/'.join('/', $action->namespace, $parent); + if ($action->namespace) { + $parent = '/'.join('/', $action->namespace, $parent); + } else { + $parent = '/'.$parent; # special case namespace '' (root) + } } } else { $parent = '/' @@ -244,7 +252,7 @@ sub uri_for_action { my ( $self, $action, $captures ) = @_; return undef unless ($action->attributes->{Chained} - && $action->attributes->{Args}); + && !$action->attributes->{CaptureArgs}); my @parts = (); my @captures = @$captures; @@ -253,11 +261,13 @@ sub uri_for_action { while ($curr) { if (my $cap = $curr->attributes->{CaptureArgs}) { return undef unless @captures >= $cap->[0]; # not enough captures - unshift(@parts, splice(@captures, -$cap->[0])); + if ($cap->[0]) { + unshift(@parts, splice(@captures, -$cap->[0])); + } } if (my $pp = $curr->attributes->{PartPath}) { unshift(@parts, $pp->[0]) - if (defined $pp->[0] && length $pp->[0]); + if (defined($pp->[0]) && length($pp->[0])); } $parent = $curr->attributes->{Chained}->[0]; $curr = $self->{actions}{$parent};