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 - Catalyst Response Class
23 $res->content_encoding;
35 See also L<Catalyst::Application>.
39 This is the Catalyst Response class, which provides a set of accessors
46 =item $res->body($text)
48 $c->response->body('Catalyst rocks!');
50 Contains the final output.
52 =item $res->content_encoding
54 Shortcut to $res->headers->content_encoding
56 =item $res->content_length
58 Shortcut to $res->headers->content_length
60 =item $res->content_type
62 Shortcut to $res->headers->content_type
66 Returns a reference to a hash containing the cookies to be set.
68 $c->response->cookies->{foo} = { value => '123' };
77 my ( $self, $handle ) = @_;
80 $self->{handle} = $handle;
83 # Finalize headers if someone touches the output handle
84 if ( $self->{_context} ) {
85 $self->{_context}->finalize_headers;
89 return $self->{handle};
94 Shortcut to $res->headers->header
98 Returns a L<HTTP::Headers> object containing the headers.
100 $c->response->headers->header( 'X-Catalyst' => $Catalyst::VERSION );
104 Shortcut to $res->body
106 =item $res->redirect( $url, $status )
108 Contains a location to redirect to.
110 $c->response->redirect( 'http://slashdot.org' );
111 $c->response->redirect( 'http://slashdot.org', 307 );
119 my $location = shift;
120 my $status = shift || 302;
122 $self->location($location);
123 $self->status($status);
126 return $self->location;
131 Contains the HTTP status.
133 $c->response->status(404);
135 =item $res->write( $data )
137 Writes $data to the output stream.
141 sub write { shift->{_context}->write(@_); }
147 Sebastian Riedel, C<sri@cpan.org>
148 Marcus Ramberg, C<mramberg@cpan.org>
152 This program is free software, you can redistribute it and/or modify
153 it under the same terms as Perl itself.