1 package Catalyst::Request;
4 use base 'Class::Accessor::Fast';
6 __PACKAGE__->mk_accessors(
7 qw/action address arguments base cookies headers hostname match method
8 parameters path snippets uploads/
12 *params = \¶meters;
14 sub content_encoding { shift->headers->content_encoding(@_) }
15 sub content_length { shift->headers->content_length(@_) }
16 sub content_type { shift->headers->content_type(@_) }
17 sub header { shift->headers->header(@_) }
18 sub referer { shift->headers->referer(@_) }
19 sub user_agent { shift->headers->user_agent(@_) }
23 my ( $self, $map, $values ) = @_;
25 while ( my ( $name, $value ) = splice( @{ $values }, 0, 2 ) ) {
27 if ( exists $map->{$name} ) {
28 for ( $map->{$name} ) {
29 $_ = [$_] unless ref($_) eq "ARRAY";
34 $map->{$name} = $value;
41 Catalyst::Request - Catalyst Request Class
52 $req->content_encoding;
75 This is the Catalyst Request class, which provides a set of accessors to the
76 request data. The request object is prepared by the specialized Catalyst
77 Engine module thus hiding the details of the particular engine implementation.
86 Contains the requested action.
88 print $c->request->action;
92 Contains the remote address.
94 print $c->request->address
98 Shortcut for arguments
100 =item $req->arguments
102 Returns a reference to an array containing the arguments.
104 print $c->request->arguments->[0];
108 Contains the url base. This will always have a trailing slash.
110 =item $req->content_encoding
112 Shortcut to $req->headers->content_encoding
114 =item $req->content_length
116 Shortcut to $req->headers->content_length
118 =item $req->content_type
120 Shortcut to $req->headers->content_type
124 Returns a reference to a hash containing the cookies.
126 print $c->request->cookies->{mycookie}->value;
130 Shortcut to $req->headers->header
134 Returns an L<HTTP::Headers> object containing the headers.
136 print $c->request->headers->header('X-Catalyst');
140 Contains the hostname of the remote user.
142 print $c->request->hostname
146 This contains be the matching part of a regexp action. otherwise it
147 returns the same as 'action'.
149 print $c->request->match;
153 Contains the request method (C<GET>, C<POST>, C<HEAD>, etc).
155 print $c->request->method;
159 Get request parameters with a CGI.pm like param method.
161 $value = $c->request->param('foo');
162 @values = $c->request->param('foo');
163 @params = $c->request->param;
171 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 Shortcut for $req->parameters.
196 =item $req->parameters
198 Returns a reference to a hash containing parameters. Values can
199 be either a scalar or a arrayref containing scalars.
201 print $c->request->parameters->{field};
202 print $c->request->parameters->{field}->[0];
208 print $c->request->path;
212 Shortcut to $req->headers->referer. Referring page.
216 Returns a reference to an array containing regex snippets.
218 my @snippets = @{ $c->request->snippets };
222 A convenient method to $req->uploads.
224 $upload = $c->request->upload('field');
225 @uploads = $c->request->upload('field');
226 @fields = $c->request->upload;
228 for my $upload ( $c->request->upload('field') ) {
229 print $upload->{filename};
238 return keys %{ $self->uploads };
243 unless ( exists $self->uploads->{$upload} ) {
244 return wantarray ? () : undef;
247 if ( ref $self->uploads->{$upload} eq 'ARRAY' ) {
249 ? @{ $self->uploads->{$upload} }
250 : $self->uploads->{$upload}->[0];
254 ? ( $self->uploads->{$upload} )
255 : $self->uploads->{$upload};
261 Returns a reference to a hash containing uploads. Values can
262 be either a hashref or a arrayref containing hashrefs.
264 my $upload = $c->request->uploads->{field};
265 my $upload = $c->request->uploads->{field}->[0];
267 The upload hashref contains the following keys:
277 Client supplied filename.
281 Size of the file in bytes.
285 Path to the temporary spool file.
289 Client supplied Content-Type.
293 =item $req->user_agent
295 Shortcut to $req->headers->user_agent. User Agent version string.
301 Sebastian Riedel, C<sri@cpan.org>
302 Marcus Ramberg, C<mramberg@cpan.org>
306 This program is free software, you can redistribute it and/or modify
307 it under the same terms as Perl itself.