Factor Data::Serialization into a sep dist
Arthur Axel 'fREW' Schmidt [Fri, 12 Apr 2013 00:58:31 +0000 (19:58 -0500)]
Changes
Makefile.PL
lib/Catalyst/Action/Deserialize/Data/Serializer.pm [deleted file]
lib/Catalyst/Action/Serialize/Data/Serializer.pm [deleted file]
lib/Catalyst/Controller/REST.pm
t/catalyst-action-serialize-accept.t
t/catalyst-action-serialize.t
t/data-serializer.t [deleted file]

diff --git a/Changes b/Changes
index eee5555..1d49325 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,22 @@
+ Factor Data::Serializable into it's own dist to stop breakages.
+
+   If you use any of:
+
+   * Data::Dumper
+   * Data::Denter
+   * Data::Taxi
+   * Config::General
+   * PHP::Serialization
+
+   You'll need to install Catalyst-Action-Serialize-Data-Serializer and add the
+   appropriate lines to your controller config.  Said lines may be:
+
+         'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
+         'text/x-data-denter' => [ 'Data::Serializer', 'Data::Denter' ],
+         'text/x-data-taxi'   => [ 'Data::Serializer', 'Data::Taxi'   ],
+         'text/x-config-general'    => [ 'Data::Serializer', 'Config::General' ],
+         'text/x-php-serialization' => [ 'Data::Serializer', 'PHP::Serialization' ],
+
 Thu 11 Apr 2012 20:20:00 BST - Release 1.07
  Don't serialize if a view is explicitly set.
 
index 7e22b90..3a754d4 100644 (file)
@@ -17,7 +17,6 @@ requires('YAML::Syck'                => '0.67');
 requires('HTML::Parser'              => undef);
 requires('Module::Pluggable::Object' => undef);
 requires('LWP::UserAgent'            => '2.033');
-requires('Data::Serializer'          => '0.36');
 requires('Class::Inspector'          => '1.13');
 requires('URI::Find'                 => undef);
 requires('MRO::Compat'               => '0.10');
diff --git a/lib/Catalyst/Action/Deserialize/Data/Serializer.pm b/lib/Catalyst/Action/Deserialize/Data/Serializer.pm
deleted file mode 100644 (file)
index 8eacc74..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-package Catalyst::Action::Deserialize::Data::Serializer;
-
-use Moose;
-use namespace::autoclean;
-
-extends 'Catalyst::Action';
-use Data::Serializer;
-use Safe;
-use Scalar::Util qw(openhandle);
-my $compartment = Safe->new;
-$compartment->permit_only( qw(padany null lineseq const pushmark list anonhash anonlist refgen leaveeval undef) );
-
-our $VERSION = '1.07';
-$VERSION = eval $VERSION;
-
-sub execute {
-    my $self = shift;
-    my ( $controller, $c, $serializer ) = @_;
-
-    my $sp = $serializer;
-    $sp =~ s/::/\//g;
-    $sp .= ".pm";
-    eval {
-        require $sp
-    };
-    if ($@) {
-        $c->log->debug("Could not load $serializer, refusing to serialize: $@")
-            if $c->debug;
-        return 0;
-    }
-    my $body = $c->request->body;
-    if ($body) {
-        my $rbody = '';
-
-        if(openhandle $body) {
-            seek($body, 0, 0); # in case something has already read from it
-            while ( defined( my $line = <$body> ) ) {
-                $rbody .= $line;
-            }
-        } else {
-            $rbody = $body;
-        }
-
-        my $rdata;
-        if ( $serializer eq "Data::Dumper" ) {
-            # Taken from Data::Serialize::Data::Dumper::deserialize, but run within a Safe compartment
-            my $code = $rbody =~ /^\{/ ? "+".$rbody : $rbody;
-            $rdata = $compartment->reval( $code );
-        }
-        else {
-            my $dso = Data::Serializer->new( serializer => $serializer );
-            eval {
-                $rdata = $dso->raw_deserialize($rbody);
-            };
-        }
-        if ($@) {
-            return $@;
-        }
-        $c->request->data($rdata);
-    } else {
-        $c->log->debug(
-            'I would have deserialized, but there was nothing in the body!')
-                if $c->debug;
-    }
-    return 1;
-}
-
-__PACKAGE__->meta->make_immutable;
-
-1;
diff --git a/lib/Catalyst/Action/Serialize/Data/Serializer.pm b/lib/Catalyst/Action/Serialize/Data/Serializer.pm
deleted file mode 100644 (file)
index 545d43a..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-package Catalyst::Action::Serialize::Data::Serializer;
-
-use Moose;
-use namespace::autoclean;
-
-extends 'Catalyst::Action';
-use Data::Serializer;
-
-our $VERSION = '1.07';
-$VERSION = eval $VERSION;
-
-sub execute {
-    my $self = shift;
-    my ( $controller, $c, $serializer ) = @_;
-
-    my $stash_key = (
-            $controller->{'serialize'} ?
-                $controller->{'serialize'}->{'stash_key'} :
-                $controller->{'stash_key'} 
-        ) || 'rest';
-    my $sp = $serializer;
-    $sp =~ s/::/\//g;
-    $sp .= ".pm";
-    eval {
-        require $sp
-    };
-    if ($@) {
-        $c->log->info("Could not load $serializer, refusing to serialize: $@");
-        return;
-    }
-    my $dso = Data::Serializer->new( serializer => $serializer );
-    my $data = $dso->raw_serialize($c->stash->{$stash_key});
-    $c->response->output( $data );
-    return 1;
-}
-
-__PACKAGE__->meta->make_immutable;
-
-1;
index 6af9b76..a3a81a8 100644 (file)
@@ -296,11 +296,6 @@ __PACKAGE__->config(
         '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' ],
-        'text/x-data-taxi'   => [ 'Data::Serializer', 'Data::Taxi'   ],
-        'text/x-config-general'    => [ 'Data::Serializer', 'Config::General' ],
-        'text/x-php-serialization' => [ 'Data::Serializer', 'PHP::Serialization' ],
     },
 );
 
index 64732f5..8303a87 100644 (file)
@@ -73,21 +73,6 @@ SKIP: {
     is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type')
 }
 
-# Make sure that when using content_type_stash_key, a valid value in the stash gets priority.
-# This also tests that application-level config is properly passed to
-# individual controllers; see t/lib/Test/Catalyst/Action/REST.pm
-{
-    my $req = $t->get(url =>
-        '/serialize/test_second?serialize_content_type=text/x-data-dumper'
-    );
-    $req->remove_header('Content-Type');
-    $req->header('Accept', '*/*');
-    my $res = request($req);
-    ok( $res->is_success, 'GET the serialized request succeeded' );
-    is( $res->content, "{'lou' => 'is my cat'}", "Request returned proper data");
-    is( $res->header('Content-type'), 'text/x-data-dumper', '... with expected content-type')
-}
-
 # Make sure that the default content type you specify really gets used.
 {
     my $req = $t->get(url => '/override/test');
index 2535cfe..0b0fb2c 100644 (file)
@@ -8,14 +8,13 @@ use FindBin;
 use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib", "$FindBin::Bin/broken");
 use Test::Rest;
 
-# Should use Data::Dumper, via YAML 
-my $t = Test::Rest->new('content_type' => 'text/x-data-dumper');
+my $t = Test::Rest->new('content_type' => 'application/json');
 
 use_ok 'Catalyst::Test', 'Test::Catalyst::Action::REST';
 
 my $res = request($t->get(url => '/serialize/test'));
 ok( $res->is_success, 'GET the serialized request succeeded' );
-is( $res->content, "{'lou' => 'is my cat'}", "Request returned proper data");
+is( $res->content, '{"lou":"is my cat"}', "Request returned proper data");
 
 my $nt = Test::Rest->new('content_type' => 'text/broken');
 my $bres = request($nt->get(url => '/serialize/test'));
@@ -29,16 +28,16 @@ is ($bres->code, 415, 'GET on unknown Content-Type returns 415');
 # request.
 my $res2 = request($t->get(url => '/serialize/test_second'));
 ok( $res2->is_success, '2nd request succeeded' );
-is( $res2->content, "{'lou' => 'is my cat'}", "2nd request returned proper data");
+is( $res2->content,'{"lou":"is my cat"}', "2nd request returned proper data");
 
 Test::Catalyst::Action::REST->controller('Serialize')->{serialize} = {};
 $res2 = request($t->get(url => '/serialize/test_second'));
 ok( $res2->is_success, 'request succeeded (deprecated config)' );
-is( $res2->content, "{'lou' => 'is my cat'}", "request returned proper data");
+is( $res2->content,'{"lou":"is my cat"}', "request returned proper data");
 
 
 $res = request($t->get(url => '/serialize/empty_serialized'));
-is $res->content, q[{'foo' => 'bar'}], 'normal case ok';
+is $res->content, q[{"foo":"bar"}], 'normal case ok';
 ok $res->header('Content-Length'), 'set content-length when we serialize';
 
 $res = request($t->get(url => '/serialize/empty_not_serialized_blank'));
diff --git a/t/data-serializer.t b/t/data-serializer.t
deleted file mode 100644 (file)
index 7fb3932..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-use strict;
-use warnings;
-use Test::More;
-use FindBin;
-
-use lib ( "$FindBin::Bin/lib", "$FindBin::Bin/../lib" );
-use Test::Rest;
-
-use_ok 'Catalyst::Test', 'Test::Serialize';
-
-my %ctypes =( 
-            'text/x-data-dumper' =>   'Data::Dumper' ,
-            'text/x-data-denter' =>   'Data::Denter' ,
-            'text/x-data-taxi'   =>   'Data::Taxi'   ,
-            'application/x-storable'    =>   'Storable'     ,
-            'application/x-freezethaw'  =>   'FreezeThaw'   ,
-            'text/x-config-general' =>   'Config::General' ,
-            'text/x-php-serialization' =>   'PHP::Serialization' ,
-        );
-
-my $has_serializer = eval "require Data::Serializer";
-
-foreach my $content_type (keys(%ctypes)) {
-    my $dso;
-    my $skip = 0;
-    my $loadclass = $ctypes{$content_type};
-    $loadclass =~ s/::/\//g;
-    $loadclass .= '.pm';
-    eval {
-       require $loadclass 
-    };
-    if ($@) {
-        $skip = 1;
-    }
-    SKIP: {
-        skip "$ctypes{$content_type} not installed", 4 if $skip;
-        $dso = Data::Serializer->new( serializer => $ctypes{$content_type} );
-        my $t = Test::Rest->new( 'content_type' => $content_type );
-
-        my $monkey_template = { monkey => 'likes chicken!', };
-        my $mres = request( $t->get( url => '/monkey_get' ) );
-        ok( $mres->is_success, "GET $content_type succeeded" );
-        is_deeply( $dso->raw_deserialize( $mres->content ),
-            $monkey_template, "GET $content_type has the right data" );
-
-        my $post_data = { 'sushi' => 'is good for monkey', };
-        my $mres_post = request(
-            $t->post(
-                url  => '/monkey_put',
-                data => $dso->raw_serialize($post_data)
-            )
-        );
-        ok( $mres_post->is_success, "POST $content_type succeeded" );
-        is_deeply(
-            $mres_post->content,
-            "is good for monkey",
-            "POST $content_type data matches"
-        );
-    }
-}
-
-{
-        my $t = Test::Rest->new( 'content_type' => 'text/x-data-dumper' );
-
-        my $post_data = "{ 'sushi' => die('hack attempt') }";
-        my $mres_post = request(
-            $t->post(
-                url  => '/monkey_put',
-                data => $post_data,
-            )
-        );
-        ok( ! $mres_post->is_success, "POST Data::Dumper fails due to invalid input" );
-        like(
-            $mres_post->content,
-            qr%Content-Type text/x-data-dumper had a problem with your request.*'die' trapped by operation mask%s,
-            "POST Data::Dumper data error matches"
-        );
-}
-
-1;
-
-done_testing;