From: Florian Ragwitz Date: Fri, 5 Sep 2008 15:50:16 +0000 (+0000) Subject: Make go('/chained/action') execute the full chain, not just the endpoint. X-Git-Tag: 5.8000_03~71 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=52f71256fa6baba38de781b3074884ff0d12769f;hp=1faaa3e99565660c7e3cd433e01c80343828f8a8 Make go('/chained/action') execute the full chain, not just the endpoint. --- diff --git a/lib/Catalyst/DispatchType.pm b/lib/Catalyst/DispatchType.pm index 31b980c..06905ad 100644 --- a/lib/Catalyst/DispatchType.pm +++ b/lib/Catalyst/DispatchType.pm @@ -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 diff --git a/lib/Catalyst/DispatchType/Chained.pm b/lib/Catalyst/DispatchType/Chained.pm index 399a378..a7d08a3 100644 --- a/lib/Catalyst/DispatchType/Chained.pm +++ b/lib/Catalyst/DispatchType/Chained.pm @@ -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 diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index b4e3dc2..91ae6fc 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -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