Display unattached chained actions under -Debug.
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Chained.pm
index cde26e1..a27f6ba 100644 (file)
@@ -71,6 +71,11 @@ sub list {
                     [ 35, 'Path Spec' ], [ 36, 'Private' ]
                 );
 
+    my $has_unattached_actions;
+    my $unattached_actions = Text::SimpleTable->new(
+        [ 35, 'Private' ], [ 36, 'Missing parent' ],
+    );
+
     ENDPOINT: foreach my $endpoint (
                   sort { $a->reverse cmp $b->reverse }
                            @{ $self->_endpoints }
@@ -92,7 +97,11 @@ sub list {
             $curr = $self->_actions->{$parent};
             unshift(@parents, $curr) if $curr;
         }
-        next ENDPOINT unless $parent eq '/'; # skip dangling action
+        if ($parent ne '/') {
+            $has_unattached_actions = 1;
+            $unattached_actions->row('/'.$parents[0]->reverse, $parent);
+            next ENDPOINT;
+        }
         my @rows;
         foreach my $p (@parents) {
             my $name = "/${p}";
@@ -110,6 +119,8 @@ sub list {
     }
 
     $c->log->debug( "Loaded Chained actions:\n" . $paths->draw . "\n" );
+    $c->log->debug( "Unattached Chained actions:\n", $unattached_actions->draw . "\n" )
+        if $has_unattached_actions;
 }
 
 =head2 $self->match( $c, $path )
@@ -246,7 +257,7 @@ sub register {
         );
     }
 
-    my $children = ($self->{children_of}{ $chained_attr[0] } ||= {});
+    my $children = ($self->_children_of->{ $chained_attr[0] } ||= {});
 
     my @path_part = @{ $action->attributes->{PathPart} || [] };
 
@@ -319,6 +330,23 @@ sub uri_for_action {
    
 }
 
+sub expand_action {
+    my ($self, $action) = @_;
+
+    return unless $action->attributes && $action->attributes->{Chained};
+
+    my @chain;
+    my $curr = $action;
+
+    while ($curr) {
+        push @chain, $curr;
+        my $parent = $curr->attributes->{Chained}->[0];
+        $curr = $self->_actions->{$parent};
+    }
+
+    return Catalyst::ActionChain->from_chain([reverse @chain]);
+}
+
 __PACKAGE__->meta->make_immutable;
 
 =head1 USAGE
@@ -496,13 +524,18 @@ with C<sub bar :PathPart('foo/bar') :Chained('/')> would bind to
 C</foo/bar/...>. If you don't specify C<:PathPart> it has the same
 effect as using C<:PathPart>, it would default to the action name.
 
+=item PathPrefix
+
+Sets PathPart to the path_prefix of the current controller.
+
 =item Chained
 
 Has to be specified for every child in the chain. Possible values are
-absolute and relative private action paths, with the relatives pointing
-to the current controller, or a single slash C</> to tell Catalyst that
-this is the root of a chain. The attribute C<:Chained> without arguments
-also defaults to the C</> behavior.
+absolute and relative private action paths or a single slash C</> to
+tell Catalyst that this is the root of a chain. The attribute
+C<:Chained> without arguments also defaults to the C</> behavior.
+Relative action paths may use C<../> to refer to actions in parent
+controllers.
 
 Because you can specify an absolute path to the parent action, it
 doesn't matter to Catalyst where that parent is located. So, if your
@@ -525,6 +558,19 @@ with the path of the current controller namespace, namely
 C</foo/bar>. That action chains directly to C</>, so the C</bar/*/baz/*>
 chain comes out as the end product.
 
+=item ChainedParent
+
+Chains an action to another action with the same name in the parent
+controller. For Example:
+
+  # in MyApp::Controller::Foo
+  sub bar : Chained CaptureArgs(1) { ... }
+
+  # in MyApp::Controller::Foo::Moo
+  sub bar : ChainedParent Args(1) { ... }
+
+This builds a chain like C</bar/*/bar/*>.
+
 =item CaptureArgs
 
 Must be specified for every part of the chain that is not an