1Catalyst::Request(3) User Contributed Perl Documentation Catalyst::Request(3)
2
3
4
6 Catalyst::Request - provides information about the current client
7 request
8
10 $req = $c->request;
11 $req->action;
12 $req->address;
13 $req->arguments;
14 $req->args;
15 $req->base;
16 $req->body;
17 $req->body_parameters;
18 $req->content_encoding;
19 $req->content_length;
20 $req->content_type;
21 $req->cookie;
22 $req->cookies;
23 $req->header;
24 $req->headers;
25 $req->hostname;
26 $req->input;
27 $req->query_keywords;
28 $req->match;
29 $req->method;
30 $req->param;
31 $req->parameters;
32 $req->params;
33 $req->path;
34 $req->protocol;
35 $req->query_parameters;
36 $req->read;
37 $req->referer;
38 $req->secure;
39 $req->captures; # previously knows as snippets
40 $req->upload;
41 $req->uploads;
42 $req->uri;
43 $req->user;
44 $req->user_agent;
45
46 See also Catalyst, Catalyst::Request::Upload.
47
49 This is the Catalyst Request class, which provides an interface to data
50 for the current client request. The request object is prepared by Cata‐
51 lyst::Engine, thus hiding the details of the particular engine imple‐
52 mentation.
53
55 $req->action
56
57 [DEPRECATED] Returns the name of the requested action.
58
59 Use "$c->action" instead (which returns a Catalyst::Action object).
60
61 $req->address
62
63 Returns the IP address of the client.
64
65 $req->arguments
66
67 Returns a reference to an array containing the arguments.
68
69 print $c->request->arguments->[0];
70
71 For example, if your action was
72
73 package MyApp::C::Foo;
74
75 sub moose : Local {
76 ...
77 }
78
79 and the URI for the request was "http://.../foo/moose/bah", the string
80 "bah" would be the first and only argument.
81
82 $req->args
83
84 Shortcut for arguments.
85
86 $req->base
87
88 Contains the URI base. This will always have a trailing slash.
89
90 If your application was queried with the URI "http://local‐
91 host:3000/some/path" then "base" is "http://localhost:3000/".
92
93 $req->body
94
95 Returns the message body of the request, unless Content-Type is "appli‐
96 cation/x-www-form-urlencoded" or "multipart/form-data".
97
98 $req->body_parameters
99
100 Returns a reference to a hash containing body (POST) parameters. Values
101 can be either a scalar or an arrayref containing scalars.
102
103 print $c->request->body_parameters->{field};
104 print $c->request->body_parameters->{field}->[0];
105
106 These are the parameters from the POST part of the request, if any.
107
108 $req->body_params
109
110 Shortcut for body_parameters.
111
112 $req->content_encoding
113
114 Shortcut for $req->headers->content_encoding.
115
116 $req->content_length
117
118 Shortcut for $req->headers->content_length.
119
120 $req->content_type
121
122 Shortcut for $req->headers->content_type.
123
124 $req->cookie
125
126 A convenient method to access $req->cookies.
127
128 $cookie = $c->request->cookie('name');
129 @cookies = $c->request->cookie;
130
131 $req->cookies
132
133 Returns a reference to a hash containing the cookies.
134
135 print $c->request->cookies->{mycookie}->value;
136
137 The cookies in the hash are indexed by name, and the values are
138 CGI::Cookie objects.
139
140 $req->header
141
142 Shortcut for $req->headers->header.
143
144 $req->headers
145
146 Returns an HTTP::Headers object containing the headers for the current
147 request.
148
149 print $c->request->headers->header('X-Catalyst');
150
151 $req->hostname
152
153 Returns the hostname of the client.
154
155 $req->input
156
157 Alias for $req->body.
158
159 $req->query_keywords
160
161 Contains the keywords portion of a query string, when no '=' signs are
162 present.
163
164 http://localhost/path?some+keywords
165
166 $c->request->query_keywords will contain 'some keywords'
167
168 $req->match
169
170 This contains the matching part of a Regex action. Otherwise it returns
171 the same as 'action', except for default actions, which return an empty
172 string.
173
174 $req->method
175
176 Contains the request method ("GET", "POST", "HEAD", etc).
177
178 $req->param
179
180 Returns GET and POST parameters with a CGI.pm-compatible param method.
181 This is an alternative method for accessing parameters in
182 $c->req->parameters.
183
184 $value = $c->request->param( 'foo' );
185 @values = $c->request->param( 'foo' );
186 @params = $c->request->param;
187
188 Like CGI, and unlike earlier versions of Catalyst, passing multiple
189 arguments to this method, like this:
190
191 $c->request->param( 'foo', 'bar', 'gorch', 'quxx' );
192
193 will set the parameter "foo" to the multiple values "bar", "gorch" and
194 "quxx". Previously this would have added "bar" as another value to
195 "foo" (creating it if it didn't exist before), and "quxx" as another
196 value for "gorch".
197
198 $req->parameters
199
200 Returns a reference to a hash containing GET and POST parameters. Val‐
201 ues can be either a scalar or an arrayref containing scalars.
202
203 print $c->request->parameters->{field};
204 print $c->request->parameters->{field}->[0];
205
206 This is the combination of "query_parameters" and "body_parameters".
207
208 $req->params
209
210 Shortcut for $req->parameters.
211
212 $req->path
213
214 Returns the path, i.e. the part of the URI after $req->base, for the
215 current request.
216
217 $req->path_info
218
219 Alias for path, added for compability with CGI.
220
221 $req->protocol
222
223 Returns the protocol (HTTP/1.0 or HTTP/1.1) used for the current
224 request.
225
226 $req->query_parameters
227
228 $req->query_params
229
230 Returns a reference to a hash containing query string (GET) parameters.
231 Values can be either a scalar or an arrayref containing scalars.
232
233 print $c->request->query_parameters->{field};
234 print $c->request->query_parameters->{field}->[0];
235
236 $req->read( [$maxlength] )
237
238 Reads a chunk of data from the request body. This method is intended to
239 be used in a while loop, reading $maxlength bytes on every call.
240 $maxlength defaults to the size of the request if not specified.
241
242 You have to set MyApp->config->{parse_on_demand} to use this directly.
243
244 $req->referer
245
246 Shortcut for $req->headers->referer. Returns the referring page.
247
248 $req->secure
249
250 Returns true or false, indicating whether the connection is secure
251 (https).
252
253 $req->captures
254
255 Returns a reference to an array containing regex captures.
256
257 my @captures = @{ $c->request->captures };
258
259 $req->snippets
260
261 "captures" used to be called snippets. This is still available for
262 backwoards compatibility, but is considered deprecated.
263
264 $req->upload
265
266 A convenient method to access $req->uploads.
267
268 $upload = $c->request->upload('field');
269 @uploads = $c->request->upload('field');
270 @fields = $c->request->upload;
271
272 for my $upload ( $c->request->upload('field') ) {
273 print $upload->filename;
274 }
275
276 $req->uploads
277
278 Returns a reference to a hash containing uploads. Values can be either
279 a Catalyst::Request::Upload object, or an arrayref of Cata‐
280 lyst::Request::Upload objects.
281
282 my $upload = $c->request->uploads->{field};
283 my $upload = $c->request->uploads->{field}->[0];
284
285 $req->uri
286
287 Returns a URI object for the current request. Stringifies to the URI
288 text.
289
290 $req->uri_with( { key => 'value' } );
291
292 Returns a rewritten URI object for the current request. Key/value pairs
293 passed in will override existing parameters. Unmodified pairs will be
294 preserved.
295
296 $req->user
297
298 Returns the currently logged in user. Deprecated. The method recom‐
299 mended for newer plugins is $c->user.
300
301 $req->user_agent
302
303 Shortcut to $req->headers->user_agent. Returns the user agent (browser)
304 version string.
305
307 Sebastian Riedel, "sri@cpan.org"
308
309 Marcus Ramberg, "mramberg@cpan.org"
310
312 This program is free software, you can redistribute it and/or modify it
313 under the same terms as Perl itself.
314
315
316
317perl v5.8.8 2007-09-20 Catalyst::Request(3)