3 Catalyst::Manual::Actions - Catalyst Reusable Actions
7 This section of the manual describes the reusable action system in
8 Catalyst, how they work, descriptions of some existing ones, and how to
9 write your own. Reusable actions are attributes on Catalyst methods
10 that allow you to decorate your method with functions running before or
11 after the method call. This can be used to implement commonly used
12 action patterns, while still leaving you full freedom to customize them.
16 This is pretty simple. It works just like the normal dispatch attributes
17 you are used to, like Local or Private:
19 sub Hello :Local :ActionClass('SayBefore') {
20 $c->res->output( 'Hello '.$c->stash->{what} );
23 In this example, we expect the SayBefore action to magically populate
24 stash with something relevant before C<Hello> is run. In the next
25 section we'll show you how to implement it. If you want it in another
26 namespace than Catalyst::Action you can prefix the action name with a
27 '+', for instance '+Foo::SayBefore', or if you just want it under your
28 application namespace instead, use MyAction, like MyAction('SayBefore').
30 =head1 WRITING YOUR OWN ACTIONS
32 Implementing the action itself is almost as easy. Just use
33 L<Catalyst::Action> as a base class and decorate the C<execute> call in
36 package Catalyst::Action::SayBefore;
38 use base 'Catalyst::Action';
42 my ( $controller, $c, $test ) = @_;
43 $c->stash->{what} = 'world';
44 $self->NEXT::execute( @_ );
49 If you want to do something after the action, just put it after the
50 C<execute> call. Pretty simple, huh?
54 =head2 Catalyst::Action::RenderView
56 This is meant to decorate end actions. It's similar in operation to
57 L<Catalyst::Plugin::DefaultEnd>, but allows you to decide on an action
58 level rather than on an application level where it should be run.
62 The Catalyst Core Team - see http://catalyst.perl.org/
66 This program is free software. You can redistribute it and/or modify it
67 under the same terms as Perl itself.