1Catalyst::Controller::AUcsteironCRoonlter(i3b)uted PerlCDaotcaulmyesntt:a:tCioonntroller::ActionRole(3)
2
3
4

NAME

6       Catalyst::Controller::ActionRole - Apply roles to action instances
7

SYNOPSIS

9           package MyApp::Controller::Foo;
10
11           use Moose;
12           use namespace::autoclean;
13
14           BEGIN { extends 'Catalyst::Controller::ActionRole' }
15
16           sub bar : Local Does('Moo') { ... }
17

DESCRIPTION

19       This module allows to apply Moose::Roles to the "Catalyst::Action"s for
20       different controller methods.
21
22       For that a "Does" attribute is provided. That attribute takes an
23       argument, that determines the role, which is going to be applied. If
24       that argument is prefixed with "+", it is assumed to be the full name
25       of the role. If it's prefixed with "~", the name of your application
26       followed by "::ActionRole::" is prepended. If it isn't prefixed with
27       "+" or "~", the role name will be searched for in @INC according to the
28       rules for role prefix searching.
29
30       It's possible to to apply roles to all actions of a controller without
31       specifying the "Does" keyword in every action definition:
32
33           package MyApp::Controller::Bar
34
35           use Moose;
36           use namespace::autoclean;
37
38           BEGIN { extends 'Catalyst::Controller::ActionRole' }
39
40           __PACKAGE__->config(
41               action_roles => ['Foo', '~Bar'],
42           );
43
44           # Has Catalyst::ActionRole::Foo and MyApp::ActionRole::Bar applied.
45           #
46           # If MyApp::ActionRole::Foo exists and is loadable, it will take
47           # precedence over Catalyst::ActionRole::Foo.
48           #
49           # If MyApp::ActionRole::Bar exists and is loadable, it will be loaded,
50           # but even if it doesn't exist Catalyst::ActionRole::Bar will not be loaded.
51           sub moo : Local { ... }
52
53       Additionally, roles can be applied to selected actions without
54       specifying "Does" using "action" in Catalyst::Controller and configured
55       with "action_args" in Catalyst::Controller:
56
57           package MyApp::Controller::Baz;
58
59           use Moose;
60           use namespace::autoclean;
61
62           BEGIN { extends 'Catalyst::Controller::ActionRole' }
63
64           __PACKAGE__->config(
65               action_roles => [qw( Foo )],
66               action       => {
67                   some_action    => { Does => [qw( ~Bar )] },
68                   another_action => { Does => [qw( +MyActionRole::Baz )] },
69               },
70               action_args  => {
71                   another_action => { customarg => 'arg1' },
72               }
73           );
74
75           # has Catalyst::ActionRole::Foo and MyApp::ActionRole::Bar applied
76           sub some_action : Local { ... }
77
78           # has Catalyst::ActionRole::Foo and MyActionRole::Baz applied
79           # and associated action class would get additional arguments passed
80           sub another_action : Local { ... }
81

ATTRIBUTES

83   _action_role_prefix
84       This class attribute stores an array reference of role prefixes to
85       search for role names in if they aren't prefixed with "+" or "~". It
86       defaults to "[ 'Catalyst::ActionRole::' ]".  See "role prefix
87       searching".
88
89   _action_roles
90       This attribute stores an array reference of role names that will be
91       applied to every action of this controller. It can be set by passing a
92       "action_roles" argument to the constructor. The same expansions as for
93       "Does" will be performed.
94

METHODS

96   gather_action_roles(\%action_args)
97       Gathers the list of roles to apply to an action with the given
98       %action_args.
99

ROLE PREFIX SEARCHING

101       Roles specified with no prefix are looked up under a set of role
102       prefixes.  The first prefix is always "MyApp::ActionRole::" (with
103       "MyApp" replaced as appropriate for your application); the following
104       prefixes are taken from the "_action_role_prefix" attribute.
105

AUTHORS

107       ·   Florian Ragwitz <rafl@debian.org>
108
109       ·   Hans Dieter Pearcey <hdp@weftsoar.net>
110
111       ·   Alex J. G. BurzyXski <ajgb@ajgb.net>
112
113       ·   John Napiorkowski <jjn1056@yahoo.com>
114
115       ·   William King <william.king@quentustech.com>
116
117       ·   Tomas Doran <bobtfish@bobtfish.net>
118
120       This software is copyright (c) 2010 by Florian Ragwitz.
121
122       This is free software; you can redistribute it and/or modify it under
123       the same terms as the Perl 5 programming language system itself.
124
125
126
127perl v5.12.1                      2010-08-25Catalyst::Controller::ActionRole(3)
Impressum