Hello community,
here is the log from the commit of package perl-Cpanel-JSON-XS for
openSUSE:Factory checked in at 2019-12-17 16:54:43
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/perl-Cpanel-JSON-XS (Old)
and /work/SRC/openSUSE:Factory/.perl-Cpanel-JSON-XS.new.4691 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-Cpanel-JSON-XS"
Tue Dec 17 16:54:43 2019 rev:25 rq:757550 version:4.18
Changes:
--------
--- /work/SRC/openSUSE:Factory/perl-Cpanel-JSON-XS/perl-Cpanel-JSON-XS.changes
2019-12-02 13:33:35.224660233 +0100
+++
/work/SRC/openSUSE:Factory/.perl-Cpanel-JSON-XS.new.4691/perl-Cpanel-JSON-XS.changes
2019-12-17 16:54:43.453343500 +0100
@@ -1,0 +2,18 @@
+Sat Dec 14 03:08:38 UTC 2019 - <[email protected]>
+
+- updated to 4.18
+ see /usr/share/doc/packages/perl-Cpanel-JSON-XS/Changes
+
+ 4.18 2019-12-13 (rurban)
+ - Add new method ->type_all_string (#156 by Pali).
+ When type_all_string is set then encode method produce stable
deterministic
+ string types in result JSON.
+ This can be an alternative to Cpanel::JSON::XS::Type when having
+ deterministic output is required but string JSON types are enough
for any
+ output.
+ - Move SvGETMAGIC() from encode_av() and encode_hv() to encode_sv()
+ (#156 by Pali)
+ - Add Math::BigInt and Math::BigFloat as recommended dependences
+ (#157 by Pali and Grinnz)
+
+-------------------------------------------------------------------
Old:
----
Cpanel-JSON-XS-4.17.tar.gz
New:
----
Cpanel-JSON-XS-4.18.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ perl-Cpanel-JSON-XS.spec ++++++
--- /var/tmp/diff_new_pack.DA10TX/_old 2019-12-17 16:54:44.145343748 +0100
+++ /var/tmp/diff_new_pack.DA10TX/_new 2019-12-17 16:54:44.149343749 +0100
@@ -1,7 +1,7 @@
#
# spec file for package perl-Cpanel-JSON-XS
#
-# Copyright (c) 2019 SUSE LLC
+# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -17,18 +17,19 @@
Name: perl-Cpanel-JSON-XS
-Version: 4.17
+Version: 4.18
Release: 0
%define cpan_name Cpanel-JSON-XS
Summary: CPanel fork of JSON::XS, fast and correct serializing
License: Artistic-1.0 OR GPL-1.0-or-later
Group: Development/Libraries/Perl
-URL: https://metacpan.org/release/%{cpan_name}
+Url: https://metacpan.org/release/%{cpan_name}
Source0:
https://cpan.metacpan.org/authors/id/R/RU/RURBAN/%{cpan_name}-%{version}.tar.gz
Source1: cpanspec.yml
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: perl
BuildRequires: perl-macros
+BuildRequires: perl(Time::Piece)
%{perl_requires}
%description
@@ -49,7 +50,7 @@
%prep
%setup -q -n %{cpan_name}-%{version}
-find . -type f ! -path "*/t/*" ! -name "*.pl" ! -name "*.sh" ! -path "*/bin/*"
! -path "*/script/*" ! -name "configure" -print0 | xargs -0 chmod 644
+find . -type f ! -path "*/t/*" ! -name "*.pl" ! -path "*/bin/*" ! -path
"*/script/*" ! -name "configure" -print0 | xargs -0 chmod 644
%build
perl Makefile.PL INSTALLDIRS=vendor OPTIMIZE="%{optflags}"
++++++ Cpanel-JSON-XS-4.17.tar.gz -> Cpanel-JSON-XS-4.18.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Cpanel-JSON-XS-4.17/Changes
new/Cpanel-JSON-XS-4.18/Changes
--- old/Cpanel-JSON-XS-4.17/Changes 2019-11-05 14:02:50.000000000 +0100
+++ new/Cpanel-JSON-XS-4.18/Changes 2019-12-13 16:49:38.000000000 +0100
@@ -2,6 +2,18 @@
TODO: http://stevehanov.ca/blog/index.php?id=104 compression
+4.18 2019-12-13 (rurban)
+ - Add new method ->type_all_string (#156 by Pali).
+ When type_all_string is set then encode method produce stable
deterministic
+ string types in result JSON.
+ This can be an alternative to Cpanel::JSON::XS::Type when having
+ deterministic output is required but string JSON types are enough
for any
+ output.
+ - Move SvGETMAGIC() from encode_av() and encode_hv() to encode_sv()
+ (#156 by Pali)
+ - Add Math::BigInt and Math::BigFloat as recommended dependences
+ (#157 by Pali and Grinnz)
+
4.17 2019-11-04 (rurban)
- Add Changes tests and fixups (see #155)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Cpanel-JSON-XS-4.17/MANIFEST
new/Cpanel-JSON-XS-4.18/MANIFEST
--- old/Cpanel-JSON-XS-4.17/MANIFEST 2019-11-05 14:29:27.000000000 +0100
+++ new/Cpanel-JSON-XS-4.18/MANIFEST 2019-12-13 16:53:55.000000000 +0100
@@ -42,6 +42,7 @@
t/118_type.t
t/119_type_decode.t
t/11_pc_expo.t
+t/120_type_all_string.t
t/12_blessed.t
t/13_limit.t
t/14_latin1.t
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Cpanel-JSON-XS-4.17/META.json
new/Cpanel-JSON-XS-4.18/META.json
--- old/Cpanel-JSON-XS-4.17/META.json 2019-11-05 14:29:27.000000000 +0100
+++ new/Cpanel-JSON-XS-4.18/META.json 2019-12-13 16:53:55.000000000 +0100
@@ -3,8 +3,8 @@
"author" : [
"Reini Urban <[email protected]>"
],
- "dynamic_config" : 1,
- "generated_by" : "ExtUtils::MakeMaker version 8.3508, CPAN::Meta::Converter
version 2.150010",
+ "dynamic_config" : 0,
+ "generated_by" : "ExtUtils::MakeMaker version 7.38, CPAN::Meta::Converter
version 2.150010",
"license" : [
"perl_5"
],
@@ -32,6 +32,10 @@
}
},
"runtime" : {
+ "recommends" : {
+ "Math::BigFloat" : "1.16",
+ "Math::BigInt" : "0"
+ },
"requires" : {
"Carp" : "0",
"Encode" : "1.9801",
@@ -49,14 +53,37 @@
"Config" : "0",
"Data::Dumper" : "0",
"Devel::Peek" : "0",
+ "Encode" : "1.9801",
"POSIX" : "0",
"Test" : "0",
"Test::More" : "0",
"Tie::Array" : "0",
"Tie::Hash" : "0",
+ "Time::Piece" : "0",
"charnames" : "0",
"lib" : "0",
"utf8" : "0"
+ },
+ "suggests" : {
+ "Class::XSAccessor" : "0",
+ "JSON" : "0",
+ "JSON::PP" : "0",
+ "JSON::XS" : "0",
+ "List::MoreUtils" : "0",
+ "Mojo::JSON" : "6.11",
+ "Perl::MinimumVersion" : "1.20",
+ "Pod::Spell::CommonMistakes" : "0",
+ "Test::CPAN::Changes" : "0.40",
+ "Test::CPAN::Meta" : "0.12",
+ "Test::CheckChanges" : "1.14",
+ "Test::Kwalitee" : "0",
+ "Test::LeakTrace" : "0",
+ "Test::MinimumVersion" : "0.008",
+ "Test::Pod" : "1.00",
+ "Test::Pod::Coverage" : "1.04",
+ "Test::Spelling" : "0",
+ "Text::CSV_XS" : "0",
+ "common::sense" : "3.5"
}
}
},
@@ -69,10 +96,11 @@
"http://dev.perl.org/licenses/"
],
"repository" : {
+ "type" : "git",
"url" : "https://github.com/rurban/Cpanel-JSON-XS"
}
},
- "version" : "4.17",
+ "version" : "4.18",
"x_contributors" : [
"Ashley Willis <[email protected]>",
"Chip Salzenberg <[email protected]>",
@@ -99,5 +127,5 @@
"Syohei Yoshida <[email protected]>",
"tevfik1903 <[email protected]>"
],
- "x_serialization_backend" : "JSON::PP version 2.97001_04"
+ "x_serialization_backend" : "JSON::PP version 2.97001"
}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Cpanel-JSON-XS-4.17/META.yml
new/Cpanel-JSON-XS-4.18/META.yml
--- old/Cpanel-JSON-XS-4.17/META.yml 2019-11-05 14:29:27.000000000 +0100
+++ new/Cpanel-JSON-XS-4.18/META.yml 2019-12-13 16:53:55.000000000 +0100
@@ -7,20 +7,22 @@
Config: '0'
Data::Dumper: '0'
Devel::Peek: '0'
+ Encode: '1.9801'
ExtUtils::MakeMaker: '0'
POSIX: '0'
Test: '0'
Test::More: '0'
Tie::Array: '0'
Tie::Hash: '0'
+ Time::Piece: '0'
charnames: '0'
lib: '0'
utf8: '0'
configure_requires:
Config: '0'
ExtUtils::MakeMaker: '0'
-dynamic_config: 1
-generated_by: 'ExtUtils::MakeMaker version 8.3508, CPAN::Meta::Converter
version 2.150010'
+dynamic_config: 0
+generated_by: 'ExtUtils::MakeMaker version 7.38, CPAN::Meta::Converter version
2.150010'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -30,6 +32,9 @@
directory:
- t
- inc
+recommends:
+ Math::BigFloat: '1.16'
+ Math::BigInt: '0'
requires:
Carp: '0'
Encode: '1.9801'
@@ -43,7 +48,7 @@
bugtracker: https://github.com/rurban/Cpanel-JSON-XS/issues
license: http://dev.perl.org/licenses/
repository: https://github.com/rurban/Cpanel-JSON-XS
-version: '4.17'
+version: '4.18'
x_contributors:
- 'Ashley Willis <[email protected]>'
- 'Chip Salzenberg <[email protected]>'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Cpanel-JSON-XS-4.17/Makefile.PL
new/Cpanel-JSON-XS-4.18/Makefile.PL
--- old/Cpanel-JSON-XS-4.17/Makefile.PL 2019-11-05 14:02:50.000000000 +0100
+++ new/Cpanel-JSON-XS-4.18/Makefile.PL 2019-12-13 16:49:38.000000000 +0100
@@ -88,10 +88,18 @@
($ExtUtils::MakeMaker::VERSION gt '6.46'
? ('META_MERGE' =>
{
+ 'meta-spec' => {
+ version => 2,
+ },
+ dynamic_config => 0,
prereqs => {
runtime => {
requires => { # just the script, not the module
'Encode' => '1.9801',
+ },
+ recommends => {
+ 'Math::BigInt' => 0,
+ 'Math::BigFloat' => '1.16',
}
},
test => {
@@ -124,10 +132,10 @@
},
resources =>
{
- license => 'http://dev.perl.org/licenses/',
- bugtracker => 'https://github.com/rurban/Cpanel-JSON-XS/issues',
+ license => [ 'http://dev.perl.org/licenses/' ],
+ bugtracker => { web =>
'https://github.com/rurban/Cpanel-JSON-XS/issues' },
# Note:
https://rt.cpan.org/Public/Dist/Display.html?Queue=Cpanel-JSON-XS is also
observed
- repository => 'https://github.com/rurban/Cpanel-JSON-XS',
+ repository => { url => 'https://github.com/rurban/Cpanel-JSON-XS',
type => 'git' },
},
x_contributors => [
'Ashley Willis <[email protected]>',
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Cpanel-JSON-XS-4.17/README
new/Cpanel-JSON-XS-4.18/README
--- old/Cpanel-JSON-XS-4.17/README 2019-11-05 14:29:28.000000000 +0100
+++ new/Cpanel-JSON-XS-4.18/README 2019-12-13 16:53:55.000000000 +0100
@@ -716,11 +716,27 @@
$enable = $json->get_require_types
$json = $json->require_types([$enable])
- If $enable is true (or missing), then "encode" will require second
- argument with supplied JSON types. See Cpanel::JSON::XS::Type. When
- second argument is not provided (or is undef), then "encode" croaks.
- It also croaks when the type for provided structure in "encode" is
- incomplete.
+ If $enable is true (or missing), then "encode" will require either
+ enabled "type_all_string" or second argument with supplied JSON
+ types. See Cpanel::JSON::XS::Type. When "type_all_string" is not
+ enabled or second argument is not provided (or is undef), then
+ "encode" croaks. It also croaks when the type for provided structure
+ in "encode" is incomplete.
+
+ $json = $json->type_all_string ([$enable])
+ $enable = $json->get_type_all_string
+ $json = $json->type_all_string([$enable])
+
+ If $enable is true (or missing), then "encode" will always produce
+ stable deterministic JSON string types in resulted output.
+
+ When $enable is false, then result of encoded JSON output may be
+ different for different Perl versions and may depends on loaded
+ modules.
+
+ This is useful it you need deterministic JSON types, independently
+ of used Perl version and other modules, but do not want to write
+ complicated type definitions for Cpanel::JSON::XS::Type.
$json = $json->allow_dupkeys ([$enable])
$enabled = $json->get_allow_dupkeys
@@ -1418,6 +1434,9 @@
If you want to have stable and deterministic types in JSON encoder
then use Cpanel::JSON::XS::Type.
+ Alternative way for deterministic types is to use "type_all_string"
+ method when all perl scalars are encoded to JSON strings.
+
Non-deterministic behavior is following: scalars that have last been
used in a string context before encoding as JSON strings, and
anything else as number value:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Cpanel-JSON-XS-4.17/SIGNATURE
new/Cpanel-JSON-XS-4.18/SIGNATURE
--- old/Cpanel-JSON-XS-4.17/SIGNATURE 2019-11-05 14:29:28.000000000 +0100
+++ new/Cpanel-JSON-XS-4.18/SIGNATURE 2019-12-13 16:53:55.000000000 +0100
@@ -12,23 +12,23 @@
not run its Makefile.PL or Build.PL.
-----BEGIN PGP SIGNED MESSAGE-----
-Hash: SHA512
+Hash: SHA256
SHA256 aac2b4bbaa7b93eaf72300f60e167a17e05adcd721087f735ba55d2900f31490
.appveyor.yml
SHA256 082201a3cbd62a55f2e58ffbb991c4b2bb806de0009bc9497ffcc07202f60855
.github/FUNDING.yml
SHA256 fb7ff638c0af0c5dde7148f2b00836ca1afd14fdde99f874922b98b08725af36
.travis.yml
SHA256 c3f2a1a4f66382f796f71a571946722edba53cf3238152b26fd325f4c2f1a20f
.whitesource
SHA256 8de3540a3cd7ecc9a9dcb48975fe852c082fe17d4462f87bb72aa7cc47f083ad COPYING
-SHA256 58ca6acc48780bd72a9163a95d6119f89f719292588612258c025814e04d1fd2 Changes
-SHA256 1a2ec479500e3582ac2b9ed76a4c116f07cc77b4ad9af2dee5eb1a5af6737ebb
MANIFEST
-SHA256 729d7112f66bb707191aa5a0b593e35f806d92f7ff22c41cb5102341bd43d242
META.json
-SHA256 f448b2b58cde97cfebd20b0d0a5dd87d7b9620a7ffaca88767fb8fb751c3d19f
META.yml
-SHA256 997ce707680f64c4a628aa604819b33ee484aab950e1c165965973f128dcb0ee
Makefile.PL
-SHA256 5047896b50e641c9b78b1013f145762b223223a20b0991102c450dedb3054e7a README
-SHA256 0dbd533f55dcce6ef93268f3c70c9ea050971fd3a52669fc8b0957fa731f29d7 XS.pm
-SHA256 2d0eed72b7eb67c68f8f54c160f3022cda2fb62372fcbc8f4966872f6456f4a1 XS.xs
+SHA256 eaf2458c09ef069043ec22ffcff989e4b1bbf87879988c71d6d2f78bd94e6a81 Changes
+SHA256 b676c2364f0118f6b973c4a0d3021a5f2b9746a6d3111f518f8ab0725b34123a
MANIFEST
+SHA256 5e3f2d875cae70a48a2ff082d54719d3b98a0c84e088822edecf852142c84aab
META.json
+SHA256 3ebbd25e71eef86e0719b75e886fb00fa6514baac6d21ecc893ac6eab4291108
META.yml
+SHA256 e4e901f402d07d3ca2b4a8ce90b1912980072367bf61faa95874e4e3b38cdc32
Makefile.PL
+SHA256 e2bbfc6c67915abca519b1e2172384f6229e8c4c8e08c140ad4533a349850d1b README
+SHA256 1b1b58a4f39cbcabb6ad6a5699daac64550244a3c8f65a4f82f4ebbbd6513942 XS.pm
+SHA256 6d683a305a9692731f2dc8eac2bce9da9b64bba438e50d5cea9e3e8b97d8b4d1 XS.xs
SHA256 c95e4b970183cbd6d1ec9c88c37a80f12bd2b66ed6be3c008ffd578d2f622c01
XS/Boolean.pm
-SHA256 ca0447b652d5547206091e8de2799308ffffbe5b5f00a9195641580070573149
XS/Type.pm
+SHA256 20596259e7e399ed1984a469a9a907be878499406d5285a11f1ab98f93aff44f
XS/Type.pm
SHA256 2f34a530b7ce981b0df9aacd2b6944ccf74c4a7f8bb49fde57b342663e7feb26
bin/cpanel_json_xs
SHA256 0d188abe82c2270e7bc5fc21de1d8210bfc52118a834b22592781bb2879a6065
eg/bench
SHA256 3290077eba2e57ff1d2bf46c2a7d34a3b9c7f9b24fe517a3943430f5720da95f
ppport.h
@@ -60,6 +60,7 @@
SHA256 5cd66b444afc6323e9edfa1cc2eddc19ca212e05381e0ee5f1fa74bd7de86a2b
t/118_type.t
SHA256 5f4f0f1d4221f5b5c28c1988f4d127462a42f36ae82fedd7319c8e0fbfbd57eb
t/119_type_decode.t
SHA256 8f0f898f0499424740eea5e2537e97faee949b1e3981a1588b1a61645d942d3c
t/11_pc_expo.t
+SHA256 67295534f9f44b6c2fd9375a4baff3b959318ce2468d466204efd1aeb8caadae
t/120_type_all_string.t
SHA256 9807d307292461a749f5e1fe4b3b1469e743ea2413e6e6c19208304ca5926f69
t/12_blessed.t
SHA256 43a8dfc79182d0ea1462e9266bad1197bc172a9698c0fd002a8e9b0324112ca7
t/13_limit.t
SHA256 99275341c61a98875e26651c858941a299bf6a6fb99a2d60e04d22395b69e3fb
t/14_latin1.t
@@ -438,16 +439,16 @@
SHA256 3e77c26b01896ae196cbbc88f1a72530c4b0d412245b1f9df5184f782eccaec9
xt/perl_minimum_version.t
SHA256 763b7c3057710be453f94661badc01243f2ec528aa274760f6273e9eab443022
xt/pod-coverage.t
SHA256 85b87067a123cec4ca7b0268f4285274ce5216bb5bf6f4479d5988fce05b2295
xt/pod-spell-mistakes.t
-SHA256 4957bf202f71abf4ee1372ea057199676b42663928c77c757180829e94a99587
xt/pod-spelling.t
+SHA256 c5f72383a02e5db78b4ef80a4cb48601dd1c9249bcc469200a6bbc0b26f62ed4
xt/pod-spelling.t
SHA256 aca6f846869ab2e4881e807739086e1535b1438bd0e23d7a021360742736a6a9
xt/pod.t
-----BEGIN PGP SIGNATURE-----
-iQEzBAEBCgAdFiEEKJWogdNCcPq/6PdHtPYzOeZdZBQFAl3BeTgACgkQtPYzOeZd
-ZBQwOQgAg4L/B9/KLLQqYGQSjUqa02TZAHNAIXasyH7s9MmWzWTCo91dzSlPP8V+
-CJimu8G4+lVm1ob5SUc2UfIAczGpAXl4LUs2KCJiqxxxcBBN8eX06rvj9x7Hv/Az
-z85MI48ysJIHSU04UDNS1D7AXQ6b6ptY/d7gjWpSJQNggbi0JTnWOX3WRpzWT/rd
-8TiEKTx73lkHbk2mlpDOgWKqPd9Qb9vYPK5+q9XBgiJjvFUOaCleolkubbXFeSuX
-Hf62AiaHk3jUyduGNbrKOugl+gklK1TMvK1qvvFaf+MhGcJNFSOhqo5Ok6OTaj6M
-eTy8W97nl0t44yOB1DFB01ea7gUbAw==
-=I9ui
+iQEzBAEBCAAdFiEEKJWogdNCcPq/6PdHtPYzOeZdZBQFAl3ztBMACgkQtPYzOeZd
+ZBRdHwf9G3PquzSTKFHjlbEtN5TZlQIEg+mrhoylBm8l0fU7EutKrtJ9CzrWQc64
+i/5Meyg4n0V7+yrIsOPYwl5/WeJaA4Tmm8zeZQvulfjhQvy0P/Drw97iSW/6+AyS
+vqWn1+o43ThgbdGs3RaV9nCZh6C9CYtSsygb8yqV5z4XPZoMI5xUL0VT/aEjss8u
+8gSIijMS2LQDS3d8MkK6dc9dEmvSCjwtaTIlDLQ7kLlwnSKybFFU3GGa/X92nw/1
+N8ZuZJvLjpzBFrCsz9PR5KBY262Wl0aA48lZ1ltiIFuf03zKjyxzKvncSZToT7Ga
+lrxYLm7gRvEdzNcz7zw0YTreyLgcIQ==
+=Pe4m
-----END PGP SIGNATURE-----
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Cpanel-JSON-XS-4.17/XS/Type.pm
new/Cpanel-JSON-XS-4.18/XS/Type.pm
--- old/Cpanel-JSON-XS-4.17/XS/Type.pm 2019-06-10 15:18:43.000000000 +0200
+++ new/Cpanel-JSON-XS-4.18/XS/Type.pm 2019-12-13 16:49:38.000000000 +0100
@@ -174,6 +174,12 @@
Like L<C<json_type_anyof>|/json_type_anyof>, but scalar can be only
perl's C<undef>.
+=back
+
+=head2 Recursive specifications
+
+=over 4
+
=item json_type_weaken
This function can be used as an argument for L</json_type_arrayof>,
@@ -191,6 +197,25 @@
json_type_arrayof(JSON_TYPE_STRING),
);
+If you want to encode all perl scalars to JSON string types despite
+how complicated is input perl structure you can define JSON type
+specification for alternatives recursively. It could be defined as:
+
+ my $type = json_type_anyof();
+ $type->[0] = JSON_TYPE_STRING_OR_NULL;
+ $type->[1] = json_type_arrayof(json_type_weaken($type));
+ $type->[2] = json_type_hashof(json_type_weaken($type));
+
+ print encode_json([ 10, "10", { key => 10 } ], $type);
+ # ["10","10",{"key":"10"}]
+
+An alternative solution for encoding all scalars to JSON strings is to
+use C<type_all_string> method of L<Cpanel::JSON::XS> itself:
+
+ my $json = Cpanel::JSON::XS->new->type_all_string;
+ print $json->encode([ 10, "10", { key => 10 } ]);
+ # ["10","10",{"key":"10"}]
+
=back
=head1 AUTHOR
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Cpanel-JSON-XS-4.17/XS.pm
new/Cpanel-JSON-XS-4.18/XS.pm
--- old/Cpanel-JSON-XS-4.17/XS.pm 2019-11-05 14:02:50.000000000 +0100
+++ new/Cpanel-JSON-XS-4.18/XS.pm 2019-12-13 16:49:38.000000000 +0100
@@ -1,5 +1,5 @@
package Cpanel::JSON::XS;
-our $VERSION = '4.17';
+our $VERSION = '4.18';
our $XS_VERSION = $VERSION;
# $VERSION = eval $VERSION;
@@ -839,11 +839,28 @@
$json = $json->require_types([$enable])
If C<$enable> is true (or missing), then C<encode> will require
-second argument with supplied JSON types. See L<Cpanel::JSON::XS::Type>.
-When second argument is not provided (or is undef), then C<encode>
+either enabled C<type_all_string> or second argument with supplied JSON types.
+See L<Cpanel::JSON::XS::Type>. When C<type_all_string> is not enabled or
+second argument is not provided (or is undef), then C<encode>
croaks. It also croaks when the type for provided structure in
C<encode> is incomplete.
+=item $json = $json->type_all_string ([$enable])
+
+=item $enable = $json->get_type_all_string
+
+ $json = $json->type_all_string([$enable])
+
+If C<$enable> is true (or missing), then C<encode> will always
+produce stable deterministic JSON string types in resulted output.
+
+When C<$enable> is false, then result of encoded JSON output may be
+different for different Perl versions and may depends on loaded modules.
+
+This is useful it you need deterministic JSON types, independently of used
+Perl version and other modules, but do not want to write complicated type
+definitions for L<Cpanel::JSON::XS::Type>.
+
=item $json = $json->allow_dupkeys ([$enable])
=item $enabled = $json->get_allow_dupkeys
@@ -1590,6 +1607,9 @@
If you want to have stable and deterministic types in JSON encoder then
use L<Cpanel::JSON::XS::Type>.
+Alternative way for deterministic types is to use C<type_all_string>
+method when all perl scalars are encoded to JSON strings.
+
Non-deterministic behavior is following: scalars that have last been
used in a string context before encoding as JSON strings, and anything
else as number value:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Cpanel-JSON-XS-4.17/XS.xs
new/Cpanel-JSON-XS-4.18/XS.xs
--- old/Cpanel-JSON-XS-4.17/XS.xs 2019-11-04 16:54:24.000000000 +0100
+++ new/Cpanel-JSON-XS-4.18/XS.xs 2019-12-13 16:49:38.000000000 +0100
@@ -330,6 +330,7 @@
#define F_UNBLESSED_BOOL 0x00400000UL
#define F_ALLOW_DUPKEYS 0x00800000UL
#define F_REQUIRE_TYPES 0x01000000UL
+#define F_TYPE_ALL_STRING 0x02000000UL
#define F_HOOK 0x80000000UL /* some hooks exist, so slow-path
processing */
#define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER
@@ -1059,8 +1060,6 @@
if (enc->indent >= enc->json.max_depth)
croak (ERR_NESTING_EXCEEDED);
- SvGETMAGIC (typesv);
-
if (UNLIKELY (SvOK (typesv)))
{
if (SvROK (typesv) &&
@@ -1220,8 +1219,6 @@
if (enc->indent >= enc->json.max_depth)
croak (ERR_NESTING_EXCEEDED);
- SvGETMAGIC (typesv);
-
if (UNLIKELY (SvOK (typesv)))
{
if (SvROK (typesv) &&
@@ -1775,8 +1772,9 @@
int force_conversion = 0;
SvGETMAGIC (sv);
+ SvGETMAGIC (typesv);
- if (UNLIKELY (!(SvOK (typesv)) && (enc->json.flags & F_REQUIRE_TYPES)))
+ if (UNLIKELY (!(SvOK (typesv)) && (enc->json.flags & F_REQUIRE_TYPES) &&
!(enc->json.flags & F_TYPE_ALL_STRING)))
croak ("type for '%s' was not specified", SvPV_nolen (sv));
if (SvROK (sv) && !SvOBJECT (SvRV (sv)))
@@ -1794,7 +1792,8 @@
}
}
- SvGETMAGIC (typesv);
+ if (UNLIKELY (!(SvOK (typesv)) && (enc->json.flags & F_TYPE_ALL_STRING)))
+ typesv = sv_2mortal (newSViv (JSON_TYPE_STRING | JSON_TYPE_CAN_BE_NULL));
if (UNLIKELY (SvOK (typesv)))
{
@@ -4535,6 +4534,7 @@
unblessed_bool = F_UNBLESSED_BOOL
allow_dupkeys = F_ALLOW_DUPKEYS
require_types = F_REQUIRE_TYPES
+ type_all_string = F_TYPE_ALL_STRING
PPCODE:
if (enable)
self->flags |= ix;
@@ -4567,6 +4567,7 @@
get_unblessed_bool = F_UNBLESSED_BOOL
get_allow_dupkeys = F_ALLOW_DUPKEYS
get_require_types = F_REQUIRE_TYPES
+ get_type_all_string = F_TYPE_ALL_STRING
PPCODE:
XPUSHs (boolSV (self->flags & ix));
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Cpanel-JSON-XS-4.17/t/120_type_all_string.t
new/Cpanel-JSON-XS-4.18/t/120_type_all_string.t
--- old/Cpanel-JSON-XS-4.17/t/120_type_all_string.t 1970-01-01
01:00:00.000000000 +0100
+++ new/Cpanel-JSON-XS-4.18/t/120_type_all_string.t 2019-12-13
16:49:38.000000000 +0100
@@ -0,0 +1,14 @@
+use strict;
+use warnings;
+
+use Cpanel::JSON::XS;
+
+use Test::More tests => 5;
+
+my $sjson =
Cpanel::JSON::XS->new->canonical->require_types->type_all_string->allow_nonref;
+
+is($sjson->encode(0), '"0"');
+is($sjson->encode("0"), '"0"');
+is($sjson->encode(0.5), '"0.5"');
+is($sjson->encode("0.5"), '"0.5"');
+is($sjson->encode([ 1, "2", { key1 => 3.5 }, [ "string", -10 ] ]),
'["1","2",{"key1":"3.5"},["string","-10"]]');
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Cpanel-JSON-XS-4.17/xt/pod-spelling.t
new/Cpanel-JSON-XS-4.18/xt/pod-spelling.t
--- old/Cpanel-JSON-XS-4.17/xt/pod-spelling.t 2019-06-10 15:26:34.000000000
+0200
+++ new/Cpanel-JSON-XS-4.18/xt/pod-spelling.t 2019-12-13 16:49:38.000000000
+0100
@@ -13,6 +13,24 @@
all_pod_files_spelling_ok();
__DATA__
+14k
+180k
+18KB
+8MB
+KOI8
+RFC4627
+RFC7158
+RFC7159
+amd64
+favourably
+latin1
+licences
+utf8
+www
+16be
+16le
+32le
+32be
BMP
BOM
BOM's