fix missing v1.15 v1.15
Arthur Axel 'fREW' Schmidt [Fri, 12 Sep 2014 18:11:15 +0000 (13:11 -0500)]
Changes
dist.ini
lib/Catalyst/Controller/REST.pm
t/catalyst-controller-rest.t
t/lib/Test/Catalyst/Action/REST/Controller/REST.pm

diff --git a/Changes b/Changes
index 9346742..9b5529e 100644 (file)
--- a/Changes
+++ b/Changes
@@ -2,6 +2,11 @@ Revision history for {{$dist->name}}
 
 {{$NEXT}}
 
+1.15      2014-05-07 09:02:44-05:00 CST6CDT
+
+ * Added new status_see_other method for returning a 303 redirect.
+ * Added new status_moved method for returning a 301 redirect. (Matthew Keller)
+
 1.14      2013-12-27 15:32:19 America/Chicago
 
  * Stop prompting for features at install time
index c05662b..ca7f9a0 100644 (file)
--- a/dist.ini
+++ b/dist.ini
@@ -2,7 +2,7 @@ name             = Catalyst-Action-REST
 author           = Tomas Doran <bobtfish@cpan.org>
 license          = Perl_5
 copyright_holder = Tomas Doran
-version          = 1.14
+version          = 1.15
 
 [NextRelease]
 [@Git]
index d43ef86..a9b67f6 100644 (file)
@@ -561,6 +561,79 @@ sub status_gone {
     return 1;
 }
 
+=item status_see_other
+
+Returns a "303 See Other" response.  Takes an optional "entity" to serialize,
+and a "location" where the client should redirect to.
+
+Example:
+
+  $self->status_see_other(
+    $c,
+    location => $some_other_url,
+    entity => {
+        radiohead => "Is a good band!",
+    }
+  );
+
+=cut
+
+sub status_see_other {
+    my $self = shift;
+    my $c    = shift;
+    my %p    = Params::Validate::validate(
+        @_,
+        {
+            location => { type     => SCALAR | OBJECT },
+            entity   => { optional => 1 },
+        },
+    );
+
+    $c->response->status(303);
+    $c->response->header( 'Location' => $p{location} );
+    $self->_set_entity( $c, $p{'entity'} );
+    return 1;
+}
+
+=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 = ref $p{location}
+      ? $p{location}->as_string
+      : $p{location}
+   ;
+
+   $c->response->status(301);
+   $c->response->header( Location => $location );
+   $self->_set_entity($c, $p{entity});
+   return 1;
+}
+
 sub _set_entity {
     my $self   = shift;
     my $c      = shift;
index 7b4555c..ec39392 100644 (file)
@@ -41,6 +41,11 @@ is_deeply Load( $res->content ),
     "...  status found message";
 is $res->header('Location'), '/rest', "...location of what was found";
 
+ok $res = request( $t->get( url => '/rest/test_status_see_other' ) );
+is $res->code, 303, "... status see other";
+is $res->header('Location'), '/rest', "...location to redirect to";
+
+
 ok $res = request( $t->get( url => '/rest/test_status_bad_request' ) );
 is $res->code, 400, '... status bad request';
 is_deeply Load( $res->content ),
index 08bcdf0..2cc7d46 100644 (file)
@@ -82,6 +82,15 @@ sub test_status_gone : Local {
         message => "Document have been deleted by foo", );
 }
 
+sub test_status_see_other : Local {
+    my ( $self, $c ) = @_;
+    $self->status_see_other(
+        $c,
+        location => '/rest',
+        entity   => { somethin => 'happenin' }
+    );
+}
+
 sub opts : Local ActionClass('REST') {}
 
 sub opts_GET {