Document C::Request and C::Response
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Request.pm
1 package Catalyst::Request;
2
3 use strict;
4 use base 'Class::Accessor::Fast';
5
6 __PACKAGE__->mk_accessors(
7     qw/action address arguments base cookies headers hostname match method
8       parameters path snippets uploads/
9 );
10
11 *args   = \&arguments;
12 *params = \&parameters;
13
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
21 =head1 NAME
22
23 Catalyst::Request - Catalyst Request Class
24
25 =head1 SYNOPSIS
26
27
28     $req = $c->request;
29     $req->action;
30     $req->address;
31     $req->args;
32     $req->arguments;
33     $req->base;
34     $req->content_encoding;
35     $req->content_length;
36     $req->content_type;
37     $req->cookies;
38     $req->header;
39     $req->headers;
40     $req->hostname;
41     $req->match;
42     $req->method;
43     $req->parameters;
44     $req->params;
45     $req->path;
46     $req->referer;
47     $req->snippets;
48     $req->uploads;
49     $req->user_agent
50
51 See also L<Catalyst>.
52
53 =head1 DESCRIPTION
54
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
61
62 =over 4
63
64 =item $req->action
65
66 Contains the action.
67
68     print $c->request->action;
69
70 =item $req->address
71
72 Contains the remote address.
73
74     print $c->request->address
75
76 =item $req->arguments
77
78 =item $req->args
79
80 Returns a reference to an array containing the arguments.
81
82     print $c->request->arguments->[0];
83
84 =item $req->base
85
86 Contains the uri base.
87
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
100 =item $req->cookies
101
102 Returns a reference to a hash containing the cookies.
103
104     print $c->request->cookies->{mycookie}->value;
105
106 =item $req->header
107
108 Shortcut to $req->headers->header
109
110 =item $req->headers
111
112 Returns an L<HTTP::Headers> object containing the headers.
113
114     print $c->request->headers->header('X-Catalyst');
115
116 =item $req->hostname
117
118 Contains the remote hostname.
119
120     print $c->request->hostname
121
122 =item $req->match
123
124 Contains the match.
125
126     print $c->request->match;
127
128 =item $req->method
129
130 Contains the request method (C<GET>, C<POST>, C<HEAD>, etc).
131
132     print $c->request->method
133
134 =item $req->parameters
135
136 =item $req->params
137
138 Returns a reference to a hash containing the parameters.
139
140     print $c->request->parameters->{foo};
141
142 =item $req->path
143
144 Contains the path.
145
146     print $c->request->path;
147
148 =item $req->referer
149
150 Shortcut to $req->headers->referer
151
152 =item $req->snippets
153
154 Returns a reference to an array containing regex snippets.
155
156     my @snippets = @{ $c->request->snippets };
157
158 =item $req->uploads
159
160 Returns a reference to a hash containing the uploads.
161
162     my $filename = $c->req->parameters->{foo};
163     print $c->request->uploads->{$filename}->{type};
164     print $c->request->uploads->{$filename}->{size};
165     my $fh = $c->request->uploads->{$filename}->{fh};
166     my $content = do { local $/; <$fh> };
167
168 =item $req->user_agent
169
170 Shortcut to $req->headers->user_agent
171
172 =back
173
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;