1 package Catalyst::Response;
4 use base 'Class::Accessor::Fast';
6 __PACKAGE__->mk_accessors(qw/cookies body headers location status/);
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(@_) }
17 Catalyst::Response - stores output responding to the current client request
23 $res->content_encoding;
36 This is the Catalyst Response class, which provides methods for responding to
37 the current client request.
41 =head2 $res->body($text)
43 $c->response->body('Catalyst rocks!');
45 Sets or returns the output (text or binary data).
47 =head2 $res->content_encoding
49 Shortcut for $res->headers->content_encoding.
51 =head2 $res->content_length
53 Shortcut for $res->headers->content_length.
55 =head2 $res->content_type
57 Shortcut for $res->headers->content_type.
61 Returns a reference to a hash containing cookies to be set. The keys of the
62 hash are the cookies' names, and their corresponding values are hash
63 references used to construct a L<CGI::Cookie> object.
65 $c->response->cookies->{foo} = { value => '123' };
67 The keys of the hash reference on the right correspond to the L<CGI::Cookie>
68 parameters of the same name, except they are used without a leading dash.
69 Possible parameters are:
83 Shortcut for $res->headers->header.
87 Returns an L<HTTP::Headers> object, which can be used to set headers.
89 $c->response->headers->header( 'X-Catalyst' => $Catalyst::VERSION );
95 =head2 $res->redirect( $url, $status )
97 Causes the response to redirect to the specified URL.
99 $c->response->redirect( 'http://slashdot.org' );
100 $c->response->redirect( 'http://slashdot.org', 307 );
108 my $location = shift;
109 my $status = shift || 302;
111 $self->location($location);
112 $self->status($status);
115 return $self->location;
120 Sets or returns the HTTP status.
122 $c->response->status(404);
124 =head2 $res->write( $data )
126 Writes $data to the output stream.
130 sub write { shift->{_context}->write(@_); }
134 Sebastian Riedel, C<sri@cpan.org>
136 Marcus Ramberg, C<mramberg@cpan.org>
140 This program is free software, you can redistribute it and/or modify
141 it under the same terms as Perl itself.