1 package Catalyst::ActionChain;
4 use base qw/Catalyst::Action/;
9 Catalyst::ActionChain - Chain of Catalyst Actions
13 See L<Catalyst::Manual::Intro> for more info about Chained actions.
17 This class represents a chain of Catalyst Actions. It behaves exactly like
18 the action at the *end* of the chain except on dispatch it will execute all
19 the actions in the chain in order.
23 __PACKAGE__->mk_accessors(qw/chain/);
27 # Stringify to reverse for debug output etc.
28 q{""} => sub { shift->{reverse} },
30 # Codulate to execute to invoke the encapsulated action coderef
31 '&{}' => sub { my $self = shift; sub { $self->execute(@_); }; },
33 # Make general $stuff still work
40 my ( $self, $c ) = @_;
41 my @captures = @{$c->req->captures||[]};
42 my @chain = @{ $self->chain };
43 my $last = pop(@chain);
44 foreach my $action ( @chain ) {
46 if (my $cap = $action->attributes->{CaptureArgs}) {
47 @args = splice(@captures, 0, $cap->[0]);
49 local $c->request->{arguments} = \@args;
50 $action->dispatch( $c );
52 $last->dispatch( $c );
56 my ( $self, $actions ) = @_;
57 my $final = $actions->[-1];
58 return $self->new({ %$final, chain => $actions });
69 Accessor for the action chain; will be an arrayref of the Catalyst::Action
70 objects encapsulated by this chain.
74 Dispatch this action chain against a context; will dispatch the encapsulated
77 =head2 from_chain( \@actions )
79 Takes a list of Catalyst::Action objects and constructs and returns a
80 Catalyst::ActionChain object representing a chain of these actions
84 Catalyst Contributors, see Catalyst.pm
88 This program is free software, you can redistribute it and/or modify it under
89 the same terms as Perl itself.