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