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