Subject: | Code Submission for Catalyst::Controller::REST |
Date: | Wed, 12 Oct 2011 16:29:18 -0400 |
To: | bug-Catalyst-Action-REST [...] rt.cpan.org |
From: | Matthew Keller <kellermg [...] gmail.com> |
Hi,
I've needed to extend Catalyst::Controller::REST to deal with tracked
relocations of content- mainly database documents that have relocated.
Anyhow, this is cloned from sub status_created, and could be easily
integrated into your next release. Consider any copyright waived, feel
free to tweak, etc. etc.
=item status_moved
Returns a "301 MOVED" response. Takes an "entity" to serialize,
and a "location" where the created object can be found.
Example:
$self->status_moved(
$c,
location => '/somewhere/else',
entity => {
radiohead => "Is a good band!",
}
);
=cut
sub status_moved {
my $self = shift;
my $c = shift;
my %p = Params::Validate::validate(
@_,
{
location => { type => SCALAR | OBJECT },
entity => { optional => 1 },
},
);
my $location;
if ( ref( $p{'location'} ) ) {
$location = $p{'location'}->as_string;
} else {
$location = $p{'location'};
}
$c->response->status(301);
$c->response->header( 'Location' => $location );
$self->_set_entity( $c, $p{'entity'} );
return 1;
}