From: Matt S Trout Date: Mon, 24 Oct 2005 00:46:47 +0000 (+0000) Subject: - Fixed Index, cleaned up get_action X-Git-Tag: 5.7099_04~1116 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=772ab8ae1affcaed555bfdb070e18ed1af592b71 - Fixed Index, cleaned up get_action --- diff --git a/lib/Catalyst/DispatchType/Index.pm b/lib/Catalyst/DispatchType/Index.pm index 9057de1..e0203e6 100644 --- a/lib/Catalyst/DispatchType/Index.pm +++ b/lib/Catalyst/DispatchType/Index.pm @@ -24,7 +24,7 @@ See L. sub match { my ( $self, $c, $path ) = @_; return if @{ $c->req->args }; - my $result = @{ $c->get_action( 'index', $c->req->path ) || [] }[-1]; + my $result = @{ $c->get_action( 'index', $path ) || [] }[-1]; # Find default on namespace or super if ($result) { diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 0fe6c32..66e8721 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -254,29 +254,31 @@ sub get_action { my ( $self, $c, $action, $namespace, $inherit ) = @_; return [] unless $action; $namespace ||= ''; - $inherit ||= 0; + $namespace = '' if $namespace eq '/'; + $inherit ||= 0; my @match = $self->get_containers($namespace); - my @results; - - foreach my $child ( $inherit ? @match : $match[-1] ) { - my $node = $child->actions; - if ( defined $node->{$action} ) { - unless ($inherit) { - $namespace = '' if $namespace eq '/'; - my $reverse = $node->{$action}->reverse; - my $name = $namespace - ? $namespace =~ /\/$/ - ? "$namespace$action" - : "$namespace/$action" - : $action; - last unless $name eq $reverse; - } - push( @results, [ $node->{$action} ] ); + if ($inherit) { # Return [ [ $act_obj ], ... ] for valid containers + return [ + map { [ $_->{$action} ] } # Make [ $action_obj ] + grep { defined $_->{$action} } # If it exists in the container + map { $_->actions } # Get action hash for container + @match + ]; + } + else { + my $node = $match[-1]->actions; # Only bother looking at the last one + + if ( defined $node->{$action} + && ( $node->{$action}->prefix eq $namespace ) ) + { + return [ [ $node->{$action} ] ]; + } + else { + return []; } } - return \@results; } =item $self->get_containers( $namespace )