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