From c1dc8361049d5c3e498ef5a50004b0af5a58a734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Joaqu=C3=ADn=20Atria?= Date: Wed, 12 Jun 2024 13:57:03 +0100 Subject: [PATCH] Switch Perl library from JSON::XS to JSON::MaybeXS (#2952) The JSON::MaybeXS library serves as a compatibility layer to allow users to select the JSON backend that matches their stack, rather than forcing them to install a specific one, while still benefiting from the performance boost of XS libraries if they are available. --- BUILD.md | 2 +- lang/perl/Changes | 3 +++ lang/perl/Makefile.PL | 2 +- lang/perl/bin/avro-to-json | 4 ++-- lang/perl/lib/Avro/Protocol.pm | 4 ++-- lang/perl/lib/Avro/Schema.pm | 4 ++-- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/BUILD.md b/BUILD.md index b619b535769..f9c601681f8 100644 --- a/BUILD.md +++ b/BUILD.md @@ -14,7 +14,7 @@ The following packages must be installed before Avro can be built: - Ruby: Ruby 2.7 or greater, ruby-dev, gem, bundler, snappy - Perl: Perl 5.24.1 or greater, gmake, Module::Install, Module::Install::ReadmeFromPod, Module::Install::Repository, - Math::BigInt, JSON::XS, Try::Tiny, Regexp::Common, Encode, + Math::BigInt, JSON::MaybeXS, Try::Tiny, Regexp::Common, Encode, IO::String, Object::Tiny, Compress::ZLib, Error::Simple, Test::More, Test::Exception, Test::Pod - Rust: rustc and Cargo 1.65.0 or greater diff --git a/lang/perl/Changes b/lang/perl/Changes index 5620745b168..2d4e6c3d5c5 100644 --- a/lang/perl/Changes +++ b/lang/perl/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension Avro + - Switch from JSON::XS to JSON::MaybeXS to support + multiple JSON backends + 1.00 Fri Jan 17 15:00:00 2014 - Relicense under apache license 2.0 diff --git a/lang/perl/Makefile.PL b/lang/perl/Makefile.PL index ffac5e9d11b..b5b0a33ddc8 100644 --- a/lang/perl/Makefile.PL +++ b/lang/perl/Makefile.PL @@ -35,7 +35,7 @@ requires 'Compress::Zstd'; requires 'Encode'; requires 'Error::Simple'; requires 'IO::String'; -requires 'JSON::XS'; +requires 'JSON::MaybeXS'; requires 'Object::Tiny'; requires 'Regexp::Common'; requires 'Try::Tiny'; diff --git a/lang/perl/bin/avro-to-json b/lang/perl/bin/avro-to-json index 2ca4efc44d5..ff6f733b185 100644 --- a/lang/perl/bin/avro-to-json +++ b/lang/perl/bin/avro-to-json @@ -23,9 +23,9 @@ use warnings; use Avro::DataFileReader; use Carp; use IO::File; -use JSON::XS; +use JSON::MaybeXS (); -my $j = JSON::XS->new->allow_nonref; +my $j = JSON::MaybeXS->new->allow_nonref; my $fh = IO::File->new(shift || croak "specify a file"); my $reader = Avro::DataFileReader->new( diff --git a/lang/perl/lib/Avro/Protocol.pm b/lang/perl/lib/Avro/Protocol.pm index ca892bc7463..f701f799266 100644 --- a/lang/perl/lib/Avro/Protocol.pm +++ b/lang/perl/lib/Avro/Protocol.pm @@ -20,7 +20,7 @@ use strict; use warnings; use Carp; -use JSON::XS(); +use JSON::MaybeXS (); use Try::Tiny; use Avro::Protocol::Message; use Avro::Schema; @@ -35,7 +35,7 @@ use Object::Tiny qw{ our $VERSION = '++MODULE_VERSION++'; -my $json = JSON::XS->new->allow_nonref; +my $json = JSON::MaybeXS->new->allow_nonref; sub parse { my $class = shift; diff --git a/lang/perl/lib/Avro/Schema.pm b/lang/perl/lib/Avro/Schema.pm index 5240caed3ea..160f85ded50 100644 --- a/lang/perl/lib/Avro/Schema.pm +++ b/lang/perl/lib/Avro/Schema.pm @@ -20,12 +20,12 @@ use strict; use warnings; use Carp; -use JSON::XS(); +use JSON::MaybeXS (); use Try::Tiny; our $VERSION = '++MODULE_VERSION++'; -my $json = JSON::XS->new->allow_nonref; +my $json = JSON::MaybeXS->new->allow_nonref; sub parse { my $schema = shift;