Make go('/chained/action') execute the full chain, not just the endpoint.
Florian Ragwitz [Fri, 5 Sep 2008 15:50:16 +0000 (15:50 +0000)]
lib/Catalyst/DispatchType.pm
lib/Catalyst/DispatchType/Chained.pm
lib/Catalyst/Dispatcher.pm

index 31b980c..06905ad 100644 (file)
@@ -58,6 +58,8 @@ arrayref, or undef if unable to do so.
 
 sub uri_for_action { }
 
+sub expand_action { }
+
 =head1 AUTHORS
 
 Catalyst Contributors, see Catalyst.pm
index 399a378..a7d08a3 100644 (file)
@@ -319,6 +319,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
index b4e3dc2..91ae6fc 100644 (file)
@@ -178,6 +178,8 @@ sub go {
         return 0;
     }
 
+    $action = $self->expand_action($action);
+
     local $c->request->{arguments} = $args;
     $c->namespace($action->namespace);
     $c->action($action);
@@ -421,6 +423,17 @@ sub uri_for_action {
     return undef;
 }
 
+sub expand_action {
+    my ($self, $action) = @_;
+
+    foreach my $dispatch_type (@{ $self->_dispatch_types }) {
+        my $expanded = $dispatch_type->expand_action($action);
+        return $expanded if $expanded;
+    }
+
+    return $action;
+}
+
 =head2 $self->register( $c, $action )
 
 Make sure all required dispatch types for this action are loaded, then