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 | |
66 | Contains the action. | |
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->arguments |
fc7ec1d9 | 77 | |
b22c6668 | 78 | =item $req->args |
79 | ||
80 | Returns a reference to an array containing the arguments. | |
fc7ec1d9 | 81 | |
82 | print $c->request->arguments->[0]; | |
83 | ||
b22c6668 | 84 | =item $req->base |
fc7ec1d9 | 85 | |
86 | Contains the uri base. | |
87 | ||
b5176d9e | 88 | =item $req->content_encoding |
89 | ||
90 | Shortcut to $req->headers->content_encoding | |
91 | ||
92 | =item $req->content_length | |
93 | ||
94 | Shortcut to $req->headers->content_length | |
95 | ||
96 | =item $req->content_type | |
97 | ||
98 | Shortcut to $req->headers->content_type | |
99 | ||
b22c6668 | 100 | =item $req->cookies |
fc7ec1d9 | 101 | |
b22c6668 | 102 | Returns a reference to a hash containing the cookies. |
fc7ec1d9 | 103 | |
104 | print $c->request->cookies->{mycookie}->value; | |
105 | ||
b5176d9e | 106 | =item $req->header |
107 | ||
108 | Shortcut to $req->headers->header | |
109 | ||
b22c6668 | 110 | =item $req->headers |
fc7ec1d9 | 111 | |
b22c6668 | 112 | Returns an L<HTTP::Headers> object containing the headers. |
fc7ec1d9 | 113 | |
114 | print $c->request->headers->header('X-Catalyst'); | |
115 | ||
b22c6668 | 116 | =item $req->hostname |
0556eb49 | 117 | |
118 | Contains the remote hostname. | |
119 | ||
120 | print $c->request->hostname | |
121 | ||
b22c6668 | 122 | =item $req->match |
fc7ec1d9 | 123 | |
124 | Contains the match. | |
125 | ||
126 | print $c->request->match; | |
127 | ||
b5176d9e | 128 | =item $req->method |
129 | ||
130 | Contains the request method (C<GET>, C<POST>, C<HEAD>, etc). | |
131 | ||
132 | print $c->request->method | |
133 | ||
b22c6668 | 134 | =item $req->parameters |
135 | ||
136 | =item $req->params | |
fc7ec1d9 | 137 | |
b22c6668 | 138 | Returns a reference to a hash containing the parameters. |
fc7ec1d9 | 139 | |
140 | print $c->request->parameters->{foo}; | |
141 | ||
b22c6668 | 142 | =item $req->path |
fc7ec1d9 | 143 | |
144 | Contains the path. | |
145 | ||
146 | print $c->request->path; | |
147 | ||
b5176d9e | 148 | =item $req->referer |
fc7ec1d9 | 149 | |
b5176d9e | 150 | Shortcut to $req->headers->referer |
fc7ec1d9 | 151 | |
b22c6668 | 152 | =item $req->snippets |
fc7ec1d9 | 153 | |
b22c6668 | 154 | Returns a reference to an array containing regex snippets. |
fc7ec1d9 | 155 | |
156 | my @snippets = @{ $c->request->snippets }; | |
157 | ||
b22c6668 | 158 | =item $req->uploads |
fc7ec1d9 | 159 | |
b22c6668 | 160 | Returns a reference to a hash containing the uploads. |
fc7ec1d9 | 161 | |
7833fdfc | 162 | my $filename = $c->req->parameters->{foo}; |
0ea0c2c3 | 163 | print $c->request->uploads->{$filename}->{type}; |
164 | print $c->request->uploads->{$filename}->{size}; | |
165 | my $fh = $c->request->uploads->{$filename}->{fh}; | |
7833fdfc | 166 | my $content = do { local $/; <$fh> }; |
fc7ec1d9 | 167 | |
b5176d9e | 168 | =item $req->user_agent |
169 | ||
170 | Shortcut to $req->headers->user_agent | |
171 | ||
b22c6668 | 172 | =back |
173 | ||
fc7ec1d9 | 174 | =head1 AUTHOR |
175 | ||
176 | Sebastian Riedel, C<sri@cpan.org> | |
177 | ||
178 | =head1 COPYRIGHT | |
179 | ||
180 | This program is free software, you can redistribute it and/or modify it under | |
181 | the same terms as Perl itself. | |
182 | ||
183 | =cut | |
184 | ||
185 | 1; |