X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FController%2FREST.pm;h=428d7497a7ade4c3d051f0ccf2bf95e7a0462a87;hb=f5aa7d458e3df74ac047c538fe1754192c0e944c;hp=6df8461646723d3948ae1a0d6e4d1bfe86431039;hpb=47c3e6b3694ea55015f839be8f1a10e4141e6e4a;p=catagits%2FCatalyst-Action-REST.git diff --git a/lib/Catalyst/Controller/REST.pm b/lib/Catalyst/Controller/REST.pm index 6df8461..428d749 100644 --- a/lib/Catalyst/Controller/REST.pm +++ b/lib/Catalyst/Controller/REST.pm @@ -1,10 +1,8 @@ package Catalyst::Controller::REST; + use Moose; use namespace::autoclean; -our $VERSION = '1.11'; -$VERSION = eval $VERSION; - =head1 NAME Catalyst::Controller::REST - A RESTful controller @@ -562,6 +560,79 @@ sub status_gone { return 1; } +=item status_see_other + +Returns a "303 See Other" response. Takes an optional "entity" to serialize, +and a "location" where the client should redirect to. + +Example: + + $self->status_see_other( + $c, + location => $some_other_url, + entity => { + radiohead => "Is a good band!", + } + ); + +=cut + +sub status_see_other { + my $self = shift; + my $c = shift; + my %p = Params::Validate::validate( + @_, + { + location => { type => SCALAR | OBJECT }, + entity => { optional => 1 }, + }, + ); + + $c->response->status(303); + $c->response->header( 'Location' => $p{location} ); + $self->_set_entity( $c, $p{'entity'} ); + return 1; +} + +=item status_moved + +Returns a "301 MOVED" response. Takes an "entity" to serialize, and a +"location" where the created object can be found. + +Example: + + $self->status_moved( + $c, + location => '/somewhere/else', + entity => { + radiohead => "Is a good band!", + }, + ); + +=cut + +sub status_moved { + my $self = shift; + my $c = shift; + my %p = Params::Validate::validate( + @_, + { + location => { type => SCALAR | OBJECT }, + entity => { optional => 1 }, + }, + ); + + my $location = ref $p{location} + ? $p{location}->as_string + : $p{location} + ; + + $c->response->status(301); + $c->response->header( Location => $location ); + $self->_set_entity($c, $p{entity}); + return 1; +} + sub _set_entity { my $self = shift; my $c = shift;