Added status_created helper method
adam [Tue, 17 Oct 2006 01:03:18 +0000 (01:03 +0000)]
Changelog
lib/Catalyst/Controller/REST.pm

index 58d83fd..f3d2ae8 100644 (file)
--- 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
index 5e6c359..b915203 100644 (file)
@@ -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;