3 Catalyst::Manual::Actions - Catalyst Reusable Actions
7 This section of the manual describes the reusable action system in catalyst,
8 how they work, descriptions of some existing ones, and how to write your own.
9 Reusable actions are attributes on Catalyst methods that allow you to decorate
10 your method with functions running before or after the method call.
11 This can be used to implement commonly used action patterns, while still
12 leaving you full freedom to customize them.
16 This is pretty simple. It works just like the normal dispatch attributes you
17 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 stash with
24 something relevant before Hello is run. In the next section we'll show you
25 how to implement it. If you want it in another namespace than Catalyst::Action
26 you can prefix the action name with a '+', for instance '+Foo::SayBefore',
27 or if you just want it under your application namespace instead, use MyAction,
28 like MyAction('SayBefore').
30 =head1 WRITING YOUR OWN ACTIONS
32 Implementing the action is self is almost as easy. Just use L<Catalyst::Action>
33 as a base class and decorate the 'execute' call in the Action class:
35 package Catalyst::Action::SayBefore;
37 use base 'Catalyst::Action';
41 my ( $controller, $c, $test ) = @_;
42 $c->stash->{what} = 'world';
43 $self->NEXT::execute( @_ );
48 If you want to do something after the action, just put it after the execute
49 call. Pretty simple, huh?
53 =head2 Catalyst::Action::RenderView
55 This is meant to decorate end actions. It's similar in operation to
56 L<Catalyst::Plugin::DefaultEnd>, but allows you to decide on an action
57 level rather than on an application level where it should be run.