revised documentation for 5.0
[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 requested 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->args
77
78 Shortcut for arguments
79
80 =item $req->arguments
81
82 Returns a reference to an array containing the arguments.
83
84     print $c->request->arguments->[0];
85
86 =item $req->base
87
88 Contains the url base. This will always have a trailing slash.
89
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
102 =item $req->cookies
103
104 Returns a reference to a hash containing the cookies.
105
106     print $c->request->cookies->{mycookie}->value;
107
108 =item $req->header
109
110 Shortcut to $req->headers->header
111
112 =item $req->headers
113
114 Returns an L<HTTP::Headers> object containing the headers.
115
116     print $c->request->headers->header('X-Catalyst');
117
118 =item $req->hostname
119
120 Contains the hostname of the remote user.
121
122     print $c->request->hostname
123
124 =item $req->match
125
126 This contains be the matching part of a regexp action. otherwise it 
127 returns the same as 'action'.
128
129     print $c->request->match;
130
131 =item $req->method
132
133 Contains the request method (C<GET>, C<POST>, C<HEAD>, etc).
134
135     print $c->request->method
136
137 =item $req->params
138
139 Shortcut for $req->parameters.
140
141 =item $req->parameters
142
143 Returns a reference to a hash containing the parameters.
144
145     print $c->request->parameters->{foo};
146
147 =item $req->path
148
149 Contains the path.
150
151     print $c->request->path;
152
153 =item $req->referer
154
155 Shortcut to $req->headers->referer. Referring page.
156
157 =item $req->snippets
158
159 Returns a reference to an array containing regex snippets.
160
161     my @snippets = @{ $c->request->snippets };
162
163 =item $req->uploads
164
165 Returns a reference to a hash containing the uploads.
166
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> };
172
173 =item $req->user_agent
174
175 Shortcut to $req->headers->user_agent. User Agent version string.
176
177 =back
178
179 =head1 AUTHOR
180
181 Sebastian Riedel, C<sri@cpan.org>
182 Marcus Ramberg, C<mramberg@cpan.org>
183
184 =head1 COPYRIGHT
185
186 This program is free software, you can redistribute it and/or modify 
187 it under the same terms as Perl itself.
188
189 =cut
190
191 1;