Merge remote branch 'origin/master'
Tomas Doran [Thu, 6 May 2010 08:29:40 +0000 (09:29 +0100)]
* origin/master:
  Revert "When inserting Cat::Req::REST, always add trait, rather than sometimes using the Cat::Req::REST class directly."

25 files changed:
Changes
lib/Catalyst/Action/Deserialize.pm
lib/Catalyst/Action/Deserialize/Data/Serializer.pm
lib/Catalyst/Action/Deserialize/JSON.pm
lib/Catalyst/Action/Deserialize/View.pm
lib/Catalyst/Action/Deserialize/XML/Simple.pm
lib/Catalyst/Action/Deserialize/YAML.pm
lib/Catalyst/Action/REST.pm
lib/Catalyst/Action/Serialize.pm
lib/Catalyst/Action/Serialize/Data/Serializer.pm
lib/Catalyst/Action/Serialize/JSON.pm
lib/Catalyst/Action/Serialize/JSON/XS.pm
lib/Catalyst/Action/Serialize/JSONP.pm
lib/Catalyst/Action/Serialize/View.pm
lib/Catalyst/Action/Serialize/XML/Simple.pm
lib/Catalyst/Action/Serialize/YAML.pm
lib/Catalyst/Action/Serialize/YAML/HTML.pm
lib/Catalyst/Action/SerializeBase.pm
lib/Catalyst/Controller/REST.pm
lib/Catalyst/Request/REST.pm
lib/Catalyst/Request/REST/ForBrowsers.pm
lib/Catalyst/TraitFor/Request/REST.pm
lib/Catalyst/TraitFor/Request/REST/ForBrowsers.pm
t/catalyst-controller-rest.t
t/lib/Test/Catalyst/Action/REST/Controller/REST.pm

diff --git a/Changes b/Changes
index d0724eb..06d7729 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,8 @@
+Thu  6 May 2010 09:27:56 - Release 0.84
+  Add a status_multiple_choices helper method to the Controller base class.
+
+  Allow 3XX responses to be serialized.
+
 Mon  8 Feb 2010 22:17:12 GMT - Release 0.83
   Make it possible to deserialize a request with a DELETE method. This probably
   breaks 'strict' REST guidelines, but is useful for being able to delete multiple
index 504fc30..342b478 100644 (file)
@@ -7,7 +7,7 @@ extends 'Catalyst::Action::SerializeBase';
 use Module::Pluggable::Object;
 use MRO::Compat;
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 has plugins => ( is => 'rw' );
index 4a49c8a..3ac3a18 100644 (file)
@@ -6,7 +6,7 @@ use namespace::autoclean;
 extends 'Catalyst::Action';
 use Data::Serializer;
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 sub execute {
index 1b7e677..c786860 100644 (file)
@@ -6,7 +6,7 @@ use namespace::autoclean;
 extends 'Catalyst::Action';
 use JSON qw( decode_json );
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 sub execute {
index 342a789..84b14ed 100644 (file)
@@ -5,7 +5,7 @@ use namespace::autoclean;
 
 extends 'Catalyst::Action';
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 sub execute {
index 58bbbb3..78dde38 100644 (file)
@@ -5,7 +5,7 @@ use namespace::autoclean;
 
 extends 'Catalyst::Action';
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 sub execute {
index af9f2fd..439c6e6 100644 (file)
@@ -6,7 +6,7 @@ use namespace::autoclean;
 extends 'Catalyst::Action';
 use YAML::Syck;
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 sub execute {
index 6c7692c..214ec09 100644 (file)
@@ -10,7 +10,7 @@ use Catalyst::Controller::REST;
 
 BEGIN { require 5.008001; }
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 sub new {
index 1ee6e1c..0a44e1b 100644 (file)
@@ -7,7 +7,7 @@ extends 'Catalyst::Action::SerializeBase';
 use Module::Pluggable::Object;
 use MRO::Compat;
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 has _encoders => (
@@ -25,7 +25,7 @@ sub execute {
     return 1 if $c->req->method eq 'HEAD';
     return 1 if length( $c->response->body );
     return 1 if scalar @{ $c->error };
-    return 1 if $c->response->status =~ /^(?:204|3\d\d)$/;
+    return 1 if $c->response->status =~ /^(?:204)$/;
 
     my ( $sclass, $sarg, $content_type ) =
       $self->_load_content_plugins( "Catalyst::Action::Serialize",
index 98024a8..231d8c1 100644 (file)
@@ -6,7 +6,7 @@ use namespace::autoclean;
 extends 'Catalyst::Action';
 use Data::Serializer;
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 sub execute {
index 0b10fb7..b48a213 100644 (file)
@@ -6,7 +6,7 @@ use namespace::autoclean;
 extends 'Catalyst::Action';
 use JSON ();
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 has encoder => (
index 9aedbb9..2553b95 100644 (file)
@@ -6,7 +6,7 @@ use namespace::autoclean;
 extends 'Catalyst::Action::Serialize::JSON';
 use JSON::XS ();
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 sub _build_encoder {
index cb15920..24c4738 100644 (file)
@@ -4,7 +4,7 @@ use namespace::autoclean;
 
 extends 'Catalyst::Action::Serialize::JSON';
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 after 'execute' => sub {
index bce9933..fbfa7f4 100644 (file)
@@ -4,7 +4,7 @@ use namespace::autoclean;
 
 extends 'Catalyst::Action';
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 sub execute {
index 50b9097..bc57ad9 100644 (file)
@@ -5,7 +5,7 @@ use namespace::autoclean;
 
 extends 'Catalyst::Action';
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 sub execute {
index fbfdb0e..545d867 100644 (file)
@@ -6,7 +6,7 @@ use namespace::autoclean;
 extends 'Catalyst::Action';
 use YAML::Syck;
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 sub execute {
index de0b7c8..af0d896 100644 (file)
@@ -7,7 +7,7 @@ extends 'Catalyst::Action';
 use YAML::Syck;
 use URI::Find;
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 sub execute {
index b4447f7..ea945e6 100644 (file)
@@ -8,7 +8,7 @@ use Module::Pluggable::Object;
 use Catalyst::Request::REST;
 use Catalyst::Utils ();
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 after BUILDARGS => sub {
index fe3d49f..689ca90 100644 (file)
@@ -2,7 +2,7 @@ package Catalyst::Controller::REST;
 use Moose;
 use namespace::autoclean;
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 =head1 NAME
@@ -398,6 +398,36 @@ sub status_no_content {
     return 1.;
 }
 
+=item status_multiple_choices
+
+Returns a "300 MULTIPLE CHOICES" response. Takes an "entity" to serialize, which should
+provide list of possible locations. Also takes optional "location" for preferred choice.
+
+=cut
+
+sub status_multiple_choices {
+    my $self = shift;
+    my $c    = shift;
+    my %p    = Params::Validate::validate(
+        @_,
+        {
+            entity => 1,
+            location => { type     => SCALAR | OBJECT, optional => 1 },
+        },
+    );
+
+    my $location;
+    if ( ref( $p{'location'} ) ) {
+        $location = $p{'location'}->as_string;
+    } else {
+        $location = $p{'location'};
+    }
+    $c->response->status(300);
+    $c->response->header( 'Location' => $location ) if exists $p{'location'};
+    $self->_set_entity( $c, $p{'entity'} );
+    return 1;
+}
+
 =item status_bad_request
 
 Returns a "400 BAD REQUEST" response.  Takes a "message" argument
index a6156b4..0516281 100644 (file)
@@ -7,7 +7,7 @@ use namespace::autoclean;
 extends 'Catalyst::Request';
 with 'Catalyst::TraitFor::Request::REST';
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 # Please don't take this as a recommended way to do things.
index 01c1693..af86d1b 100644 (file)
@@ -3,7 +3,7 @@ use Moose;
 
 use namespace::autoclean;
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 extends 'Catalyst::Request::REST';
index 2d54b7e..db63210 100644 (file)
@@ -3,7 +3,7 @@ use Moose::Role;
 use HTTP::Headers::Util qw(split_header_words);
 use namespace::autoclean;
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 has [qw/ data accept_only /] => ( is => 'rw' );
index c2e4d95..43eabaf 100644 (file)
@@ -4,7 +4,7 @@ use namespace::autoclean;
 
 with 'Catalyst::TraitFor::Request::REST';
 
-our $VERSION = '0.83';
+our $VERSION = '0.84';
 $VERSION = eval $VERSION;
 
 has _determined_real_method => (
index 5d8f731..e45f0b9 100644 (file)
@@ -1,6 +1,6 @@
 use strict;
 use warnings;
-use Test::More tests => 18;
+use Test::More;
 use YAML::Syck;
 use FindBin;
 
@@ -48,3 +48,12 @@ is $res->code, 410, '... status gone';
 is_deeply Load( $res->content ),
     { error => "Document have been deleted by foo" },
     "...  status gone message";
+
+ok $res = request( $t->get( url => '/rest/test_status_multiple_choices' ) );
+is $res->code, 300, "... multiple choices";
+is_deeply Load($res->content),
+    { choices => [qw(/rest/choice1 /rest/choice2)] },
+    "... 300 multiple choices has response body";
+
+done_testing;
+
index e434159..f9f7147 100644 (file)
@@ -20,6 +20,15 @@ sub test_status_created : Local {
     );
 }
 
+sub test_status_multiple_choices : Local {
+    my ( $self, $c ) = @_;
+    $self->status_multiple_choices(
+        $c,
+        location => '/rest/choice1',
+        entity   => { choices => [qw(/rest/choice1 /rest/choice2)] }
+    );
+}
+
 sub test_status_accepted : Local {
     my ( $self, $c ) = @_;
     $self->status_accepted( $c, entity => { status => "queued", } );