From: John Napiorkowski Date: Thu, 15 Dec 2016 01:52:56 +0000 (-0600) Subject: test case and proposed fix X-Git-Tag: 5.90113~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=518b61984c49533ec00813125b16812cd681e778 test case and proposed fix --- diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index c51510e..3ed3267 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -419,7 +419,7 @@ sub get_action { $namespace = join( "/", grep { length } split '/', ( defined $namespace ? $namespace : "" ) ); - return $self->_action_hash->{"${namespace}/${name}"}; + return $self->get_action_by_path("${namespace}/${name}"); } =head2 $self->get_action_by_path( $path ); diff --git a/t/relative_root_action_for_bug.t b/t/relative_root_action_for_bug.t new file mode 100644 index 0000000..9443052 --- /dev/null +++ b/t/relative_root_action_for_bug.t @@ -0,0 +1,85 @@ +use Test::Most; + +{ + package MyApp::Controller::Root; + $INC{'MyApp/Controller/Root.pm'} = __FILE__; + + use Moose; + use MooseX::MethodAttributes; + + extends 'Catalyst::Controller'; + + sub root :Chained(/) PathPart('') CaptureArgs(0) { + my ($self, $c) = @_; + } + + sub top :Chained('root') Args(0) { + my ($self, $c) = @_; + Test::Most::is $self->action_for('top'), 'top'; + Test::Most::is $self->action_for('story/story'), 'story/story'; + + #warn ref($c)->dispatcher->get_action('story/story', '/root'); + + #use Devel::Dwarn; + #Dwarn ref($c)->dispatcher->_action_hash->{'story/story'}; + } + + MyApp::Controller::Root->config(namespace=>''); + + package MyApp::Controller::Story; + $INC{'MyApp/Controller/Story.pm'} = __FILE__; + + use Moose; + use MooseX::MethodAttributes; + + extends 'Catalyst::Controller'; + + sub root :Chained(/root) PathPart('') CaptureArgs(0) { + my ($self, $c) = @_; + } + + sub story :Chained(root) Args(0) { + my ($self, $c) = @_; + + Test::Most::is $self->action_for('story'), 'story/story'; + Test::Most::is $self->action_for('author/author'), 'story/author/author'; + } + + __PACKAGE__->meta->make_immutable; + + package MyApp::Controller::Story::Author; + $INC{'MyApp/Controller/Story/Author.pm'} = __FILE__; + + use Moose; + use MooseX::MethodAttributes; + + extends 'Catalyst::Controller'; + + sub root :Chained(/story/root) PathPart('') CaptureArgs(0) { + my ($self, $c) = @_; + } + + sub author :Chained(root) Args(0) { + my ($self, $c, $id) = @_; + Test::Most::is $self->action_for('author'), 'story/author/author'; + } + + + __PACKAGE__->meta->make_immutable; + + package MyApp; + $INC{'MyApp.pm'} = __FILE__; + + use Catalyst; + + MyApp->setup; +} + +use Catalyst::Test 'MyApp'; + +ok request '/story'; +ok request '/author'; +ok request '/top'; + +done_testing(8); +