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