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 Catalyst::Request - Catalyst Request Class
34 $req->content_encoding;
55 This is the Catalyst Request class, which provides a set of accessors to the
56 request data. The request object is prepared by the specialized Catalyst
57 Engine module thus hiding the details of the particular engine implementation.
66 Contains the requested action.
68 print $c->request->action;
72 Contains the remote address.
74 print $c->request->address
78 Shortcut for arguments
82 Returns a reference to an array containing the arguments.
84 print $c->request->arguments->[0];
88 Contains the url base. This will always have a trailing slash.
90 =item $req->content_encoding
92 Shortcut to $req->headers->content_encoding
94 =item $req->content_length
96 Shortcut to $req->headers->content_length
98 =item $req->content_type
100 Shortcut to $req->headers->content_type
104 Returns a reference to a hash containing the cookies.
106 print $c->request->cookies->{mycookie}->value;
110 Shortcut to $req->headers->header
114 Returns an L<HTTP::Headers> object containing the headers.
116 print $c->request->headers->header('X-Catalyst');
120 Contains the hostname of the remote user.
122 print $c->request->hostname
126 This contains be the matching part of a regexp action. otherwise it
127 returns the same as 'action'.
129 print $c->request->match;
133 Contains the request method (C<GET>, C<POST>, C<HEAD>, etc).
135 print $c->request->method
139 Shortcut for $req->parameters.
141 =item $req->parameters
143 Returns a reference to a hash containing the parameters.
145 print $c->request->parameters->{foo};
151 print $c->request->path;
155 Shortcut to $req->headers->referer. Referring page.
159 Returns a reference to an array containing regex snippets.
161 my @snippets = @{ $c->request->snippets };
165 Returns a reference to a hash containing the uploads.
167 my $filename = $c->req->parameters->{foo};
168 print $c->request->uploads->{$filename}->{type};
169 print $c->request->uploads->{$filename}->{size};
170 my $fh = $c->request->uploads->{$filename}->{fh};
171 my $content = do { local $/; <$fh> };
173 =item $req->user_agent
175 Shortcut to $req->headers->user_agent. User Agent version string.
181 Sebastian Riedel, C<sri@cpan.org>
182 Marcus Ramberg, C<mramberg@cpan.org>
186 This program is free software, you can redistribute it and/or modify
187 it under the same terms as Perl itself.