line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
WebService::TypePad::Util::JSON - JSON utility functions |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 DESCRIPTION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
This is just a wrapper around a singleton JSON object, ensuring that everywhere |
9
|
|
|
|
|
|
|
we deal with JSON we do it in a consistent way. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
We use JSON::Any in order to work with various underlying JSON libraries |
12
|
|
|
|
|
|
|
from CPAN. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package WebService::TypePad::Util::JSON; |
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
3
|
|
14
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
92
|
|
19
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
70
|
|
20
|
|
|
|
|
|
|
|
21
|
3
|
|
|
3
|
|
2866
|
use JSON::Any; |
|
3
|
|
|
|
|
89264
|
|
|
3
|
|
|
|
|
19
|
|
22
|
3
|
|
|
3
|
|
26330
|
use Exporter 'import'; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
560
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT = qw(json_encode json_decode json_true json_false); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 FUNCTIONS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
The functions in this package are not class methods. All will be imported into |
29
|
|
|
|
|
|
|
your package namespace by default. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $json = JSON::Any->new(); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=pod |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 json_encode($ref) |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Given some JSON-able reference (usually a HASH ref), return a JSON string. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub json_encode { |
44
|
0
|
|
|
0
|
1
|
0
|
my ($value) = @_; |
45
|
0
|
|
|
|
|
0
|
return $json->encode($value); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=pod |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 json_decode($ref) |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Given a JSON string, parse it and return some kind of reference (usually a HASH ref). |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub json_decode { |
57
|
0
|
|
|
0
|
1
|
0
|
my ($value) = @_; |
58
|
0
|
|
|
|
|
0
|
return $json->decode($value); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=pod |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 json_true |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Returns some value that, when passed into C, will lead to a JSON true value being generated. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub json_true { |
70
|
5
|
|
|
5
|
1
|
760
|
return $json->true; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=pod |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 json_false |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Returns some value that, when passed into C, will lead to a JSON false value being generated. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub json_false { |
82
|
3
|
|
|
3
|
1
|
33
|
return $json->false; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |