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/
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;
62 This is the Catalyst Request class, which provides a set of accessors to the
63 request data. The request object is prepared by the specialized Catalyst
64 Engine module thus hiding the details of the particular engine implementation.
73 Contains the requested action.
75 print $c->request->action;
79 Contains the remote address.
81 print $c->request->address
85 Shortcut for arguments
89 Returns a reference to an array containing the arguments.
91 print $c->request->arguments->[0];
95 Contains the url base. This will always have a trailing slash.
99 Contains the message body of the request unless Content-Type is
100 C<application/x-www-form-urlencoded> or C<multipart/form-data>.
102 print $c->request->body
104 =item $req->content_encoding
106 Shortcut to $req->headers->content_encoding
108 =item $req->content_length
110 Shortcut to $req->headers->content_length
112 =item $req->content_type
114 Shortcut to $req->headers->content_type
118 Returns a reference to a hash containing the cookies.
120 print $c->request->cookies->{mycookie}->value;
124 Shortcut to $req->headers->header
128 Returns an L<HTTP::Headers> object containing the headers.
130 print $c->request->headers->header('X-Catalyst');
134 Contains the hostname of the remote user.
136 print $c->request->hostname
140 Shortcut for $req->body.
144 This contains be the matching part of a regexp action. otherwise it
145 returns the same as 'action'.
147 print $c->request->match;
151 Contains the request method (C<GET>, C<POST>, C<HEAD>, etc).
153 print $c->request->method;
157 Get request parameters with a CGI.pm like param method.
159 $value = $c->request->param('foo');
160 @values = $c->request->param('foo');
161 @params = $c->request->param;
169 return keys %{ $self->parameters };
176 unless ( exists $self->parameters->{$param} ) {
177 return wantarray ? () : undef;
180 if ( ref $self->parameters->{$param} eq 'ARRAY' ) {
182 ? @{ $self->parameters->{$param} }
183 : $self->parameters->{$param}->[0];
187 ? ( $self->parameters->{$param} )
188 : $self->parameters->{$param};
194 while ( my ( $field, $value ) = splice( @_, 0, 2 ) ) {
196 if ( exists $self->parameters->{$field} ) {
197 for ( $self->parameters->{$field} ) {
198 $_ = [$_] unless ref($_) eq "ARRAY";
203 $self->parameters->{$field} = $value;
211 Shortcut for $req->parameters.
213 =item $req->parameters
215 Returns a reference to a hash containing parameters. Values can
216 be either a scalar or a arrayref containing scalars.
218 print $c->request->parameters->{field};
219 print $c->request->parameters->{field}->[0];
225 print $c->request->path;
229 Contains the protocol.
233 Shortcut to $req->headers->referer. Referring page.
237 Contains a boolean whether the communciation is secure.
241 Returns a reference to an array containing regex snippets.
243 my @snippets = @{ $c->request->snippets };
247 A convenient method to $req->uploads.
249 $upload = $c->request->upload('field');
250 @uploads = $c->request->upload('field');
251 @fields = $c->request->upload;
253 for my $upload ( $c->request->upload('field') ) {
254 print $upload->filename;
263 return keys %{ $self->uploads };
270 unless ( exists $self->uploads->{$upload} ) {
271 return wantarray ? () : undef;
274 if ( ref $self->uploads->{$upload} eq 'ARRAY' ) {
276 ? @{ $self->uploads->{$upload} }
277 : $self->uploads->{$upload}->[0];
281 ? ( $self->uploads->{$upload} )
282 : $self->uploads->{$upload};
288 while ( my ( $field, $upload ) = splice( @_, 0, 2 ) ) {
290 if ( exists $self->uploads->{$field} ) {
291 for ( $self->uploads->{$field} ) {
292 $_ = [$_] unless ref($_) eq "ARRAY";
293 push( @$_, $upload );
297 $self->uploads->{$field} = $upload;
305 Returns a reference to a hash containing uploads. Values can be either a
306 hashref or a arrayref containing C<Catalyst::Request::Upload> objects.
308 my $upload = $c->request->uploads->{field};
309 my $upload = $c->request->uploads->{field}->[0];
311 =item $req->user_agent
313 Shortcut to $req->headers->user_agent. User Agent version string.
319 Sebastian Riedel, C<sri@cpan.org>
320 Marcus Ramberg, C<mramberg@cpan.org>
324 This program is free software, you can redistribute it and/or modify
325 it under the same terms as Perl itself.