1 package Catalyst::ActionChain;
4 extends qw(Catalyst::Action);
6 has chain => (is => 'rw');
10 Catalyst::ActionChain - Chain of Catalyst Actions
14 See L<Catalyst::Manual::Intro> for more info about Chained actions.
18 This class represents a chain of Catalyst Actions. It behaves exactly like
19 the action at the *end* of the chain except on dispatch it will execute all
20 the actions in the chain in order.
26 # Stringify to reverse for debug output etc.
27 q{""} => sub { shift->{reverse} },
29 # Codulate to execute to invoke the encapsulated action coderef
30 '&{}' => sub { my $self = shift; sub { $self->execute(@_); }; },
32 # Make general $stuff still work
39 my ( $self, $c ) = @_;
40 my @captures = @{$c->req->captures||[]};
41 my @chain = @{ $self->chain };
42 my $last = pop(@chain);
43 foreach my $action ( @chain ) {
45 if (my $cap = $action->attributes->{CaptureArgs}) {
46 @args = splice(@captures, 0, $cap->[0]);
48 local $c->request->{arguments} = \@args;
49 $action->dispatch( $c );
51 $last->dispatch( $c );
55 my ( $self, $actions ) = @_;
56 my $final = $actions->[-1];
57 return $self->new({ %$final, chain => $actions });
61 __PACKAGE__->meta->make_immutable;
70 Accessor for the action chain; will be an arrayref of the Catalyst::Action
71 objects encapsulated by this chain.
75 Dispatch this action chain against a context; will dispatch the encapsulated
78 =head2 from_chain( \@actions )
80 Takes a list of Catalyst::Action objects and constructs and returns a
81 Catalyst::ActionChain object representing a chain of these actions
93 This program is free software, you can redistribute it and/or modify it under
94 the same terms as Perl itself.