Commit | Line | Data |
---|---|---|
fc7ec1d9 | 1 | package Catalyst::Request; |
2 | ||
3 | use strict; | |
4 | use base 'Class::Accessor::Fast'; | |
5 | ||
6 | __PACKAGE__->mk_accessors( | |
0556eb49 | 7 | qw/action address arguments base cookies headers hostname match method |
8 | parameters path snippets uploads/ | |
fc7ec1d9 | 9 | ); |
10 | ||
11 | *args = \&arguments; | |
12 | *params = \¶meters; | |
13 | ||
f7e4e231 | 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(@_) } | |
20 | ||
fc7ec1d9 | 21 | =head1 NAME |
22 | ||
23 | Catalyst::Request - Catalyst Request Class | |
24 | ||
25 | =head1 SYNOPSIS | |
26 | ||
b22c6668 | 27 | |
28 | $req = $c->request; | |
29 | $req->action; | |
30 | $req->address; | |
31 | $req->args; | |
32 | $req->arguments; | |
33 | $req->base; | |
b5176d9e | 34 | $req->content_encoding; |
35 | $req->content_length; | |
36 | $req->content_type; | |
b22c6668 | 37 | $req->cookies; |
b5176d9e | 38 | $req->header; |
b22c6668 | 39 | $req->headers; |
40 | $req->hostname; | |
41 | $req->match; | |
42 | $req->method; | |
43 | $req->parameters; | |
44 | $req->params; | |
45 | $req->path; | |
b5176d9e | 46 | $req->referer; |
b22c6668 | 47 | $req->snippets; |
48 | $req->uploads; | |
b5176d9e | 49 | $req->user_agent |
b22c6668 | 50 | |
51 | See also L<Catalyst>. | |
fc7ec1d9 | 52 | |
53 | =head1 DESCRIPTION | |
54 | ||
b22c6668 | 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. | |
58 | ||
59 | ||
60 | =head1 METHODS | |
fc7ec1d9 | 61 | |
b22c6668 | 62 | =over 4 |
fc7ec1d9 | 63 | |
b22c6668 | 64 | =item $req->action |
fc7ec1d9 | 65 | |
61b1e958 | 66 | Contains the requested action. |
fc7ec1d9 | 67 | |
68 | print $c->request->action; | |
69 | ||
b22c6668 | 70 | =item $req->address |
0556eb49 | 71 | |
72 | Contains the remote address. | |
73 | ||
74 | print $c->request->address | |
75 | ||
b22c6668 | 76 | =item $req->args |
77 | ||
61b1e958 | 78 | Shortcut for arguments |
79 | ||
80 | =item $req->arguments | |
81 | ||
b22c6668 | 82 | Returns a reference to an array containing the arguments. |
fc7ec1d9 | 83 | |
84 | print $c->request->arguments->[0]; | |
85 | ||
b22c6668 | 86 | =item $req->base |
fc7ec1d9 | 87 | |
61b1e958 | 88 | Contains the url base. This will always have a trailing slash. |
fc7ec1d9 | 89 | |
b5176d9e | 90 | =item $req->content_encoding |
91 | ||
92 | Shortcut to $req->headers->content_encoding | |
93 | ||
94 | =item $req->content_length | |
95 | ||
96 | Shortcut to $req->headers->content_length | |
97 | ||
98 | =item $req->content_type | |
99 | ||
100 | Shortcut to $req->headers->content_type | |
101 | ||
b22c6668 | 102 | =item $req->cookies |
fc7ec1d9 | 103 | |
b22c6668 | 104 | Returns a reference to a hash containing the cookies. |
fc7ec1d9 | 105 | |
106 | print $c->request->cookies->{mycookie}->value; | |
107 | ||
b5176d9e | 108 | =item $req->header |
109 | ||
110 | Shortcut to $req->headers->header | |
111 | ||
b22c6668 | 112 | =item $req->headers |
fc7ec1d9 | 113 | |
b22c6668 | 114 | Returns an L<HTTP::Headers> object containing the headers. |
fc7ec1d9 | 115 | |
116 | print $c->request->headers->header('X-Catalyst'); | |
117 | ||
b22c6668 | 118 | =item $req->hostname |
0556eb49 | 119 | |
61b1e958 | 120 | Contains the hostname of the remote user. |
0556eb49 | 121 | |
122 | print $c->request->hostname | |
123 | ||
b22c6668 | 124 | =item $req->match |
fc7ec1d9 | 125 | |
61b1e958 | 126 | This contains be the matching part of a regexp action. otherwise it |
127 | returns the same as 'action'. | |
fc7ec1d9 | 128 | |
129 | print $c->request->match; | |
130 | ||
b5176d9e | 131 | =item $req->method |
132 | ||
133 | Contains the request method (C<GET>, C<POST>, C<HEAD>, etc). | |
134 | ||
135 | print $c->request->method | |
136 | ||
b22c6668 | 137 | =item $req->params |
fc7ec1d9 | 138 | |
61b1e958 | 139 | Shortcut for $req->parameters. |
140 | ||
141 | =item $req->parameters | |
142 | ||
b22c6668 | 143 | Returns a reference to a hash containing the parameters. |
fc7ec1d9 | 144 | |
145 | print $c->request->parameters->{foo}; | |
146 | ||
b22c6668 | 147 | =item $req->path |
fc7ec1d9 | 148 | |
149 | Contains the path. | |
150 | ||
151 | print $c->request->path; | |
152 | ||
b5176d9e | 153 | =item $req->referer |
fc7ec1d9 | 154 | |
61b1e958 | 155 | Shortcut to $req->headers->referer. Referring page. |
fc7ec1d9 | 156 | |
b22c6668 | 157 | =item $req->snippets |
fc7ec1d9 | 158 | |
b22c6668 | 159 | Returns a reference to an array containing regex snippets. |
fc7ec1d9 | 160 | |
161 | my @snippets = @{ $c->request->snippets }; | |
162 | ||
b22c6668 | 163 | =item $req->uploads |
fc7ec1d9 | 164 | |
b22c6668 | 165 | Returns a reference to a hash containing the uploads. |
fc7ec1d9 | 166 | |
7833fdfc | 167 | my $filename = $c->req->parameters->{foo}; |
0ea0c2c3 | 168 | print $c->request->uploads->{$filename}->{type}; |
169 | print $c->request->uploads->{$filename}->{size}; | |
170 | my $fh = $c->request->uploads->{$filename}->{fh}; | |
7833fdfc | 171 | my $content = do { local $/; <$fh> }; |
fc7ec1d9 | 172 | |
b5176d9e | 173 | =item $req->user_agent |
174 | ||
61b1e958 | 175 | Shortcut to $req->headers->user_agent. User Agent version string. |
b5176d9e | 176 | |
b22c6668 | 177 | =back |
178 | ||
fc7ec1d9 | 179 | =head1 AUTHOR |
180 | ||
181 | Sebastian Riedel, C<sri@cpan.org> | |
61b1e958 | 182 | Marcus Ramberg, C<mramberg@cpan.org> |
fc7ec1d9 | 183 | |
184 | =head1 COPYRIGHT | |
185 | ||
61b1e958 | 186 | This program is free software, you can redistribute it and/or modify |
187 | it under the same terms as Perl itself. | |
fc7ec1d9 | 188 | |
189 | =cut | |
190 | ||
191 | 1; |