use strict;
use base 'Class::Accessor::Fast';
-__PACKAGE__->mk_accessors(qw/cookies body headers redirect status/);
+__PACKAGE__->mk_accessors(qw/cookies body headers location status/);
*output = \&body;
sub content_encoding { shift->headers->content_encoding(@_) }
-sub content_length { shift->headers->content_length(@_) }
-sub content_type { shift->headers->content_type(@_) }
-sub header { shift->headers->header(@_) }
+sub content_length { shift->headers->content_length(@_) }
+sub content_type { shift->headers->content_type(@_) }
+sub header { shift->headers->header(@_) }
=head1 NAME
=head1 SYNOPSIS
- $resp = $c->response;
- $resp->body;
- $resp->body_length;
- $resp->body_ref;
- $resp->content_encoding;
- $resp->content_length;
- $resp->content_type;
- $resp->cookies;
- $resp->header;
- $resp->headers;
- $resp->output;
- $resp->redirect;
- $resp->status;
+ $res = $c->response;
+ $res->body;
+ $res->content_encoding;
+ $res->content_length;
+ $res->content_type;
+ $res->cookies;
+ $res->header;
+ $res->headers;
+ $res->output;
+ $res->redirect;
+ $res->status;
+ $res->write;
See also L<Catalyst::Application>.
=over 4
-=item $resp->body($text)
+=item $res->body($text)
$c->response->body('Catalyst rocks!');
Contains the final output.
-=item $resp->body_length
+=item $res->content_encoding
-Returns the length of body in bytes.
+Shortcut to $res->headers->content_encoding
- print $c->response->body_length
+=item $res->content_length
-=cut
+Shortcut to $res->headers->content_length
-sub body_length {
- my $self = shift;
-
- use bytes;
-
- return 0 unless $self->body;
- return length($self->body);
-}
-
-=item $resp->body_ref
+=item $res->content_type
-Returns a reference to body.
+Shortcut to $res->headers->content_type
-=cut
+=item $res->cookies
-sub body_ref {
- my $self = shift;
- return \$self->{body};
-}
+Returns a reference to a hash containing the cookies to be set.
-=item $resp->content_encoding
+ $c->response->cookies->{foo} = { value => '123' };
-Shortcut to $resp->headers->content_encoding
+=item $res->header
-=item $resp->content_length
+Shortcut to $res->headers->header
-Shortcut to $resp->headers->content_length
+=item $res->headers
-=item $resp->content_type
+Returns a L<HTTP::Headers> object containing the headers.
-Shortcut to $resp->headers->content_type
+ $c->response->headers->header( 'X-Catalyst' => $Catalyst::VERSION );
-=item $resp->cookies
+=item $res->output
-Returns a reference to a hash containing the cookies to be set.
+Shortcut to $res->body
- $c->response->cookies->{foo} = { value => '123' };
+=item $res->redirect( $url, $status )
-=item $resp->header
+Contains a location to redirect to.
-Shortcut to $resp->headers->header
+ $c->response->redirect( 'http://slashdot.org' );
+ $c->response->redirect( 'http://slashdot.org', 307 );
-=item $resp->headers
+=cut
-Returns a L<HTTP::Headers> object containing the headers.
+sub redirect {
+ my $self = shift;
- $c->response->headers->header( 'X-Catalyst' => $Catalyst::VERSION );
+ if (@_) {
+ my $location = shift;
+ my $status = shift || 302;
-=item $resp->output
+ $self->location($location);
+ $self->status($status);
+ }
-Shortcut to $resp->body
+ return $self->location;
+}
-=item $resp->redirect($url)
+=item $res->status
-Contains a location to redirect to.
+Contains the HTTP status.
- $c->response->redirect('http://slashdot.org');
+ $c->response->status(404);
+
+=item $res->write( $data )
-=item status
+Writes $data to the output stream.
-Contains the HTTP status.
+=cut
- $c->response->status(404);
+sub write { shift->{_context}->write(@_); }
=back