1Catalyst::Manual::ActioUnsse(r3)Contributed Perl DocumenCtaattailoynst::Manual::Actions(3)
2
3
4
6 Catalyst::Manual::Actions - Catalyst Reusable Actions
7
9 This section of the manual describes the reusable action system in Cat‐
10 alyst, how they work, descriptions of some existing ones, and how to
11 write your own. Reusable actions are attributes on Catalyst methods
12 that allow you to decorate your method with functions running before or
13 after the method call. This can be used to implement commonly used
14 action patterns, while still leaving you full freedom to customize
15 them.
16
18 This is pretty simple. It works just like the normal dispatch
19 attributes you are used to, like Local or Private:
20
21 sub Hello :Local :ActionClass('SayBefore') {
22 $c->res->output( 'Hello '.$c->stash->{what} );
23 }
24
25 In this example, we expect the SayBefore action to magically populate
26 stash with something relevant before "Hello" is run. In the next sec‐
27 tion we'll show you how to implement it. If you want it in another
28 namespace than Catalyst::Action you can prefix the action name with a
29 '+', for instance '+Foo::SayBefore', or if you just want it under your
30 application namespace instead, use MyAction, like MyAction('SayBe‐
31 fore').
32
34 Implementing the action itself is almost as easy. Just use Cata‐
35 lyst::Action as a base class and decorate the "execute" call in the
36 Action class:
37
38 package Catalyst::Action::SayBefore;
39
40 use base 'Catalyst::Action';
41
42 sub execute {
43 my $self = shift;
44 my ( $controller, $c, $test ) = @_;
45 $c->stash->{what} = 'world';
46 $self->NEXT::execute( @_ );
47 };
48
49 1;
50
51 If you want to do something after the action, just put it after the
52 "execute" call. Pretty simple, huh?
53
55 Catalyst::Action::RenderView
56
57 This is meant to decorate end actions. It's similar in operation to
58 Catalyst::Plugin::DefaultEnd, but allows you to decide on an action
59 level rather than on an application level where it should be run.
60
62 The Catalyst Core Team - see http://catalyst.perl.org/
63
65 This program is free software. You can redistribute it and/or modify it
66 under the same terms as Perl itself.
67
68
69
70perl v5.8.8 2007-02-28 Catalyst::Manual::Actions(3)