test case and proposed fix
John Napiorkowski [Thu, 15 Dec 2016 01:52:56 +0000 (19:52 -0600)]
lib/Catalyst/Dispatcher.pm
t/relative_root_action_for_bug.t [new file with mode: 0644]

index c51510e..3ed3267 100644 (file)
@@ -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 (file)
index 0000000..9443052
--- /dev/null
@@ -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);
+