From: adam Date: Tue, 17 Oct 2006 01:03:18 +0000 (+0000) Subject: Added status_created helper method X-Git-Tag: 1.08~297 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5511d1ff8e88a0c28611b903a15f513e74dab6d0;p=catagits%2FCatalyst-Action-Serialize-Data-Serializer.git Added status_created helper method --- diff --git a/Changelog b/Changelog index 58d83fd..f3d2ae8 100644 --- a/Changelog +++ b/Changelog @@ -2,3 +2,4 @@ Mon Oct 16 14:48:54 PDT 2006 (adam) Added in Test Suite Created Catalyst::Action::Serialize and Catalyst::Action::Deserialize Added Data::Serializer actions + Added status_created helper method diff --git a/lib/Catalyst/Controller/REST.pm b/lib/Catalyst/Controller/REST.pm index 5e6c359..b915203 100644 --- a/lib/Catalyst/Controller/REST.pm +++ b/lib/Catalyst/Controller/REST.pm @@ -3,6 +3,7 @@ package Catalyst::Controller::REST; use strict; use warnings; use base 'Catalyst::Controller'; +use Params::Validate qw(:all); __PACKAGE__->mk_accessors(qw(serialize)); @@ -17,10 +18,30 @@ __PACKAGE__->config( } ); -sub begin : ActionClass('Deserialize') { -} +sub begin : ActionClass('Deserialize') {} + +sub end : ActionClass('Serialize') { } + +sub status_created { + my $self = shift; + my $c = shift; + my %p = validate(@_, + { + location => { type => SCALAR | OBJECT }, + entity => { optional => 1 }, + }, + ); -sub end : ActionClass('Serialize') { + my $location; + if (ref($p{'location'})) { + $location = $p{'location'}->as_string; + } + $c->response->status(201); + $c->response->header('Location' => $location); + if (exists($p{'entity'})) { + $c->stash->{$self->config->{'serialize'}->{'stash_key'}} = $p{'entity'}; + } + return 1; } 1;