1 package Catalyst::Request;
4 use base 'Class::Accessor::Fast';
6 __PACKAGE__->mk_accessors(
7 qw/action address arguments body base cookies headers hostname match
8 method parameters path protocol secure snippets uploads user/
13 *params = \¶meters;
15 sub content_encoding { shift->headers->content_encoding(@_) }
16 sub content_length { shift->headers->content_length(@_) }
17 sub content_type { shift->headers->content_type(@_) }
18 sub header { shift->headers->header(@_) }
19 sub referer { shift->headers->referer(@_) }
20 sub user_agent { shift->headers->user_agent(@_) }
24 Catalyst::Request - Catalyst Request Class
36 $req->content_encoding;
63 This is the Catalyst Request class, which provides a set of accessors to the
64 request data. The request object is prepared by the specialized Catalyst
65 Engine module thus hiding the details of the particular engine implementation.
74 Contains the requested action.
76 print $c->request->action;
80 Contains the remote address.
82 print $c->request->address
86 Shortcut for arguments
90 Returns a reference to an array containing the arguments.
92 print $c->request->arguments->[0];
96 Contains the url base. This will always have a trailing slash.
100 Contains the message body of the request unless Content-Type is
101 C<application/x-www-form-urlencoded> or C<multipart/form-data>.
103 print $c->request->body
105 =item $req->content_encoding
107 Shortcut to $req->headers->content_encoding
109 =item $req->content_length
111 Shortcut to $req->headers->content_length
113 =item $req->content_type
115 Shortcut to $req->headers->content_type
119 Returns a reference to a hash containing the cookies.
121 print $c->request->cookies->{mycookie}->value;
125 Shortcut to $req->headers->header
129 Returns an L<HTTP::Headers> object containing the headers.
131 print $c->request->headers->header('X-Catalyst');
135 Contains the hostname of the remote user.
137 print $c->request->hostname
141 Shortcut for $req->body.
145 This contains be the matching part of a regexp action. otherwise it
146 returns the same as 'action'.
148 print $c->request->match;
152 Contains the request method (C<GET>, C<POST>, C<HEAD>, etc).
154 print $c->request->method;
158 Get request parameters with a CGI.pm like param method.
160 $value = $c->request->param('foo');
161 @values = $c->request->param('foo');
162 @params = $c->request->param;
170 return keys %{ $self->parameters };
177 unless ( exists $self->parameters->{$param} ) {
178 return wantarray ? () : undef;
181 if ( ref $self->parameters->{$param} eq 'ARRAY' ) {
183 ? @{ $self->parameters->{$param} }
184 : $self->parameters->{$param}->[0];
188 ? ( $self->parameters->{$param} )
189 : $self->parameters->{$param};
195 while ( my ( $field, $value ) = splice( @_, 0, 2 ) ) {
197 if ( exists $self->parameters->{$field} ) {
198 for ( $self->parameters->{$field} ) {
199 $_ = [$_] unless ref($_) eq "ARRAY";
204 $self->parameters->{$field} = $value;
212 Shortcut for $req->parameters.
214 =item $req->parameters
216 Returns a reference to a hash containing parameters. Values can
217 be either a scalar or a arrayref containing scalars.
219 print $c->request->parameters->{field};
220 print $c->request->parameters->{field}->[0];
226 print $c->request->path;
230 Contains the protocol.
234 Shortcut to $req->headers->referer. Referring page.
238 Contains a boolean whether the communciation is secure.
242 Returns a reference to an array containing regex snippets.
244 my @snippets = @{ $c->request->snippets };
248 A convenient method to $req->uploads.
250 $upload = $c->request->upload('field');
251 @uploads = $c->request->upload('field');
252 @fields = $c->request->upload;
254 for my $upload ( $c->request->upload('field') ) {
255 print $upload->filename;
264 return keys %{ $self->uploads };
271 unless ( exists $self->uploads->{$upload} ) {
272 return wantarray ? () : undef;
275 if ( ref $self->uploads->{$upload} eq 'ARRAY' ) {
277 ? @{ $self->uploads->{$upload} }
278 : $self->uploads->{$upload}->[0];
282 ? ( $self->uploads->{$upload} )
283 : $self->uploads->{$upload};
289 while ( my ( $field, $upload ) = splice( @_, 0, 2 ) ) {
291 if ( exists $self->uploads->{$field} ) {
292 for ( $self->uploads->{$field} ) {
293 $_ = [$_] unless ref($_) eq "ARRAY";
294 push( @$_, $upload );
298 $self->uploads->{$field} = $upload;
306 Returns a reference to a hash containing uploads. Values can be either a
307 hashref or a arrayref containing C<Catalyst::Request::Upload> objects.
309 my $upload = $c->request->uploads->{field};
310 my $upload = $c->request->uploads->{field}->[0];
314 Contains the user name of user if authentication check was successful.
316 =item $req->user_agent
318 Shortcut to $req->headers->user_agent. User Agent version string.
324 Sebastian Riedel, C<sri@cpan.org>
325 Marcus Ramberg, C<mramberg@cpan.org>
329 This program is free software, you can redistribute it and/or modify
330 it under the same terms as Perl itself.