[Catalyst-commits] r8058 - in Catalyst-Action-REST/0.60/branches/decouple_deserialize: . lib/Catalyst/Action lib/Catalyst/Controller lib/Catalyst/Request t t/lib/Test/Serialize/Controller

lukes at dev.catalyst.perl.org lukes at dev.catalyst.perl.org
Mon Jun 30 19:38:57 BST 2008


Author: lukes
Date: 2008-06-30 19:38:56 +0100 (Mon, 30 Jun 2008)
New Revision: 8058

Modified:
   Catalyst-Action-REST/0.60/branches/decouple_deserialize/
   Catalyst-Action-REST/0.60/branches/decouple_deserialize/Changelog
   Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Action/SerializeBase.pm
   Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Controller/REST.pm
   Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Request/REST.pm
   Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/catalyst-request-rest.t
   Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/json.t
   Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/lib/Test/Serialize/Controller/REST.pm
Log:
 r8414 at luke-mbp (orig r7931):  claco | 2008-06-17 00:54:50 +0100
  r1682 at mbp:  claco | 2008-06-16 19:54:33 -0400
  Added support for application/json and wanr when using text/x-json
 



Property changes on: Catalyst-Action-REST/0.60/branches/decouple_deserialize
___________________________________________________________________
Name: svk:merge
   - 30504762-a21f-0410-86fe-fb543316e637:/local/Catalyst-Action-REST:70
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Action-REST/0.50/trunk:7341
58586828-bfeb-4a8b-ac3c-3302daf284f8:/local/Catalyst-Action-REST/0.60/trunk:1144
   + 30504762-a21f-0410-86fe-fb543316e637:/local/Catalyst-Action-REST:70
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Action-REST/0.50/trunk:7341
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Action-REST/0.60/trunk:7931
58586828-bfeb-4a8b-ac3c-3302daf284f8:/local/Catalyst-Action-REST/0.60/trunk:1682

Modified: Catalyst-Action-REST/0.60/branches/decouple_deserialize/Changelog
===================================================================
--- Catalyst-Action-REST/0.60/branches/decouple_deserialize/Changelog	2008-06-30 16:25:16 UTC (rev 8057)
+++ Catalyst-Action-REST/0.60/branches/decouple_deserialize/Changelog	2008-06-30 18:38:56 UTC (rev 8058)
@@ -1,3 +1,5 @@
+  Support official application/json and carp about text/x-json
+
 Thu Jan  3 17:23:58 PST 2008 (adam) - Release 0.60
   Updated my contact information.
   Prepped for release.

Modified: Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Action/SerializeBase.pm
===================================================================
--- Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Action/SerializeBase.pm	2008-06-30 16:25:16 UTC (rev 8057)
+++ Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Action/SerializeBase.pm	2008-06-30 18:38:56 UTC (rev 8058)
@@ -36,6 +36,12 @@
         $self->_serialize_plugins( \@plugins );
     }
 
+    # carp about old text/x-json
+    if ($content_type eq 'text/x-json') {
+        $c->log->info('Using deprecated text/x-json content-type.');
+        $c->log->info('Use application/json instead!');
+    }
+
     # Finally, we load the class.  If you have a default serializer,
     # and we still don't have a content-type that exists in the map,
     # we'll use it.

Modified: Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Controller/REST.pm
===================================================================
--- Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Controller/REST.pm	2008-06-30 16:25:16 UTC (rev 8057)
+++ Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Controller/REST.pm	2008-06-30 18:38:56 UTC (rev 8058)
@@ -218,6 +218,7 @@
             'text/html'          => 'YAML::HTML',
             'text/xml'           => 'XML::Simple',
             'text/x-yaml'        => 'YAML',
+            'application/json'   => 'JSON',
             'text/x-json'        => 'JSON',
             'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
             'text/x-data-denter' => [ 'Data::Serializer', 'Data::Denter' ],
@@ -415,6 +416,7 @@
             'text/html'          => 'YAML::HTML',
             'text/xml'           => 'XML::Simple',
             'text/x-yaml'        => 'YAML',
+            'application/json'   => 'JSON',
             'text/x-json'        => 'JSON',
             'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
             'text/x-data-denter' => [ 'Data::Serializer', 'Data::Denter' ],

Modified: Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Request/REST.pm
===================================================================
--- Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Request/REST.pm	2008-06-30 16:25:16 UTC (rev 8057)
+++ Catalyst-Action-REST/0.60/branches/decouple_deserialize/lib/Catalyst/Request/REST.pm	2008-06-30 18:38:56 UTC (rev 8058)
@@ -20,7 +20,7 @@
 
 =head1 SYNOPSIS
 
-     if ( $c->request->accepts('text/x-json') ) {
+     if ( $c->request->accepts('application/json') ) {
          ...
      }
 

Modified: Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/catalyst-request-rest.t
===================================================================
--- Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/catalyst-request-rest.t	2008-06-30 16:25:16 UTC (rev 8057)
+++ Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/catalyst-request-rest.t	2008-06-30 18:38:56 UTC (rev 8058)
@@ -1,6 +1,6 @@
 use strict;
 use warnings;
-use Test::More tests => 21;
+use Test::More tests => 24;
 use FindBin;
 use lib ( "$FindBin::Bin/../lib" );
 
@@ -112,6 +112,31 @@
     $request->headers( HTTP::Headers->new );
     $request->parameters( {} );
     $request->method('GET');
+    $request->content_type('application/json');
+    $request->headers->header(
+        'Accept' =>
+        # From Firefox 2.0 when it requests an html page
+        'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
+    );
+
+    is_deeply( $request->accepted_content_types,
+               [ qw( application/json
+                     text/xml application/xml application/xhtml+xml
+                     image/png
+                     text/html
+                     text/plain
+                     */*
+                   ) ],
+               'accept header is parsed properly, and content-type header has precedence over accept' );
+    ok( ! $request->accept_only, 'accept_only is false' );
+}
+
+{
+    my $request = Catalyst::Request::REST->new;
+    $request->{_context} = 'MockContext';
+    $request->headers( HTTP::Headers->new );
+    $request->parameters( {} );
+    $request->method('GET');
     $request->content_type('text/x-json');
     $request->headers->header(
         'Accept' => 'text/plain,text/x-json',
@@ -124,7 +149,24 @@
                'each type appears only once' );
 }
 
+{
+    my $request = Catalyst::Request::REST->new;
+    $request->{_context} = 'MockContext';
+    $request->headers( HTTP::Headers->new );
+    $request->parameters( {} );
+    $request->method('GET');
+    $request->content_type('application/json');
+    $request->headers->header(
+        'Accept' => 'text/plain,application/json',
+    );
 
+    is_deeply( $request->accepted_content_types,
+               [ qw( application/json
+                     text/plain
+                   ) ],
+               'each type appears only once' );
+}
+
 package MockContext;
 
 sub prepare_body { }

Modified: Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/json.t
===================================================================
--- Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/json.t	2008-06-30 16:25:16 UTC (rev 8057)
+++ Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/json.t	2008-06-30 18:38:56 UTC (rev 8058)
@@ -1,6 +1,6 @@
 use strict;
 use warnings;
-use Test::More tests => 5; 
+use Test::More tests => 9; 
 use FindBin;
 
 use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib");
@@ -8,25 +8,27 @@
 
 use_ok 'Catalyst::Test', 'Test::Serialize';
 
-my $t = Test::Rest->new('content_type' => 'text/x-json');
-
-my $has_serializer = eval "require JSON::Syck";
 SKIP: {
-    skip "JSON::Syck not available", 4, unless $has_serializer;
+    my $has_serializer = eval "require JSON::Syck";
 
-    my $monkey_template = {
-        monkey => 'likes chicken!',
-    };
-    my $mres = request($t->get(url => '/monkey_get'));
-    ok( $mres->is_success, 'GET the monkey succeeded' );
-    is_deeply(JSON::Syck::Load($mres->content), $monkey_template, "GET returned the right data");
+    skip "JSON::Syck not available", 8, unless $has_serializer;
 
-    my $post_data = {
-        'sushi' => 'is good for monkey',
-    };
-    my $mres_post = request($t->post(url => '/monkey_put', data => JSON::Syck::Dump($post_data)));
-    ok( $mres_post->is_success, "POST to the monkey succeeded");
-    is_deeply($mres_post->content, "is good for monkey", "POST data matches");
+    for ('text/x-json', 'application/json') {
+        my $t = Test::Rest->new('content_type' => $_);
+        my $monkey_template = {
+            monkey => 'likes chicken!',
+        };
+        my $mres = request($t->get(url => '/monkey_get'));
+        ok( $mres->is_success, 'GET the monkey succeeded' );
+        is_deeply(JSON::Syck::Load($mres->content), $monkey_template, "GET returned the right data");
+
+        my $post_data = {
+            'sushi' => 'is good for monkey',
+        };
+        my $mres_post = request($t->post(url => '/monkey_put', data => JSON::Syck::Dump($post_data)));
+        ok( $mres_post->is_success, "POST to the monkey succeeded");
+        is_deeply($mres_post->content, "is good for monkey", "POST data matches");
+    }
 };
 
 1;

Modified: Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/lib/Test/Serialize/Controller/REST.pm
===================================================================
--- Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/lib/Test/Serialize/Controller/REST.pm	2008-06-30 16:25:16 UTC (rev 8057)
+++ Catalyst-Action-REST/0.60/branches/decouple_deserialize/t/lib/Test/Serialize/Controller/REST.pm	2008-06-30 18:38:56 UTC (rev 8058)
@@ -12,6 +12,7 @@
         'text/html'          => 'YAML::HTML',
         'text/xml'           => 'XML::Simple',
         'text/x-yaml'        => 'YAML',
+        'application/json'   => 'JSON',
         'text/x-json'        => 'JSON',
         'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
         'text/x-data-denter' => [ 'Data::Serializer', 'Data::Denter' ],




More information about the Catalyst-commits mailing list