Added body_ref and body_length and minor optimization, use refs where it's possible
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Response.pm
CommitLineData
fc7ec1d9 1package Catalyst::Response;
2
3use strict;
4use base 'Class::Accessor::Fast';
5
e060fe05 6__PACKAGE__->mk_accessors(qw/cookies body headers redirect status/);
7
8*output = \&body;
fc7ec1d9 9
f7e4e231 10sub content_encoding { shift->headers->content_encoding(@_) }
11sub content_length { shift->headers->content_length(@_) }
12sub content_type { shift->headers->content_type(@_) }
13sub header { shift->headers->header(@_) }
14
fc7ec1d9 15=head1 NAME
16
17Catalyst::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
35See also L<Catalyst::Application>.
fc7ec1d9 36
37=head1 DESCRIPTION
38
61b1e958 39This is the Catalyst Response class, which provides a set of accessors
40to 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 50Contains the final output.
06e1b616 51
8fbcd90c 52=item $resp->body_length
53
54Returns the length of body in bytes.
55
56 print $c->response->body_length
57
58=cut
59
60sub 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
71Returns a reference to body.
72
73=cut
74
75sub body_ref {
76 my $self = shift;
77 return \$self->{body};
78}
79
b5176d9e 80=item $resp->content_encoding
81
82Shortcut to $resp->headers->content_encoding
83
84=item $resp->content_length
85
86Shortcut to $resp->headers->content_length
87
88=item $resp->content_type
89
90Shortcut to $resp->headers->content_type
91
b22c6668 92=item $resp->cookies
fc7ec1d9 93
61b1e958 94Returns 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
100Shortcut to $resp->headers->header
101
b22c6668 102=item $resp->headers
fc7ec1d9 103
104Returns 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 110Shortcut to $resp->body
fc7ec1d9 111
b22c6668 112=item $resp->redirect($url)
fc7ec1d9 113
114Contains a location to redirect to.
115
116 $c->response->redirect('http://slashdot.org');
117
b22c6668 118=item status
fc7ec1d9 119
120Contains the HTTP status.
121
122 $c->response->status(404);
123
b22c6668 124=back
125
fc7ec1d9 126=head1 AUTHOR
127
128Sebastian Riedel, C<sri@cpan.org>
61b1e958 129Marcus Ramberg, C<mramberg@cpan.org>
fc7ec1d9 130
131=head1 COPYRIGHT
132
61b1e958 133This program is free software, you can redistribute it and/or modify
134it under the same terms as Perl itself.
fc7ec1d9 135
136=cut
137
1381;