X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FController%2FREST.pm;h=d185a0bb31c15af0c1d0b7150dd3d651e42f3e34;hb=bbf0feae0566317258d7bdd47d70a0b68a2a583f;hp=6016c656d3a5a9c141e02cc900ad76523753050c;hpb=21d3f6aeb5d5150d2709f9a3d0647d21e9d74d9b;p=catagits%2FCatalyst-Action-REST.git diff --git a/lib/Catalyst/Controller/REST.pm b/lib/Catalyst/Controller/REST.pm index 6016c65..d185a0b 100644 --- a/lib/Catalyst/Controller/REST.pm +++ b/lib/Catalyst/Controller/REST.pm @@ -1,6 +1,9 @@ package Catalyst::Controller::REST; +use strict; +use warnings; -our $VERSION = '0.74'; +our $VERSION = '0.75'; +$VERSION = eval $VERSION; =head1 NAME @@ -209,8 +212,6 @@ such require you pass the current context ($c) as the first argument. =cut -use strict; -use warnings; use base 'Catalyst::Controller'; use Params::Validate qw(SCALAR OBJECT); @@ -331,6 +332,20 @@ sub status_accepted { return 1; } +=item status_no_content + +Returns a "204 NO CONTENT" response. + +=cut + +sub status_no_content { + my $self = shift; + my $c = shift; + $c->response->status(204); + $self->_set_entity( $c, undef ); + return 1.; +} + =item status_bad_request Returns a "400 BAD REQUEST" response. Takes a "message" argument @@ -383,6 +398,31 @@ sub status_not_found { return 1; } +=item gone + +Returns a "41O GONE" response. Takes a "message" argument as a scalar, +which will become the value of "error" in the serialized response. + +Example: + + $self->status_gone( + $c, + message => "The document have been deleted by foo", + ); + +=cut + +sub status_gone { + my $self = shift; + my $c = shift; + my %p = Params::Validate::validate( @_, { message => { type => SCALAR }, }, ); + + $c->response->status(410); + $c->log->debug( "Status Gone " . $p{'message'} ) if $c->debug; + $self->_set_entity( $c, { error => $p{'message'} } ); + return 1; +} + sub _set_entity { my $self = shift; my $c = shift;