X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FResponse.pm;h=18930dac4798d7ed09991a2697df49f72588c62a;hp=a433f027264327055552150b6e6da05365e121e3;hb=74dafab798a163c251e09de7fcc21a267d1678a6;hpb=8fbcd90cdb30aed53d22d1cdbad95880f1c11693 diff --git a/lib/Catalyst/Response.pm b/lib/Catalyst/Response.pm index a433f02..18930da 100644 --- a/lib/Catalyst/Response.pm +++ b/lib/Catalyst/Response.pm @@ -3,14 +3,14 @@ package Catalyst::Response; 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 @@ -18,19 +18,18 @@ Catalyst::Response - Catalyst Response Class =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. @@ -43,83 +42,80 @@ to response data. =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 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 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