From c580bb8d722a2508ac7c9a5304517f3932cc8dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Tue, 4 Dec 2018 13:55:23 +0100 Subject: [PATCH] Adapt to changes in JSON-XS-4.0 --- ...ow_nonref-in-JSON-XS-4-and-JSON-PP-3.patch | 120 ++++++++++++++++++ JSON-Any-1.39-Support-JSON-XS-4.patch | 36 ++++++ perl-JSON-Any.spec | 14 +- 3 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 JSON-Any-1.39-Disable-allow_nonref-in-JSON-XS-4-and-JSON-PP-3.patch create mode 100644 JSON-Any-1.39-Support-JSON-XS-4.patch diff --git a/JSON-Any-1.39-Disable-allow_nonref-in-JSON-XS-4-and-JSON-PP-3.patch b/JSON-Any-1.39-Disable-allow_nonref-in-JSON-XS-4-and-JSON-PP-3.patch new file mode 100644 index 0000000..4581c15 --- /dev/null +++ b/JSON-Any-1.39-Disable-allow_nonref-in-JSON-XS-4-and-JSON-PP-3.patch @@ -0,0 +1,120 @@ +From 2361260e8d4c84ce6ab43f225322b28a8e4e4391 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= +Date: Mon, 4 Feb 2019 16:14:30 +0100 +Subject: [PATCH] Disable allow_nonref in JSON::XS 4 and JSON:PP 3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This patch disables allow_nonref feature in JSON::XS >= 4 and JSON::PP >= 3. +The reason is to provide a uniform behavior including backends that +do not support it. + + + +Signed-off-by: Petr Písař +--- + lib/JSON/Any.pm | 19 ++++++++++++++---- + t/15-allow_nonref.t | 48 +++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 63 insertions(+), 4 deletions(-) + create mode 100644 t/15-allow_nonref.t + +diff --git a/lib/JSON/Any.pm b/lib/JSON/Any.pm +index 11a4928..b47ca3a 100644 +--- a/lib/JSON/Any.pm ++++ b/lib/JSON/Any.pm +@@ -207,9 +207,17 @@ BEGIN { + ); + + # JSON::PP has the same API as JSON.pm v2 +- $conf{json_pp} = { %{ $conf{json_2} } }; +- $conf{json_pp}{get_true} = sub { return JSON::PP::true(); }; +- $conf{json_pp}{get_false} = sub { return JSON::PP::false(); }; ++ $conf{json_pp_2} = { %{ $conf{json_2} } }; ++ $conf{json_pp_2}{get_true} = sub { return JSON::PP::true(); }; ++ $conf{json_pp_2}{get_false} = sub { return JSON::PP::false(); }; ++ ++ # JSON::PP 3.99 enables allow_nonref by default. ++ $conf{json_pp_3} = { %{ $conf{json_pp_2} } }; ++ $conf{json_pp_3}{create_object} = sub { ++ $conf{json_pp_2}{create_object}->($_[0], {allow_nonref => 0, %{$_[1]}}); ++ }; ++ ++ $conf{json_pp_4} = { %{ $conf{json_pp_3} } }; + + # Cpanel::JSON::XS is a fork of JSON::XS (currently) + $conf{cpanel_json_xs} = { %{ $conf{json_xs_2} } }; +@@ -224,12 +232,15 @@ BEGIN { + # JSON::XS 4 is almost the same as JSON::XS 3. It only enables + # allow_nonref by default. + $conf{json_xs_4} = { %{ $conf{json_xs_3} } }; ++ $conf{json_xs_4}{create_object} = sub { ++ $conf{json_xs_3}{create_object}->($_[0], {allow_nonref => 0, %{$_[1]}}); ++ }; + } + + sub _make_key { + my $handler = shift; + ( my $key = lc($handler) ) =~ s/::/_/g; +- if ( 'json_xs' eq $key || 'json' eq $key ) { ++ if ( 'json_xs' eq $key || 'json_pp' eq $key || 'json' eq $key ) { + no strict 'refs'; + $key .= "_" . ( split /\./, ${"$handler\::VERSION"} )[0]; + } +diff --git a/t/15-allow_nonref.t b/t/15-allow_nonref.t +new file mode 100644 +index 0000000..7a36df3 +--- /dev/null ++++ b/t/15-allow_nonref.t +@@ -0,0 +1,48 @@ ++use strict; ++use warnings; ++ ++use Test::More; ++use Test::Fatal; ++use JSON::Any; ++ ++my @backends = qw(CPANEL XS PP JSON DWIW); ++ ++plan tests => @backends * 2 * 3; ++ ++test ($_) for @backends; ++ ++sub test { ++ my ($backend) = @_; ++ ++ SKIP: { ++ my $j = eval { ++ JSON::Any->import($backend); ++ JSON::Any->new; ++ }; ++ ++ note("$backend: " . $@), skip("Backend $backend failed to load", 2 * 3) if $@; ++ ++ $j and $j->handler or next; ++ ++ note "handler is " . ( ref( $j->handler ) || $j->handlerType ); ++ ++ for my $json ( 'null', '42', '"hello"' ) { ++ my $data; ++ isnt( ++ exception { $data = $j->jsonToObj($json) }, ++ undef, ++ "decoding '$json' is not supported", ++ ); ++ } ++ ++ for my $object ( undef, 42, 'hello' ) { ++ my $json; ++ my $printable_object = $object // 'undef'; ++ isnt( ++ exception { $json = $j->objToJson($object) }, ++ undef, ++ "encoding '$printable_object' is not supported", ++ ); ++ } ++ }; ++} +-- +2.17.2 + diff --git a/JSON-Any-1.39-Support-JSON-XS-4.patch b/JSON-Any-1.39-Support-JSON-XS-4.patch new file mode 100644 index 0000000..296aac2 --- /dev/null +++ b/JSON-Any-1.39-Support-JSON-XS-4.patch @@ -0,0 +1,36 @@ +From 073c636002cb9c19bba16389e882f1bf4ab23fb2 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= +Date: Tue, 4 Dec 2018 12:52:28 +0100 +Subject: [PATCH] Support JSON::XS 4 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +JSON::XS 4 has the same API as version 3. It only enables allow_nonref +by default. + +CPAN RT#127753 + +Signed-off-by: Petr Písař +--- + lib/JSON/Any.pm | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/lib/JSON/Any.pm b/lib/JSON/Any.pm +index a8a607e..11a4928 100644 +--- a/lib/JSON/Any.pm ++++ b/lib/JSON/Any.pm +@@ -220,6 +220,10 @@ BEGIN { + $conf{json_xs_3} = { %{ $conf{json_xs_2} } }; + $conf{json_xs_3}{get_true} = sub { return Types::Serialiser::true(); }; + $conf{json_xs_3}{get_false} = sub { return Types::Serialiser::false(); }; ++ ++ # JSON::XS 4 is almost the same as JSON::XS 3. It only enables ++ # allow_nonref by default. ++ $conf{json_xs_4} = { %{ $conf{json_xs_3} } }; + } + + sub _make_key { +-- +2.17.2 + diff --git a/perl-JSON-Any.spec b/perl-JSON-Any.spec index 8cae7b3..179907a 100644 --- a/perl-JSON-Any.spec +++ b/perl-JSON-Any.spec @@ -1,10 +1,15 @@ Name: perl-JSON-Any Summary: A meta-module to make working with JSON easier Version: 1.39 -Release: 11%{?dist} +Release: 12%{?dist} License: GPL+ or Artistic -Source0: https://cpan.metacpan.org/authors/id/E/ET/ETHER/JSON-Any-%{version}.tar.gz +Source0: https://cpan.metacpan.org/authors/id/E/ET/ETHER/JSON-Any-%{version}.tar.gz +# Adapt to changes in JSON-XS-4.0, CPAN RT#127753 +Patch0: JSON-Any-1.39-Support-JSON-XS-4.patch +# And disable allow_nonref as requested in CPAN RT#127753 +Patch1: JSON-Any-1.39-Disable-allow_nonref-in-JSON-XS-4-and-JSON-PP-3.patch + URL: https://metacpan.org/release/JSON-Any Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version)) BuildArch: noarch @@ -42,6 +47,8 @@ currently on CPAN. %prep %setup -q -n JSON-Any-%{version} +%patch0 -p1 +%patch1 -p1 find . -type f -exec chmod -c -x {} + @@ -62,6 +69,9 @@ make test %{_mandir}/man3/JSON* %changelog +* Mon Feb 04 2019 Petr Pisar - 1.39-12 +- Adapt to changes in JSON-XS-4.0 (CPAN RT#127753) + * Fri Feb 01 2019 Fedora Release Engineering - 1.39-11 - Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild