Commit | Line | Data |
---|---|---|
fc7ec1d9 | 1 | package Catalyst::Response; |
2 | ||
3 | use strict; | |
4 | use base 'Class::Accessor::Fast'; | |
5 | ||
73a52566 | 6 | __PACKAGE__->mk_accessors(qw/cookies body headers location status/); |
e060fe05 | 7 | |
8 | *output = \&body; | |
fc7ec1d9 | 9 | |
f7e4e231 | 10 | sub content_encoding { shift->headers->content_encoding(@_) } |
fbcc39ad | 11 | sub content_length { shift->headers->content_length(@_) } |
12 | sub content_type { shift->headers->content_type(@_) } | |
13 | sub header { shift->headers->header(@_) } | |
f7e4e231 | 14 | |
fc7ec1d9 | 15 | =head1 NAME |
16 | ||
17 | Catalyst::Response - Catalyst Response Class | |
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 | |
34 | See also L<Catalyst::Application>. | |
fc7ec1d9 | 35 | |
36 | =head1 DESCRIPTION | |
37 | ||
61b1e958 | 38 | This is the Catalyst Response class, which provides a set of accessors |
39 | to response data. | |
b22c6668 | 40 | |
41 | =head1 METHODS | |
fc7ec1d9 | 42 | |
b22c6668 | 43 | =over 4 |
fc7ec1d9 | 44 | |
fbcc39ad | 45 | =item $res->body($text) |
e060fe05 | 46 | |
47 | $c->response->body('Catalyst rocks!'); | |
06e1b616 | 48 | |
e060fe05 | 49 | Contains the final output. |
06e1b616 | 50 | |
fbcc39ad | 51 | =item $res->content_encoding |
b5176d9e | 52 | |
fbcc39ad | 53 | Shortcut to $res->headers->content_encoding |
b5176d9e | 54 | |
fbcc39ad | 55 | =item $res->content_length |
b5176d9e | 56 | |
fbcc39ad | 57 | Shortcut to $res->headers->content_length |
b5176d9e | 58 | |
fbcc39ad | 59 | =item $res->content_type |
b5176d9e | 60 | |
fbcc39ad | 61 | Shortcut to $res->headers->content_type |
b5176d9e | 62 | |
fbcc39ad | 63 | =item $res->cookies |
fc7ec1d9 | 64 | |
61b1e958 | 65 | Returns a reference to a hash containing the cookies to be set. |
fc7ec1d9 | 66 | |
67 | $c->response->cookies->{foo} = { value => '123' }; | |
68 | ||
fbcc39ad | 69 | =item $res->header |
70 | ||
71 | Shortcut to $res->headers->header | |
72 | ||
73 | =item $res->headers | |
fc7ec1d9 | 74 | |
75 | Returns a L<HTTP::Headers> object containing the headers. | |
76 | ||
77 | $c->response->headers->header( 'X-Catalyst' => $Catalyst::VERSION ); | |
78 | ||
fbcc39ad | 79 | =item $res->output |
fc7ec1d9 | 80 | |
fbcc39ad | 81 | Shortcut to $res->body |
fc7ec1d9 | 82 | |
fbcc39ad | 83 | =item $res->redirect( $url, $status ) |
fc7ec1d9 | 84 | |
85 | Contains a location to redirect to. | |
86 | ||
73a52566 | 87 | $c->response->redirect( 'http://slashdot.org' ); |
88 | $c->response->redirect( 'http://slashdot.org', 307 ); | |
89 | ||
90 | =cut | |
91 | ||
92 | sub redirect { | |
93 | my $self = shift; | |
fbcc39ad | 94 | |
95 | if (@_) { | |
73a52566 | 96 | my $location = shift; |
97 | my $status = shift || 302; | |
98 | ||
99 | $self->location($location); | |
100 | $self->status($status); | |
101 | } | |
102 | ||
103 | return $self->location; | |
104 | } | |
fc7ec1d9 | 105 | |
fbcc39ad | 106 | =item $res->status |
fc7ec1d9 | 107 | |
108 | Contains the HTTP status. | |
109 | ||
110 | $c->response->status(404); | |
fbcc39ad | 111 | |
112 | =item $res->write( $data ) | |
113 | ||
114 | Writes $data to the output stream. | |
115 | ||
116 | =cut | |
117 | ||
118 | sub write { shift->{_context}->write(@_); } | |
fc7ec1d9 | 119 | |
b22c6668 | 120 | =back |
121 | ||
fc7ec1d9 | 122 | =head1 AUTHOR |
123 | ||
124 | Sebastian Riedel, C<sri@cpan.org> | |
61b1e958 | 125 | Marcus Ramberg, C<mramberg@cpan.org> |
fc7ec1d9 | 126 | |
127 | =head1 COPYRIGHT | |
128 | ||
61b1e958 | 129 | This program is free software, you can redistribute it and/or modify |
130 | it under the same terms as Perl itself. | |
fc7ec1d9 | 131 | |
132 | =cut | |
133 | ||
134 | 1; |