From: adam Date: Tue, 17 Oct 2006 22:41:52 +0000 (+0000) Subject: Added more status_ actions X-Git-Tag: 0.67_01~68 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Action-REST.git;a=commitdiff_plain;h=bb4130f6a50a3fee070d2ce81311fb019166d3a5 Added more status_ actions Fixed dispatch to work with Chained actions --- diff --git a/lib/Catalyst/Action/REST.pm b/lib/Catalyst/Action/REST.pm index 5c0d112..54ade49 100644 --- a/lib/Catalyst/Action/REST.pm +++ b/lib/Catalyst/Action/REST.pm @@ -57,15 +57,16 @@ mechanism described above. =cut sub dispatch { - my ( $self, $c ) = @_; + my $self = shift; + my $c = shift; my $controller = $self->class; my $method = $self->name . "_" . uc( $c->request->method ); if ( $controller->can($method) ) { - return $controller->$method($c); + return $controller->$method($c, @{$c->req->args}); } else { $self->_return_405($c); - return $c->execute( $self->class, $self ); + return $c->execute( $self->class, $self, @{$c->req->args} ); } } diff --git a/lib/Catalyst/Controller/REST.pm b/lib/Catalyst/Controller/REST.pm index b915203..0b1aaca 100644 --- a/lib/Catalyst/Controller/REST.pm +++ b/lib/Catalyst/Controller/REST.pm @@ -22,6 +22,11 @@ sub begin : ActionClass('Deserialize') {} sub end : ActionClass('Serialize') { } +# You probably want to refer to the HTTP 1.1 Spec for these; they should +# conform as much as possible. +# +# ftp://ftp.isi.edu/in-notes/rfc2616.txt + sub status_created { my $self = shift; my $c = shift; @@ -38,8 +43,44 @@ sub status_created { } $c->response->status(201); $c->response->header('Location' => $location); - if (exists($p{'entity'})) { - $c->stash->{$self->config->{'serialize'}->{'stash_key'}} = $p{'entity'}; + $self->_set_entity($c, $p{'entity'}); + return 1; +} + +sub status_ok { + my $self = shift; + my $c = shift; + my %p = validate(@_, + { + entity => 1, + }, + ); + + $c->response->status(200); + $self->_set_entity($c, $p{'entity'}); + return 1; +} + +sub status_not_found { + my $self = shift; + my $c = shift; + my %p = validate(@_, + { + message => { type => SCALAR }, + }, + ); + + $c->response->status(404); + $c->response->body($p{'message'}); + return 1; +} + +sub _set_entity { + my $self = shift; + my $c = shift; + my $entity = shift; + if (defined($entity)) { + $c->stash->{$self->config->{'serialize'}->{'stash_key'}} = $entity; } return 1; }