1Catalyst::Controller(3)User Contributed Perl DocumentatioCnatalyst::Controller(3)
2
3
4

NAME

6       Catalyst::Controller - Catalyst Controller base class
7

SYNOPSIS

9         package MyApp::Controller::Search
10         use base qw/Catalyst::Controller/;
11
12         sub foo : Local {
13           my ($self,$c,@args) = @_;
14           ...
15         } # Dispatches to /search/foo
16

DESCRIPTION

18       Controllers are where the actions in the Catalyst framework reside.
19       Each action is represented by a function with an attribute to identify
20       what kind of action it is. See the Catalyst::Dispatcher for more info
21       about how Catalyst dispatches to actions.
22

CONFIGURATION

24       Like any other Catalyst::Component, controllers have a config hash,
25       accessible through $self->config from the controller actions.  Some
26       settings are in use by the Catalyst framework:
27
28   namespace
29       This specifies the internal namespace the controller should be bound
30       to. By default the controller is bound to the URI version of the
31       controller name. For instance controller 'MyApp::Controller::Foo::Bar'
32       will be bound to 'foo/bar'. The default Root controller is an example
33       of setting namespace to '' (the null string).
34
35   path
36       Sets 'path_prefix', as described below.
37
38   action
39       Allows you to set the attributes that the dispatcher creates actions
40       out of.  This allows you to do 'rails style routes', or override some
41       of the attribute defintions of actions composed from Roles.  You can
42       set arguments globally (for all actions of the controller) and
43       specifically (for a single action).
44
45           __PACKAGE__->config(
46               action => {
47                   '*' => { Chained => 'base', Args => 0  },
48                   base => { Chained => '/', PathPart => '', CaptureArgs => 0 },
49               },
50            );
51
52       In the case above every sub in the package would be made into a Chain
53       endpoint with a URI the same as the sub name for each sub, chained to
54       the sub named "base". Ergo dispatch to "/example" would call the "base"
55       method, then the "example" method.
56
57   action_args
58       Allows you to set constructor arguments on your actions. You can set
59       arguments globally and specifically (as above).  This is particularly
60       useful when using "ActionRole"s (Catalyst::Controller::ActionRole) and
61       custom "ActionClass"es.
62
63           __PACKAGE__->config(
64               action_args => {
65                   '*' => { globalarg1 => 'hello', globalarg2 => 'goodbye' },
66                   'specific_action' => { customarg => 'arg1' },
67               },
68            );
69
70       In the case above the action class associated with "specific_action"
71       would get passed the following arguments, in addition to the normal
72       action constructor arguments, when it is instantiated:
73
74         (globalarg1 => 'hello', globalarg2 => 'goodbye', customarg => 'arg1')
75

METHODS

77   BUILDARGS ($app, @args)
78       From Catalyst::Component::ApplicationAttribute, stashes the application
79       instance as $self->_application.
80
81   $self->action_for('name')
82       Returns the Catalyst::Action object (if any) for a given method name in
83       this component.
84
85   $self->action_namespace($c)
86       Returns the private namespace for actions in this component. Defaults
87       to a value from the controller name (for e.g.
88       MyApp::Controller::Foo::Bar becomes "foo/bar") or can be overridden
89       from the "namespace" config key.
90
91   $self->path_prefix($c)
92       Returns the default path prefix for :PathPrefix, :Local, :LocalRegex
93       and relative :Path actions in this component. Defaults to the
94       action_namespace or can be overridden from the "path" config key.
95
96   $self->register_actions($c)
97       Finds all applicable actions for this component, creates
98       Catalyst::Action objects (using $self->create_action) for them and
99       registers them with $c->dispatcher.
100
101   $self->get_action_methods()
102       Returns a list of Moose::Meta::Method objects, doing the
103       MooseX::MethodAttributes::Role::Meta::Method role, which are the set of
104       action methods for this package.
105
106   $self->register_action_methods($c, @methods)
107       Creates action objects for a set of action methods using "
108       create_action ", and registers them with the dispatcher.
109
110   $self->action_class(%args)
111       Used when a controller is creating an action to determine the correct
112       base action class to use.
113
114   $self->create_action(%args)
115       Called with a hash of data to be use for construction of a new
116       Catalyst::Action (or appropriate sub/alternative class) object.
117
118   $self->_application
119   $self->_app
120       Returns the application instance stored by "new()"
121

AUTHORS

123       Catalyst Contributors, see Catalyst.pm
124
126       This library is free software. You can redistribute it and/or modify it
127       under the same terms as Perl itself.
128
129
130
131perl v5.12.1                      2010-07-28           Catalyst::Controller(3)
Impressum