1 package Catalyst::ActionChain;
5 extends qw(Catalyst::Action);
7 has chain => (is => 'rw');
13 Catalyst::ActionChain - Chain of Catalyst Actions
17 See L<Catalyst::Manual::Intro> for more info about Chained actions.
21 This class represents a chain of Catalyst Actions. It behaves exactly like
22 the action at the *end* of the chain except on dispatch it will execute all
23 the actions in the chain in order.
29 # Stringify to reverse for debug output etc.
30 q{""} => sub { shift->{reverse} },
32 # Codulate to execute to invoke the encapsulated action coderef
33 '&{}' => sub { my $self = shift; sub { $self->execute(@_); }; },
35 # Make general $stuff still work
42 my ( $self, $c ) = @_;
43 my @captures = @{$c->req->captures||[]};
44 my @chain = @{ $self->chain };
45 my $last = pop(@chain);
46 foreach my $action ( @chain ) {
48 if (my $cap = $action->attributes->{CaptureArgs}) {
49 @args = splice(@captures, 0, $cap->[0]);
51 local $c->request->{arguments} = \@args;
52 $action->dispatch( $c );
54 $last->dispatch( $c );
58 my ( $self, $actions ) = @_;
59 my $final = $actions->[-1];
60 return $self->new({ %$final, chain => $actions });
63 __PACKAGE__->meta->make_immutable;
72 Accessor for the action chain; will be an arrayref of the Catalyst::Action
73 objects encapsulated by this chain.
77 Dispatch this action chain against a context; will dispatch the encapsulated
80 =head2 from_chain( \@actions )
82 Takes a list of Catalyst::Action objects and constructs and returns a
83 Catalyst::ActionChain object representing a chain of these actions
95 This program is free software, you can redistribute it and/or modify it under
96 the same terms as Perl itself.