1 package Catalyst::ActionChain;
4 extends qw(Catalyst::Action);
6 has chain => (is => 'rw');
11 Catalyst::ActionChain - Chain of Catalyst Actions
15 See L<Catalyst::Manual::Intro> for more info about Chained actions.
19 This class represents a chain of Catalyst Actions. It behaves exactly like
20 the action at the *end* of the chain except on dispatch it will execute all
21 the actions in the chain in order.
26 my ( $self, $c ) = @_;
27 my @captures = @{$c->req->captures||[]};
28 my @chain = @{ $self->chain };
29 my $last = pop(@chain);
30 foreach my $action ( @chain ) {
32 if (my $cap = $action->number_of_captures) {
33 @args = splice(@captures, 0, $cap);
35 local $c->request->{arguments} = \@args;
36 $action->dispatch( $c );
38 # break the chain if exception occurs in the middle of chain
39 return if (@{$c->error} && $c->config->{abort_chain_on_error_fix});
41 $last->dispatch( $c );
45 my ( $self, $actions ) = @_;
46 my $final = $actions->[-1];
47 return $self->new({ %$final, chain => $actions });
50 sub number_of_captures {
52 my $chain = $self->chain;
55 $captures += $_->number_of_captures for @$chain;
59 __PACKAGE__->meta->make_immutable;
68 Accessor for the action chain; will be an arrayref of the Catalyst::Action
69 objects encapsulated by this chain.
73 Dispatch this action chain against a context; will dispatch the encapsulated
76 =head2 from_chain( \@actions )
78 Takes a list of Catalyst::Action objects and constructs and returns a
79 Catalyst::ActionChain object representing a chain of these actions
81 =head2 number_of_captures
83 Returns the total number of captures for the entire chain of actions.
91 Catalyst Contributors, see Catalyst.pm
95 This library is free software. You can redistribute it and/or modify it under
96 the same terms as Perl itself.