Added recursive -r flag to prove example
[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(@_) }
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;
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
33See also L<Catalyst::Application>.
fc7ec1d9 34
35=head1 DESCRIPTION
36
61b1e958 37This is the Catalyst Response class, which provides a set of accessors
38to 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 48Contains the final output.
06e1b616 49
b5176d9e 50=item $resp->content_encoding
51
52Shortcut to $resp->headers->content_encoding
53
54=item $resp->content_length
55
56Shortcut to $resp->headers->content_length
57
58=item $resp->content_type
59
60Shortcut to $resp->headers->content_type
61
b22c6668 62=item $resp->cookies
fc7ec1d9 63
61b1e958 64Returns 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
70Shortcut to $resp->headers->header
71
b22c6668 72=item $resp->headers
fc7ec1d9 73
74Returns 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 80Shortcut to $resp->body
fc7ec1d9 81
73a52566 82=item $resp->redirect( $url, $status )
fc7ec1d9 83
84Contains 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
91sub 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
107Contains the HTTP status.
108
109 $c->response->status(404);
110
b22c6668 111=back
112
fc7ec1d9 113=head1 AUTHOR
114
115Sebastian Riedel, C<sri@cpan.org>
61b1e958 116Marcus Ramberg, C<mramberg@cpan.org>
fc7ec1d9 117
118=head1 COPYRIGHT
119
61b1e958 120This program is free software, you can redistribute it and/or modify
121it under the same terms as Perl itself.
fc7ec1d9 122
123=cut
124
1251;