line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::XS::VersionOneAndTwo; |
2
|
1
|
|
|
1
|
|
1656
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
3
|
1
|
|
|
1
|
|
4
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
5477
|
use JSON::XS; |
|
1
|
|
|
|
|
26377
|
|
|
1
|
|
|
|
|
379
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.31'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub import { |
9
|
1
|
|
|
1
|
|
9
|
my ( $exporter, @imports ) = @_; |
10
|
1
|
|
|
|
|
43
|
my ( $caller, $file, $line ) = caller; |
11
|
1
|
|
|
|
|
3
|
my $json_xs_version = $JSON::XS::VERSION; |
12
|
1
|
50
|
|
|
|
6
|
if ( $json_xs_version < 2.01 ) { |
13
|
0
|
|
|
|
|
0
|
*{ $caller . '::encode_json' } = \&JSON::XS::to_json; |
|
0
|
|
|
|
|
0
|
|
14
|
0
|
|
|
|
|
0
|
*{ $caller . '::to_json' } = \&JSON::XS::to_json; |
|
0
|
|
|
|
|
0
|
|
15
|
0
|
|
|
|
|
0
|
*{ $caller . '::decode_json' } = \&JSON::XS::from_json; |
|
0
|
|
|
|
|
0
|
|
16
|
0
|
|
|
|
|
0
|
*{ $caller . '::from_json' } = \&JSON::XS::from_json; |
|
0
|
|
|
|
|
0
|
|
17
|
|
|
|
|
|
|
} else { |
18
|
1
|
|
|
|
|
2
|
*{ $caller . '::encode_json' } = \&JSON::XS::encode_json; |
|
1
|
|
|
|
|
7
|
|
19
|
1
|
|
|
|
|
2
|
*{ $caller . '::to_json' } = \&JSON::XS::encode_json; |
|
1
|
|
|
|
|
3
|
|
20
|
1
|
|
|
|
|
2
|
*{ $caller . '::decode_json' } = \&JSON::XS::decode_json; |
|
1
|
|
|
|
|
5
|
|
21
|
1
|
|
|
|
|
2
|
*{ $caller . '::from_json' } = \&JSON::XS::decode_json; |
|
1
|
|
|
|
|
33
|
|
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
1; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
__END__ |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 NAME |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
JSON::XS::VersionOneAndTwo - Support versions 1 and 2 of JSON::XS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 SYNOPSIS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use JSON::XS::VersionOneAndTwo; |
36
|
|
|
|
|
|
|
my $data = { 'three' => [ 1, 2, 3 ] }; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# use JSON::XS version 1.X style |
39
|
|
|
|
|
|
|
my $json1 = to_json($data); |
40
|
|
|
|
|
|
|
my $data1 = from_json($json1); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# or use JSON::XS version 2.X style |
43
|
|
|
|
|
|
|
my $json2 = encode_json($data); |
44
|
|
|
|
|
|
|
my $data2 = decode_json($json2); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 DESCRIPTION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
L<JSON::XS> is by far the best JSON module on the CPAN. However, it changed |
49
|
|
|
|
|
|
|
its API at version 2.01. If you have to maintain code which may be |
50
|
|
|
|
|
|
|
run on systems with either version one or two then this is a bit |
51
|
|
|
|
|
|
|
of a pain. This module takes the pain away without sacrificing performance. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 AUTHOR |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Leon Brocard <acme@astray.com>. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 COPYRIGHT |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Copyright (C) 2008, Leon Brocard |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
This module is free software; you can redistribute it or modify it |
62
|
|
|
|
|
|
|
under the same terms as Perl itself. |