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.
43 =item $res->body($text)
45 $c->response->body('Catalyst rocks!');
47 Sets or returns the output (text or binary data).
49 =item $res->content_encoding
51 Shortcut for $res->headers->content_encoding.
53 =item $res->content_length
55 Shortcut for $res->headers->content_length.
57 =item $res->content_type
59 Shortcut for $res->headers->content_type.
63 Returns a reference to a hash containing cookies to be set. The keys of the
64 hash are the cookies' names, and their corresponding values are hash
65 references used to construct a L<CGI::Cookie> object.
67 $c->response->cookies->{foo} = { value => '123' };
69 The keys of the hash reference on the right correspond to the L<CGI::Cookie>
70 parameters of the same name, except they are used without a leading dash.
71 Possible parameters are:
89 Shortcut for $res->headers->header.
93 Returns an L<HTTP::Headers> object, which can be used to set headers.
95 $c->response->headers->header( 'X-Catalyst' => $Catalyst::VERSION );
101 =item $res->redirect( $url, $status )
103 Causes the response to redirect to the specified URL.
105 $c->response->redirect( 'http://slashdot.org' );
106 $c->response->redirect( 'http://slashdot.org', 307 );
114 my $location = shift;
115 my $status = shift || 302;
117 $self->location($location);
118 $self->status($status);
121 return $self->location;
126 Sets or returns the HTTP status.
128 $c->response->status(404);
130 =item $res->write( $data )
132 Writes $data to the output stream.
136 sub write { shift->{_context}->write(@_); }
142 Sebastian Riedel, C<sri@cpan.org>
144 Marcus Ramberg, C<mramberg@cpan.org>
148 This program is free software, you can redistribute it and/or modify
149 it under the same terms as Perl itself.