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 | ||
14 | =head1 NAME | |
15 | ||
16 | Catalyst::Request - Catalyst Request Class | |
17 | ||
18 | =head1 SYNOPSIS | |
19 | ||
b22c6668 | 20 | |
21 | $req = $c->request; | |
22 | $req->action; | |
23 | $req->address; | |
24 | $req->args; | |
25 | $req->arguments; | |
26 | $req->base; | |
27 | $req->cookies; | |
28 | $req->headers; | |
29 | $req->hostname; | |
30 | $req->match; | |
31 | $req->method; | |
32 | $req->parameters; | |
33 | $req->params; | |
34 | $req->path; | |
35 | $req->snippets; | |
36 | $req->uploads; | |
37 | ||
38 | See also L<Catalyst>. | |
fc7ec1d9 | 39 | |
40 | =head1 DESCRIPTION | |
41 | ||
b22c6668 | 42 | This is the Catalyst Request class, which provides a set of accessors to the |
43 | request data. The request object is prepared by the specialized Catalyst | |
44 | Engine module thus hiding the details of the particular engine implementation. | |
45 | ||
46 | ||
47 | =head1 METHODS | |
fc7ec1d9 | 48 | |
b22c6668 | 49 | =over 4 |
fc7ec1d9 | 50 | |
b22c6668 | 51 | =item $req->action |
fc7ec1d9 | 52 | |
53 | Contains the action. | |
54 | ||
55 | print $c->request->action; | |
56 | ||
b22c6668 | 57 | =item $req->address |
0556eb49 | 58 | |
59 | Contains the remote address. | |
60 | ||
61 | print $c->request->address | |
62 | ||
b22c6668 | 63 | =item $req->arguments |
fc7ec1d9 | 64 | |
b22c6668 | 65 | =item $req->args |
66 | ||
67 | Returns a reference to an array containing the arguments. | |
fc7ec1d9 | 68 | |
69 | print $c->request->arguments->[0]; | |
70 | ||
b22c6668 | 71 | =item $req->base |
fc7ec1d9 | 72 | |
73 | Contains the uri base. | |
74 | ||
b22c6668 | 75 | =item $req->cookies |
fc7ec1d9 | 76 | |
b22c6668 | 77 | Returns a reference to a hash containing the cookies. |
fc7ec1d9 | 78 | |
79 | print $c->request->cookies->{mycookie}->value; | |
80 | ||
b22c6668 | 81 | =item $req->headers |
fc7ec1d9 | 82 | |
b22c6668 | 83 | Returns an L<HTTP::Headers> object containing the headers. |
fc7ec1d9 | 84 | |
85 | print $c->request->headers->header('X-Catalyst'); | |
86 | ||
b22c6668 | 87 | =item $req->hostname |
0556eb49 | 88 | |
89 | Contains the remote hostname. | |
90 | ||
91 | print $c->request->hostname | |
92 | ||
b22c6668 | 93 | =item $req->match |
fc7ec1d9 | 94 | |
95 | Contains the match. | |
96 | ||
97 | print $c->request->match; | |
98 | ||
b22c6668 | 99 | =item $req->parameters |
100 | ||
101 | =item $req->params | |
fc7ec1d9 | 102 | |
b22c6668 | 103 | Returns a reference to a hash containing the parameters. |
fc7ec1d9 | 104 | |
105 | print $c->request->parameters->{foo}; | |
106 | ||
b22c6668 | 107 | =item $req->path |
fc7ec1d9 | 108 | |
109 | Contains the path. | |
110 | ||
111 | print $c->request->path; | |
112 | ||
b22c6668 | 113 | =item $req->method |
fc7ec1d9 | 114 | |
b22c6668 | 115 | Contains the request method (C<GET>, C<POST>, C<HEAD>, etc). |
fc7ec1d9 | 116 | |
117 | print $c->request->method | |
118 | ||
b22c6668 | 119 | =item $req->snippets |
fc7ec1d9 | 120 | |
b22c6668 | 121 | Returns a reference to an array containing regex snippets. |
fc7ec1d9 | 122 | |
123 | my @snippets = @{ $c->request->snippets }; | |
124 | ||
b22c6668 | 125 | =item $req->uploads |
fc7ec1d9 | 126 | |
b22c6668 | 127 | Returns a reference to a hash containing the uploads. |
fc7ec1d9 | 128 | |
7833fdfc | 129 | my $filename = $c->req->parameters->{foo}; |
0ea0c2c3 | 130 | print $c->request->uploads->{$filename}->{type}; |
131 | print $c->request->uploads->{$filename}->{size}; | |
132 | my $fh = $c->request->uploads->{$filename}->{fh}; | |
7833fdfc | 133 | my $content = do { local $/; <$fh> }; |
fc7ec1d9 | 134 | |
b22c6668 | 135 | =back |
136 | ||
fc7ec1d9 | 137 | =head1 AUTHOR |
138 | ||
139 | Sebastian Riedel, C<sri@cpan.org> | |
140 | ||
141 | =head1 COPYRIGHT | |
142 | ||
143 | This program is free software, you can redistribute it and/or modify it under | |
144 | the same terms as Perl itself. | |
145 | ||
146 | =cut | |
147 | ||
148 | 1; |