X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FResponse.pm;h=a6fbf0f1a750653f0ad113148fe568413cbae061;hb=dcc61a75845d35ef799c6693d3ff514ab46dcb33;hp=a433f027264327055552150b6e6da05365e121e3;hpb=8fbcd90cdb30aed53d22d1cdbad95880f1c11693;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Response.pm b/lib/Catalyst/Response.pm index a433f02..a6fbf0f 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,103 @@ 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 $res->content_type -=item $resp->body_ref +Shortcut to $res->headers->content_type -Returns a reference to body. +=item $res->cookies -=cut +Returns a reference to a hash containing the cookies to be set. The keys of the +hash are the cookies' names, and their corresponding values are hash references +used to construct L object. -sub body_ref { - my $self = shift; - return \$self->{body}; -} + $c->response->cookies->{foo} = { value => '123' }; -=item $resp->content_encoding +The values correspond to the L parameters of the same name, except +they are used without a leading dash. -Shortcut to $resp->headers->content_encoding +The proxied parameters are -=item $resp->content_length +=over 4 -Shortcut to $resp->headers->content_length +=item value -=item $resp->content_type +=item expires -Shortcut to $resp->headers->content_type +=item domain -=item $resp->cookies +=item path -Returns a reference to a hash containing the cookies to be set. +=item secure - $c->response->cookies->{foo} = { value => '123' }; +=item -=item $resp->header +=back + +=item $res->header -Shortcut to $resp->headers->header +Shortcut to $res->headers->header -=item $resp->headers +=item $res->headers Returns a L object containing the headers. $c->response->headers->header( 'X-Catalyst' => $Catalyst::VERSION ); -=item $resp->output +=item $res->output -Shortcut to $resp->body +Shortcut to $res->body -=item $resp->redirect($url) +=item $res->redirect( $url, $status ) Contains a location to redirect to. - $c->response->redirect('http://slashdot.org'); + $c->response->redirect( 'http://slashdot.org' ); + $c->response->redirect( 'http://slashdot.org', 307 ); -=item status +=cut + +sub redirect { + my $self = shift; + + if (@_) { + my $location = shift; + my $status = shift || 302; + + $self->location($location); + $self->status($status); + } + + return $self->location; +} + +=item $res->status Contains the HTTP status. $c->response->status(404); + +=item $res->write( $data ) + +Writes $data to the output stream. + +=cut + +sub write { shift->{_context}->write(@_); } =back