Updated catalyst.pl
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Response.pm
CommitLineData
fc7ec1d9 1package Catalyst::Response;
2
3use strict;
4use base 'Class::Accessor::Fast';
5
73a52566 6__PACKAGE__->mk_accessors(qw/cookies body headers location status/);
e060fe05 7
8*output = \&body;
fc7ec1d9 9
f7e4e231 10sub content_encoding { shift->headers->content_encoding(@_) }
fbcc39ad 11sub content_length { shift->headers->content_length(@_) }
12sub content_type { shift->headers->content_type(@_) }
13sub header { shift->headers->header(@_) }
f7e4e231 14
fc7ec1d9 15=head1 NAME
16
910410b8 17Catalyst::Response - stores output responding to the current client request
fc7ec1d9 18
19=head1 SYNOPSIS
20
fbcc39ad 21 $res = $c->response;
22 $res->body;
23 $res->content_encoding;
24 $res->content_length;
25 $res->content_type;
26 $res->cookies;
fbcc39ad 27 $res->header;
28 $res->headers;
29 $res->output;
30 $res->redirect;
31 $res->status;
32 $res->write;
b22c6668 33
fc7ec1d9 34=head1 DESCRIPTION
35
910410b8 36This is the Catalyst Response class, which provides methods for responding to
37the current client request.
b22c6668 38
39=head1 METHODS
fc7ec1d9 40
b22c6668 41=over 4
fc7ec1d9 42
fbcc39ad 43=item $res->body($text)
e060fe05 44
45 $c->response->body('Catalyst rocks!');
06e1b616 46
910410b8 47Sets or returns the output (text or binary data).
06e1b616 48
fbcc39ad 49=item $res->content_encoding
b5176d9e 50
910410b8 51Shortcut for $res->headers->content_encoding.
b5176d9e 52
fbcc39ad 53=item $res->content_length
b5176d9e 54
910410b8 55Shortcut for $res->headers->content_length.
b5176d9e 56
fbcc39ad 57=item $res->content_type
b5176d9e 58
910410b8 59Shortcut for $res->headers->content_type.
b5176d9e 60
fbcc39ad 61=item $res->cookies
fc7ec1d9 62
910410b8 63Returns a reference to a hash containing cookies to be set. The keys of the
64hash are the cookies' names, and their corresponding values are hash
65references used to construct a L<CGI::Cookie> object.
fc7ec1d9 66
67 $c->response->cookies->{foo} = { value => '123' };
68
910410b8 69The keys of the hash reference on the right correspond to the L<CGI::Cookie>
70parameters of the same name, except they are used without a leading dash.
71Possible parameters are:
ac965e92 72
73=over 4
74
75=item value
76
77=item expires
78
79=item domain
80
81=item path
82
83=item secure
84
ac965e92 85=back
86
fbcc39ad 87=item $res->header
88
910410b8 89Shortcut for $res->headers->header.
fbcc39ad 90
91=item $res->headers
fc7ec1d9 92
910410b8 93Returns an L<HTTP::Headers> object, which can be used to set headers.
fc7ec1d9 94
95 $c->response->headers->header( 'X-Catalyst' => $Catalyst::VERSION );
96
fbcc39ad 97=item $res->output
fc7ec1d9 98
910410b8 99Alias for $res->body.
fc7ec1d9 100
fbcc39ad 101=item $res->redirect( $url, $status )
fc7ec1d9 102
910410b8 103Causes the response to redirect to the specified URL.
fc7ec1d9 104
73a52566 105 $c->response->redirect( 'http://slashdot.org' );
106 $c->response->redirect( 'http://slashdot.org', 307 );
107
108=cut
109
110sub redirect {
111 my $self = shift;
fbcc39ad 112
113 if (@_) {
73a52566 114 my $location = shift;
115 my $status = shift || 302;
116
117 $self->location($location);
118 $self->status($status);
119 }
120
121 return $self->location;
122}
fc7ec1d9 123
fbcc39ad 124=item $res->status
fc7ec1d9 125
910410b8 126Sets or returns the HTTP status.
fc7ec1d9 127
128 $c->response->status(404);
fbcc39ad 129
130=item $res->write( $data )
131
132Writes $data to the output stream.
133
134=cut
135
136sub write { shift->{_context}->write(@_); }
fc7ec1d9 137
b22c6668 138=back
139
910410b8 140=head1 AUTHORS
fc7ec1d9 141
142Sebastian Riedel, C<sri@cpan.org>
910410b8 143
61b1e958 144Marcus Ramberg, C<mramberg@cpan.org>
fc7ec1d9 145
146=head1 COPYRIGHT
147
61b1e958 148This program is free software, you can redistribute it and/or modify
149it under the same terms as Perl itself.
fc7ec1d9 150
151=cut
152
1531;