Skip to content

Commit 0aceaa9

Browse files
author
Arthur Axel 'fREW' Schmidt
committed
fix missing v1.15
1 parent 9b5736d commit 0aceaa9

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed

Changes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ Revision history for {{$dist->name}}
22

33
{{$NEXT}}
44

5+
1.15 2014-05-07 09:02:44-05:00 CST6CDT
6+
7+
* Added new status_see_other method for returning a 303 redirect.
8+
* Added new status_moved method for returning a 301 redirect. (Matthew Keller)
9+
510
1.14 2013-12-27 15:32:19 America/Chicago
611

712
* Stop prompting for features at install time

dist.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = Catalyst-Action-REST
22
author = Tomas Doran <bobtfish@cpan.org>
33
license = Perl_5
44
copyright_holder = Tomas Doran
5-
version = 1.14
5+
version = 1.15
66

77
[NextRelease]
88
[@Git]

lib/Catalyst/Controller/REST.pm

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,79 @@ sub status_gone {
561561
return 1;
562562
}
563563

564+
=item status_see_other
565+
566+
Returns a "303 See Other" response. Takes an optional "entity" to serialize,
567+
and a "location" where the client should redirect to.
568+
569+
Example:
570+
571+
$self->status_see_other(
572+
$c,
573+
location => $some_other_url,
574+
entity => {
575+
radiohead => "Is a good band!",
576+
}
577+
);
578+
579+
=cut
580+
581+
sub status_see_other {
582+
my $self = shift;
583+
my $c = shift;
584+
my %p = Params::Validate::validate(
585+
@_,
586+
{
587+
location => { type => SCALAR | OBJECT },
588+
entity => { optional => 1 },
589+
},
590+
);
591+
592+
$c->response->status(303);
593+
$c->response->header( 'Location' => $p{location} );
594+
$self->_set_entity( $c, $p{'entity'} );
595+
return 1;
596+
}
597+
598+
=item status_moved
599+
600+
Returns a "301 MOVED" response. Takes an "entity" to serialize, and a
601+
"location" where the created object can be found.
602+
603+
Example:
604+
605+
$self->status_moved(
606+
$c,
607+
location => '/somewhere/else',
608+
entity => {
609+
radiohead => "Is a good band!",
610+
},
611+
);
612+
613+
=cut
614+
615+
sub status_moved {
616+
my $self = shift;
617+
my $c = shift;
618+
my %p = Params::Validate::validate(
619+
@_,
620+
{
621+
location => { type => SCALAR | OBJECT },
622+
entity => { optional => 1 },
623+
},
624+
);
625+
626+
my $location = ref $p{location}
627+
? $p{location}->as_string
628+
: $p{location}
629+
;
630+
631+
$c->response->status(301);
632+
$c->response->header( Location => $location );
633+
$self->_set_entity($c, $p{entity});
634+
return 1;
635+
}
636+
564637
sub _set_entity {
565638
my $self = shift;
566639
my $c = shift;

t/catalyst-controller-rest.t

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ is_deeply Load( $res->content ),
4141
"... status found message";
4242
is $res->header('Location'), '/rest', "...location of what was found";
4343

44+
ok $res = request( $t->get( url => '/rest/test_status_see_other' ) );
45+
is $res->code, 303, "... status see other";
46+
is $res->header('Location'), '/rest', "...location to redirect to";
47+
48+
4449
ok $res = request( $t->get( url => '/rest/test_status_bad_request' ) );
4550
is $res->code, 400, '... status bad request';
4651
is_deeply Load( $res->content ),

t/lib/Test/Catalyst/Action/REST/Controller/REST.pm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ sub test_status_gone : Local {
8282
message => "Document have been deleted by foo", );
8383
}
8484

85+
sub test_status_see_other : Local {
86+
my ( $self, $c ) = @_;
87+
$self->status_see_other(
88+
$c,
89+
location => '/rest',
90+
entity => { somethin => 'happenin' }
91+
);
92+
}
93+
8594
sub opts : Local ActionClass('REST') {}
8695

8796
sub opts_GET {

0 commit comments

Comments
 (0)