convert from JSON::Any -> JSON::MaybeXS
for now, keep the weird utf8 handling as it is
Karen Etheridge
9 years ago
0 | 0 |
Revision history for {{$dist->name}}
|
1 | 1 |
|
2 | 2 |
{{$NEXT}}
|
|
3 |
- switched the JSON serializer from JSON::Any to JSON::MaybeXS
|
3 | 4 |
|
4 | 5 |
0.47 2014-08-23 22:34:21Z
|
5 | 6 |
- report the versions of all JSON and YAML backends during tests, in an
|
54 | 54 |
-description = Serialize to JSON. You should have at least one serialization format.
|
55 | 55 |
-always_recommend = 1
|
56 | 56 |
-default = 1
|
57 | |
JSON::Any = 1.15
|
|
57 |
JSON::MaybeXS = 1.001000
|
58 | 58 |
|
59 | 59 |
[OptionalFeature / JSON-RuntimeRecommends]
|
60 | 60 |
-description = Serialize to JSON. You should have at least one serialization format.
|
1 | 1 |
# ABSTRACT: A JSON serialization role
|
2 | 2 |
|
3 | 3 |
use Moose::Role;
|
4 | |
use JSON::Any;
|
|
4 |
use JSON::MaybeXS;
|
5 | 5 |
use namespace::autoclean;
|
6 | 6 |
|
7 | 7 |
requires 'pack';
|
|
13 | 13 |
# TODO ugh! this is surely wrong and should be fixed.
|
14 | 14 |
utf8::encode($json) if utf8::is_utf8($json);
|
15 | 15 |
|
16 | |
$class->unpack( JSON::Any->new->jsonToObj($json), @args );
|
|
16 |
$class->unpack( JSON::MaybeXS->new({ utf8 => 1 })->decode( $json), @args );
|
17 | 17 |
}
|
18 | 18 |
|
19 | 19 |
sub freeze {
|
20 | 20 |
my ( $self, @args ) = @_;
|
21 | 21 |
|
22 | |
my $json = JSON::Any->new(canonical => 1)->objToJson( $self->pack(@args) );
|
|
22 |
my $json = JSON::MaybeXS->new({ utf8 => 1, canonical => 1 })->encode($self->pack(@args));
|
23 | 23 |
|
|
24 |
# if it's valid utf8 mark it as such
|
24 | 25 |
# TODO ugh! this is surely wrong and should be fixed.
|
25 | |
utf8::decode($json) if !utf8::is_utf8($json) and utf8::valid($json); # if it's valid utf8 mark it as such
|
|
26 |
utf8::decode($json) if !utf8::is_utf8($json) and utf8::valid($json);
|
26 | 27 |
|
27 | 28 |
return $json;
|
28 | 29 |
}
|
31 | 31 |
sub _inflate_json {
|
32 | 32 |
my ($self, $json) = @_;
|
33 | 33 |
|
34 | |
eval { require JSON::Any; JSON::Any->import };
|
|
34 |
eval { require JSON::MaybeXS; JSON::MaybeXS->import };
|
35 | 35 |
confess "Could not load JSON module because : $@" if $@;
|
36 | 36 |
|
|
37 |
# this is actually a bad idea, but for consistency, we'll have to keep
|
|
38 |
# doing it...
|
37 | 39 |
utf8::encode($json) if utf8::is_utf8($json);
|
38 | 40 |
|
39 | |
my $data = eval { JSON::Any->jsonToObj($json) };
|
|
41 |
my $data = eval { JSON::MaybeXS->new({ utf8 => 1 })->decode($json) };
|
40 | 42 |
if ($@) {
|
41 | 43 |
confess "There was an error when attempting to peek at JSON: $@";
|
42 | 44 |
}
|
8 | 8 |
|
9 | 9 |
my $dir = tempdir;
|
10 | 10 |
|
11 | |
use Test::Requires 'JSON::Any';
|
12 | |
diag 'using JSON backend: ', JSON::Any->handlerType;
|
|
11 |
use Test::Requires 'JSON::MaybeXS';
|
|
12 |
diag 'using JSON backend: ', JSON;
|
13 | 13 |
|
14 | 14 |
BEGIN {
|
15 | 15 |
plan tests => 10;
|
4 | 4 |
use Test::Deep;
|
5 | 5 |
|
6 | 6 |
use Test::Requires qw(
|
7 | |
JSON::Any
|
|
7 |
JSON::MaybeXS
|
8 | 8 |
Test::Deep::JSON
|
9 | 9 |
);
|
10 | |
diag 'using JSON backend: ', JSON::Any->handlerType;
|
|
10 |
diag 'using JSON backend: ', JSON;
|
11 | 11 |
|
12 | 12 |
BEGIN {
|
13 | 13 |
plan tests => 11;
|
2 | 2 |
|
3 | 3 |
use Test::More;
|
4 | 4 |
|
5 | |
# NOTE:
|
6 | |
# this is because JSON::XS (and Cpanel::JSON::XS) is
|
7 | |
# the only one which really gets utf8 correct
|
8 | |
# - SL
|
9 | |
BEGIN {
|
10 | |
$ENV{JSON_ANY_ORDER} = 'XS CPANEL';
|
11 | |
$ENV{JSON_ANY_CONFIG} = "utf8=0,canonical=1";
|
12 | |
}
|
13 | |
|
14 | 5 |
use Test::Requires qw(
|
15 | 6 |
Encode
|
16 | |
JSON::Any
|
|
7 |
JSON::MaybeXS
|
17 | 8 |
);
|
18 | |
diag 'using JSON backend: ', JSON::Any->handlerType;
|
|
9 |
diag 'using JSON backend: ', JSON;
|
19 | 10 |
|
20 | 11 |
binmode $_, ':utf8' foreach map { Test::Builder->new->$_ } qw(output failure_output todo_output);
|
21 | 12 |
binmode STDOUT, ':utf8';
|
3 | 3 |
use Test::More;
|
4 | 4 |
use Test::Deep;
|
5 | 5 |
|
6 | |
use Test::Requires 'MooseX::Storage::Format::JSONpm';
|
|
6 |
use Test::Requires qw(MooseX::Storage::Format::JSONpm JSON::MaybeXS);
|
7 | 7 |
|
8 | 8 |
BEGIN {
|
9 | 9 |
plan tests => 6;
|
|
60 | 60 |
my $json = eval { Bar->new(x => 10, y => 20)->freeze({ format => $p }) };
|
61 | 61 |
|
62 | 62 |
cmp_deeply(
|
63 | |
JSON->new->decode($json),
|
|
63 |
decode_json($json),
|
64 | 64 |
{
|
65 | 65 |
'__CLASS__' => 'Bar-0.01',
|
66 | 66 |
x => 10,
|
6 | 6 |
|
7 | 7 |
use Test::Requires qw(
|
8 | 8 |
Digest::HMAC_SHA1
|
9 | |
JSON::Any
|
|
9 |
JSON::MaybeXS
|
10 | 10 |
);
|
11 | |
diag 'using JSON backend: ', JSON::Any->handlerType;
|
|
11 |
diag 'using JSON backend: ', JSON;
|
12 | 12 |
|
13 | 13 |
BEGIN {
|
14 | 14 |
plan tests => 26;
|
7 | 7 |
|
8 | 8 |
use Test::Requires qw(
|
9 | 9 |
Test::Deep::JSON
|
10 | |
JSON::Any
|
|
10 |
JSON::MaybeXS
|
11 | 11 |
YAML::Any
|
12 | 12 |
);
|
13 | |
diag 'using JSON backend: ', JSON::Any->handlerType;
|
|
13 |
diag 'using JSON backend: ', JSON;
|
14 | 14 |
diag 'using YAML backend: ', YAML::Any->implementation;
|
15 | 15 |
|
16 | 16 |
BEGIN {
|
9 | 9 |
|
10 | 10 |
use Test::Requires qw(
|
11 | 11 |
IO::AtomicFile
|
12 | |
JSON::Any
|
|
12 |
JSON::MaybeXS
|
13 | 13 |
);
|
14 | |
diag 'using JSON backend: ', JSON::Any->handlerType;
|
|
14 |
diag 'using JSON backend: ', JSON;
|
15 | 15 |
|
16 | 16 |
BEGIN {
|
17 | 17 |
plan tests => 24;
|
6 | 6 |
use File::Spec::Functions;
|
7 | 7 |
my $dir = tempdir;
|
8 | 8 |
|
9 | |
use Test::Requires 'JSON::Any';
|
10 | |
diag 'using JSON backend: ', JSON::Any->handlerType;
|
|
9 |
use Test::Requires 'JSON::MaybeXS';
|
|
10 |
diag 'using JSON backend: ', JSON;
|
11 | 11 |
|
12 | 12 |
BEGIN {
|
13 | 13 |
plan tests => 14;
|
7 | 7 |
my $dir = tempdir( CLEANUP => 1 );
|
8 | 8 |
|
9 | 9 |
use Test::Requires qw(
|
10 | |
JSON::Any
|
|
10 |
JSON::MaybeXS
|
11 | 11 |
IO::AtomicFile
|
12 | 12 |
);
|
13 | |
diag 'using JSON backend: ', JSON::Any->handlerType;
|
|
13 |
diag 'using JSON backend: ', JSON;
|
14 | 14 |
|
15 | 15 |
BEGIN {
|
16 | 16 |
plan tests => 14;
|
5 | 5 |
use File::Spec::Functions;
|
6 | 6 |
my $dir = tempdir( CLEANUP => 1 );
|
7 | 7 |
|
8 | |
# NOTE:
|
9 | |
# this is because JSON::XS (and Cpanel::JSON::XS) is
|
10 | |
# the only one which really gets utf8 correct
|
11 | |
# - SL
|
12 | |
BEGIN {
|
13 | |
$ENV{JSON_ANY_ORDER} = 'XS CPANEL';
|
14 | |
$ENV{JSON_ANY_CONFIG} = "utf8=0,canonical=1";
|
15 | |
}
|
16 | |
|
17 | 8 |
use Test::Requires qw(
|
18 | |
JSON::Any
|
|
9 |
JSON::MaybeXS
|
19 | 10 |
IO::AtomicFile
|
20 | 11 |
);
|
21 | |
diag 'using JSON backend: ', JSON::Any->handlerType;
|
|
12 |
diag 'using JSON backend: ', JSON;
|
|
13 |
|
|
14 |
diag 'using JSON backend: ', JSON;
|
22 | 15 |
|
23 | 16 |
plan tests => 8;
|
24 | 17 |
use_ok('MooseX::Storage');
|
5 | 5 |
use File::Spec::Functions;
|
6 | 6 |
my $dir = tempdir;
|
7 | 7 |
|
8 | |
# NOTE:
|
9 | |
# this is because JSON::XS (and Cpanel::JSON::XS) is
|
10 | |
# the only one which really gets utf8 correct
|
11 | |
# - SL
|
12 | |
BEGIN {
|
13 | |
$ENV{JSON_ANY_ORDER} = 'XS CPANEL';
|
14 | |
$ENV{JSON_ANY_CONFIG} = "utf8=0,canonical=1";
|
15 | |
}
|
16 | |
|
17 | 8 |
use Test::Requires qw(
|
18 | |
JSON::Any
|
|
9 |
JSON::MaybeXS
|
19 | 10 |
IO::AtomicFile
|
20 | 11 |
);
|
21 | |
diag 'using JSON backend: ', JSON::Any->handlerType;
|
|
12 |
diag 'using JSON backend: ', JSON;
|
22 | 13 |
|
23 | 14 |
binmode $_, ':utf8' foreach map { Test::Builder->new->$_ } qw(output failure_output todo_output);
|
24 | 15 |
binmode STDOUT, ':utf8';
|
25 | 16 |
binmode STDERR, ':utf8';
|
|
17 |
|
|
18 |
diag 'using JSON backend: ', JSON;
|
26 | 19 |
|
27 | 20 |
plan tests => 8;
|
28 | 21 |
use_ok('MooseX::Storage');
|
2 | 2 |
use Test::More;
|
3 | 3 |
use Test::Fatal;
|
4 | 4 |
|
5 | |
use Test::Requires 'JSON::Any';
|
6 | |
diag 'using JSON backend: ', JSON::Any->handlerType;
|
|
5 |
use Test::Requires 'JSON::MaybeXS';
|
|
6 |
diag 'using JSON backend: ', JSON;
|
7 | 7 |
|
8 | 8 |
{
|
9 | 9 |
package Thing;
|