mro compat stuff
[catagits/Catalyst-Runtime.git] / lib / Catalyst / ActionChain.pm
CommitLineData
141459fa 1package Catalyst::ActionChain;
2
6f1f968a 3use MRO::Compat;
4use mro 'c3';
059c085b 5use Moose;
6extends qw(Catalyst::Action);
141459fa 7
059c085b 8has chain => (is => 'rw');
141459fa 9
0fc2d522 10no Moose;
11
141459fa 12=head1 NAME
13
14Catalyst::ActionChain - Chain of Catalyst Actions
15
16=head1 SYNOPSIS
17
b2ddf6d7 18See L<Catalyst::Manual::Intro> for more info about Chained actions.
141459fa 19
20=head1 DESCRIPTION
21
22This class represents a chain of Catalyst Actions. It behaves exactly like
23the action at the *end* of the chain except on dispatch it will execute all
24the actions in the chain in order.
25
b2ddf6d7 26=cut
141459fa 27
141459fa 28sub dispatch {
29 my ( $self, $c ) = @_;
d7962771 30 my @captures = @{$c->req->captures||[]};
ee1ac377 31 my @chain = @{ $self->chain };
32 my $last = pop(@chain);
33 foreach my $action ( @chain ) {
d7962771 34 my @args;
1c34f703 35 if (my $cap = $action->attributes->{CaptureArgs}) {
d7962771 36 @args = splice(@captures, 0, $cap->[0]);
37 }
38 local $c->request->{arguments} = \@args;
141459fa 39 $action->dispatch( $c );
40 }
ee1ac377 41 $last->dispatch( $c );
141459fa 42}
43
b2ddf6d7 44sub from_chain {
45 my ( $self, $actions ) = @_;
46 my $final = $actions->[-1];
47 return $self->new({ %$final, chain => $actions });
48}
49
e5ecd5bc 50__PACKAGE__->meta->make_immutable;
b2ddf6d7 511;
52
53__END__
54
55=head1 METHODS
56
57=head2 chain
58
59Accessor for the action chain; will be an arrayref of the Catalyst::Action
60objects encapsulated by this chain.
61
62=head2 dispatch( $c )
63
64Dispatch this action chain against a context; will dispatch the encapsulated
65actions in order.
66
141459fa 67=head2 from_chain( \@actions )
68
69Takes a list of Catalyst::Action objects and constructs and returns a
70Catalyst::ActionChain object representing a chain of these actions
71
059c085b 72=head2 meta
73
74Provided by Moose
141459fa 75
141459fa 76=head1 AUTHOR
77
78Matt S. Trout
79
80=head1 COPYRIGHT
81
82This program is free software, you can redistribute it and/or modify it under
83the same terms as Perl itself.
84
85=cut