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