From bbf0feae0566317258d7bdd47d70a0b68a2a583f Mon Sep 17 00:00:00 2001 From: franck cuny Date: Thu, 20 Aug 2009 11:57:31 +0200 Subject: [PATCH] add status for no content and gone --- lib/Catalyst/Controller/REST.pm | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/Catalyst/Controller/REST.pm b/lib/Catalyst/Controller/REST.pm index f4edc32..d185a0b 100644 --- a/lib/Catalyst/Controller/REST.pm +++ b/lib/Catalyst/Controller/REST.pm @@ -332,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 @@ -384,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;