line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Presto::Client::ContentHandlers::JSON; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:MPERRY'; |
3
|
|
|
|
|
|
|
$App::Presto::Client::ContentHandlers::JSON::VERSION = '0.010'; |
4
|
|
|
|
|
|
|
# ABSTRACT: Handles (de)serializing of JSON requests/responses |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
13273
|
use Moo; |
|
1
|
|
|
|
|
9542
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
my $HAS_JSON; |
8
|
|
|
|
|
|
|
BEGIN { |
9
|
1
|
|
|
1
|
|
1711
|
eval 'use JSON; $HAS_JSON = 1;' |
|
1
|
|
|
1
|
|
572
|
|
|
1
|
|
|
|
|
10093
|
|
|
1
|
|
|
|
|
3
|
|
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
sub can_deserialize { |
12
|
1
|
|
|
1
|
0
|
440
|
my $self = shift; |
13
|
1
|
|
|
|
|
1
|
my $content_type = shift; |
14
|
1
|
50
|
|
|
|
5
|
return unless $HAS_JSON; |
15
|
1
|
|
|
|
|
5
|
return $content_type =~ m{^application/json}i; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub deserialize { |
19
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
20
|
0
|
|
|
|
|
|
my $content = shift; |
21
|
0
|
|
|
|
|
|
my $ref; |
22
|
0
|
0
|
0
|
|
|
|
eval { $ref = JSON::decode_json($content) || 1 } or do { |
|
0
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
warn "Unable to parse JSON: $@"; |
24
|
|
|
|
|
|
|
}; |
25
|
0
|
|
|
|
|
|
return $ref; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub can_serialize { |
29
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
30
|
0
|
|
|
|
|
|
my $content_type = shift; |
31
|
0
|
0
|
|
|
|
|
return unless $HAS_JSON; |
32
|
0
|
|
|
|
|
|
return $content_type =~ m{^application/json}i; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
sub serialize { |
35
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
36
|
0
|
|
|
|
|
|
my $data = shift; |
37
|
0
|
|
|
|
|
|
return JSON::encode_json($data); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |