document $c->detach with no args
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Chained.pm
index f7af2b2..10342b9 100644 (file)
@@ -192,7 +192,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 +248,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 +257,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};