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 $last->dispatch( $c );
42 my ( $self, $actions ) = @_;
43 my $final = $actions->[-1];
44 return $self->new({ %$final, chain => $actions });
47 sub number_of_captures {
49 my $chain = $self->chain;
52 $captures += $_->number_of_captures for @$chain;
56 __PACKAGE__->meta->make_immutable;
65 Accessor for the action chain; will be an arrayref of the Catalyst::Action
66 objects encapsulated by this chain.
70 Dispatch this action chain against a context; will dispatch the encapsulated
73 =head2 from_chain( \@actions )
75 Takes a list of Catalyst::Action objects and constructs and returns a
76 Catalyst::ActionChain object representing a chain of these actions
78 =head2 number_of_captures
80 Returns the total number of captures for the entire chain of actions.
88 Catalyst Contributors, see Catalyst.pm
92 This library is free software. You can redistribute it and/or modify it under
93 the same terms as Perl itself.