[libcatmandu-perl] 12/16: require JSON::XS

Jonas Smedegaard dr at jones.dk
Thu Dec 4 14:43:17 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.9209
in repository libcatmandu-perl.

commit df423486fa944b98acdd6b0a900b50a2ffdc24bd
Author: Nicolas Steenlant <nicolas.steenlant at ugent.be>
Date:   Wed Dec 3 13:28:41 2014 +0100

    require JSON::XS
---
 Build.PL                        |  3 +--
 cpanfile                        |  3 +--
 lib/Catmandu/Exporter/JSON.pm   | 18 +++++++++---------
 lib/Catmandu/Fix/from_json.pm   |  4 ++--
 lib/Catmandu/Fix/to_json.pm     |  4 ++--
 lib/Catmandu/Importer/JSON.pm   |  4 ++--
 lib/Catmandu/Serializer/json.pm |  6 +++---
 lib/Catmandu/Util.pm            |  4 ++--
 t/Catmandu-Cmd-config.t         |  6 +++---
 t/Catmandu-Cmd-convert.t        |  4 ++--
 t/Catmandu-Cmd-export.t         |  4 ++--
 t/Catmandu-Exporter-JSON.t      |  4 ++--
 t/Catmandu-Fix-from_json.t      |  4 ++--
 t/Catmandu-Fix-to_json.t        |  4 ++--
 14 files changed, 35 insertions(+), 37 deletions(-)

diff --git a/Build.PL b/Build.PL
index f8cc34d..397a7ac 100644
--- a/Build.PL
+++ b/Build.PL
@@ -22,7 +22,6 @@ my %module_build_args = (
   "license" => "perl",
   "module_name" => "Catmandu",
   "recommends" => {
-    "JSON::XS" => "2.3",
     "Log::Any::Adapter::Log4perl" => "0.06",
     "Log::Log4perl" => "1.44"
   },
@@ -37,7 +36,7 @@ my %module_build_args = (
     "Data::Util" => "0.59",
     "File::Find::Rule" => "0.33",
     "IO::Handle::Util" => "0.01",
-    "JSON" => "2.51",
+    "JSON::XS" => "2.3",
     "List::MoreUtils" => "0.33",
     "Log::Any" => "0.15",
     "Log::Any::Adapter" => "0.11",
diff --git a/cpanfile b/cpanfile
index e2e6998..c586c6c 100644
--- a/cpanfile
+++ b/cpanfile
@@ -18,7 +18,7 @@ requires 'Data::UUID', '1.217';
 requires 'Data::Util', '0.59';
 requires 'File::Find::Rule', '0.33';
 requires 'IO::Handle::Util', '0.01';
-requires 'JSON', '2.51';
+requires 'JSON::XS', '2.3';
 requires 'List::MoreUtils', '0.33';
 requires 'Log::Any', '0.15';
 requires 'Log::Any::Adapter', '0.11';
@@ -35,7 +35,6 @@ requires 'Throwable', '0.200004';
 requires 'Try::Tiny::ByClass', '0.01';
 requires 'YAML::XS', '0.41';
 
-recommends 'JSON::XS', '2.3';
 recommends 'Log::Log4perl', '1.44';
 recommends 'Log::Any::Adapter::Log4perl', '0.06';
 
diff --git a/lib/Catmandu/Exporter/JSON.pm b/lib/Catmandu/Exporter/JSON.pm
index 7b4c6bc..3ad267f 100644
--- a/lib/Catmandu/Exporter/JSON.pm
+++ b/lib/Catmandu/Exporter/JSON.pm
@@ -2,7 +2,7 @@ package Catmandu::Exporter::JSON;
 
 use namespace::clean;
 use Catmandu::Sane;
-use JSON ();
+use JSON::XS ();
 use Moo;
 
 with 'Catmandu::Exporter';
@@ -17,14 +17,14 @@ has json         => (is => 'ro', lazy => 1, builder => '_build_json');
 
 sub _build_json {
     my ($self) = @_;
-    JSON->new
-        ->utf8(0)
-        ->allow_nonref
-        ->pretty($self->pretty)
-        ->indent($self->pretty || $self->indent)
-        ->space_before($self->pretty || $self->space_before)
-        ->space_after($self->pretty || $self->space_after)
-        ->canonical($self->canonical);
+    JSON::XS->new
+            ->utf8(0)
+            ->allow_nonref
+            ->pretty($self->pretty)
+            ->indent($self->pretty || $self->indent)
+            ->space_before($self->pretty || $self->space_before)
+            ->space_after($self->pretty || $self->space_after)
+            ->canonical($self->canonical);
 }
 
 sub add {
diff --git a/lib/Catmandu/Fix/from_json.pm b/lib/Catmandu/Fix/from_json.pm
index 43d24a6..96e6ac3 100644
--- a/lib/Catmandu/Fix/from_json.pm
+++ b/lib/Catmandu/Fix/from_json.pm
@@ -1,7 +1,7 @@
 package Catmandu::Fix::from_json;
 
 use Catmandu::Sane;
-use JSON ();
+use JSON::XS ();
 use Moo;
 use Catmandu::Fix::Has;
 
@@ -15,7 +15,7 @@ sub emit_change_value {
 
     # memoize in case called multiple times
     my $json_var = $self->_json_var ||
-                   $self->_set_json_var($fixer->capture(JSON->new->utf8(0)->pretty(0)->allow_nonref(1)));
+                   $self->_set_json_var($fixer->capture(JSON::XS->new->utf8(0)->pretty(0)->allow_nonref(1)));
 
     "if (is_string(${var})) {" .
         "${var} = ${json_var}->decode(${var});" .
diff --git a/lib/Catmandu/Fix/to_json.pm b/lib/Catmandu/Fix/to_json.pm
index 976dc86..b9db99b 100644
--- a/lib/Catmandu/Fix/to_json.pm
+++ b/lib/Catmandu/Fix/to_json.pm
@@ -1,7 +1,7 @@
 package Catmandu::Fix::to_json;
 
 use Catmandu::Sane;
-use JSON ();
+use JSON::XS ();
 use Moo;
 use Catmandu::Fix::Has;
 
@@ -14,7 +14,7 @@ sub emit {
     my $path = $fixer->split_path($self->path);
     my $key = pop @$path;
 
-    my $json_var = $fixer->capture(JSON->new->utf8(0)->pretty(0)->allow_nonref(1));
+    my $json_var = $fixer->capture(JSON::XS->new->utf8(0)->pretty(0)->allow_nonref(1));
 
     $fixer->emit_walk_path($fixer->var, $path, sub {
         my $var = shift;
diff --git a/lib/Catmandu/Importer/JSON.pm b/lib/Catmandu/Importer/JSON.pm
index 0d6fd86..0949010 100644
--- a/lib/Catmandu/Importer/JSON.pm
+++ b/lib/Catmandu/Importer/JSON.pm
@@ -2,7 +2,7 @@ package Catmandu::Importer::JSON;
 
 use namespace::clean;
 use Catmandu::Sane;
-use JSON ();
+use JSON::XS ();
 use Moo;
 
 with 'Catmandu::Importer';
@@ -12,7 +12,7 @@ has multiline => (is => 'ro', default => sub { 0 });
 
 sub _build_json {
     my ($self) = @_;
-    JSON->new->utf8($self->encoding eq ':raw');
+    JSON::XS->new->utf8($self->encoding eq ':raw');
 }
 
 sub default_encoding { ':raw' }
diff --git a/lib/Catmandu/Serializer/json.pm b/lib/Catmandu/Serializer/json.pm
index 383cb31..618f8e4 100644
--- a/lib/Catmandu/Serializer/json.pm
+++ b/lib/Catmandu/Serializer/json.pm
@@ -29,15 +29,15 @@ L<Catmandu::Serializer>
 =cut
 
 use Catmandu::Sane;
-use JSON ();
+use JSON::XS ();
 use Moo;
 
 sub serialize {
-    JSON::encode_json($_[1]);
+    JSON::XS::encode_json($_[1]);
 }
 
 sub deserialize {
-    JSON::decode_json($_[1]);
+    JSON::XS::decode_json($_[1]);
 }
 
 1;
diff --git a/lib/Catmandu/Util.pm b/lib/Catmandu/Util.pm
index b943049..2f6cf83 100644
--- a/lib/Catmandu/Util.pm
+++ b/lib/Catmandu/Util.pm
@@ -11,7 +11,7 @@ use IO::File;
 use IO::Handle::Util ();
 use File::Spec;
 use YAML::XS ();
-use JSON ();
+use JSON::XS ();
 
 our %EXPORT_TAGS = (
     io     => [qw(io read_file write_file read_yaml read_json join_path
@@ -139,7 +139,7 @@ sub read_yaml {
 sub read_json {
     my $text = read_file($_[0]);
     # dies on error
-    JSON::decode_json(read_file($_[0]));
+    JSON::XS::decode_json(read_file($_[0]));
 }
 
 sub join_path {
diff --git a/t/Catmandu-Cmd-config.t b/t/Catmandu-Cmd-config.t
index f126464..7d21816 100644
--- a/t/Catmandu-Cmd-config.t
+++ b/t/Catmandu-Cmd-config.t
@@ -5,7 +5,7 @@ use warnings;
 use Test::More;
 use Test::Exception;
 use App::Cmd::Tester;
-use JSON;
+use JSON::XS;
 
 my $pkg;
 BEGIN {
@@ -17,7 +17,7 @@ require_ok $pkg;
 use Catmandu::CLI;
 
 my $result = test_app(qq|Catmandu::CLI| => [ qw(config to JSON) ]);
-my $perl = from_json($result->stdout);
+my $perl = decode_json($result->stdout);
 
 ok $perl, 'got JSON';
 is $perl->{importer}->{default}->{package} , 'YAML' , 'got data';
@@ -30,4 +30,4 @@ like $result->stdout , qr/"YAML"/ , 'got data';
 is $result->error, undef, 'threw no exceptions' ;
 is $result->stderr, '', 'nothing sent to sderr' ;
 
-done_testing 9;
\ No newline at end of file
+done_testing 9;
diff --git a/t/Catmandu-Cmd-convert.t b/t/Catmandu-Cmd-convert.t
index d7d88c8..31d3c8c 100644
--- a/t/Catmandu-Cmd-convert.t
+++ b/t/Catmandu-Cmd-convert.t
@@ -5,7 +5,7 @@ use warnings;
 use Test::More;
 use Test::Exception;
 use App::Cmd::Tester::CaptureExternal;
-use JSON;
+use JSON::XS;
 
 my $pkg;
 BEGIN {
@@ -18,7 +18,7 @@ use Catmandu::CLI;
 
 my $result = test_app(qq|Catmandu::CLI| => [ qw(convert YAML --file t/catmandu.yml to JSON) ]);
 
-my $perl = from_json($result->stdout);
+my $perl = decode_json($result->stdout);
 
 ok $perl, 'got JSON';
 is $perl->{importer}->{default}->{package} , 'YAML' , 'got data';
diff --git a/t/Catmandu-Cmd-export.t b/t/Catmandu-Cmd-export.t
index c9fc817..932dcd3 100644
--- a/t/Catmandu-Cmd-export.t
+++ b/t/Catmandu-Cmd-export.t
@@ -5,7 +5,7 @@ use warnings;
 use Test::More;
 use Test::Exception;
 use App::Cmd::Tester::CaptureExternal;
-use JSON;
+use JSON::XS;
 
 my $pkg;
 BEGIN {
@@ -19,7 +19,7 @@ use Catmandu::CLI;
 my $result = test_app(qq|Catmandu::CLI| => [ qw(export test to JSON) ]);
 
 my @lines = split(/\n/,$result->stdout);
-my $perl = from_json($lines[0]);
+my $perl = decode_json($lines[0]);
 
 ok $perl, 'got JSON';
 is $perl->{value} , 'Sol' , 'got data';
diff --git a/t/Catmandu-Exporter-JSON.t b/t/Catmandu-Exporter-JSON.t
index 6919473..cdc5c52 100644
--- a/t/Catmandu-Exporter-JSON.t
+++ b/t/Catmandu-Exporter-JSON.t
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 use Test::More;
 use Test::Exception;
-use JSON ();
+use JSON::XS ();
 
 my $pkg;
 BEGIN {
@@ -22,7 +22,7 @@ isa_ok $exporter, $pkg;
 
 $exporter->add($_) for @$data;
 $exporter->commit;
-is_deeply $data, [ map { JSON::decode_json($_) } split /[\r\n]+/, $file ];
+is_deeply $data, [ map { JSON::XS::decode_json($_) } split /[\r\n]+/, $file ];
 
 is($exporter->count, 3, "Count ok");
 
diff --git a/t/Catmandu-Fix-from_json.t b/t/Catmandu-Fix-from_json.t
index 7fc78f7..d83311d 100644
--- a/t/Catmandu-Fix-from_json.t
+++ b/t/Catmandu-Fix-from_json.t
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 use Test::More;
 use Test::Exception;
-use JSON ();
+use JSON::XS ();
 
 my $pkg;
 BEGIN {
@@ -12,7 +12,7 @@ BEGIN {
     use_ok $pkg;
 }
 
-my $json = JSON->new->utf8(0)->allow_nonref(1);
+my $json = JSON::XS->new->utf8(0)->allow_nonref(1);
 
 is_deeply
     $pkg->new('name')->fix({name => $json->encode(["Joe"])}),
diff --git a/t/Catmandu-Fix-to_json.t b/t/Catmandu-Fix-to_json.t
index 9f78842..b9a2e4f 100644
--- a/t/Catmandu-Fix-to_json.t
+++ b/t/Catmandu-Fix-to_json.t
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 use Test::More;
 use Test::Exception;
-use JSON ();
+use JSON::XS ();
 
 my $pkg;
 BEGIN {
@@ -12,7 +12,7 @@ BEGIN {
     use_ok $pkg;
 }
 
-my $json = JSON->new->utf8(0)->allow_nonref(1);
+my $json = JSON::XS->new->utf8(0)->allow_nonref(1);
 
 is_deeply
     $pkg->new('name')->fix({name => ["Joe"]}),

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-perl.git



More information about the Pkg-perl-cvs-commits mailing list