Presto/Client/ContentHandlers/JSON.pm

filter: Statementstmt 51.7% 15 / 29 Branchbran 16.6% 1 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 4 totaltotal 40.8% 20 / 49 CC 5 SCAR 16.5
CC
5
Cov
43%
deserialize
12.0
can_serialize
6.0
can_deserialize
2.0
CRAP 5.2
« Presto/ArgProcessor.pm ↑ Summary Presto/Client/ContentHandlers/XMLSimple.pm »
1 package App::Presto::Client::ContentHandlers::JSON;
2 2 our $AUTHORITY = 'cpan:MPERRY';
3 2 $App::Presto::Client::ContentHandlers::JSON::VERSION = '0.010';
4 # ABSTRACT: Handles (de)serializing of JSON requests/responses
5  
6 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 my $HAS_JSON;
8 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶ eval 'use JSON; $HAS_JSON = 1;'
Subroutine BEGIN: called CC=1 SCAR=0.0
10 }
11 1 ▶sub can_deserialize {
Subroutine can_deserialize: called CC=2 SCAR=7.0
Pod undocumented
12 1 my $self = shift;
13 1 my $content_type = shift;
14 1 ▶ return unless $HAS_JSON;
Branch: 1 branch
BranchTrueFalseTotal
unless $HAS_JSON 0 1 1
15 1 return $content_type =~ m{^application/json}i;
16 }
17  
18 0 ▶sub deserialize {
Subroutine deserialize: not called CC=3 SCAR=24.8
Pod undocumented
19 0 my $self = shift;
20 0 my $content = shift;
21 0 my $ref;
22 0 ▶ eval { $ref = JSON::decode_json($content) || 1 } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $ref = &JSON::decode_json($content) || 1 } } or do { warn "Unable to parse JSON: $@" } 0 0 0
Condition0%0/2
&JSON::decode_json($content) || 1
l!l
00
MC/DC0%0/1
&JSON::decode_json($content) || 1
&JSON::decode_json($content)
Truth table0%0/2
A
A= &JSON::decode_json($content)
Aresult
11
00
23 0 warn "Unable to parse JSON: $@";
24 };
25 0 return $ref;
26 }
27  
28 0 ▶sub can_serialize {
Subroutine can_serialize: not called CC=2 SCAR=17.9
Pod undocumented
29 0 my $self = shift;
30 0 my $content_type = shift;
31 0 ▶ return unless $HAS_JSON;
Branch: 1 branch
BranchTrueFalseTotal
unless $HAS_JSON 0 0 0
32 0 return $content_type =~ m{^application/json}i;
33 }
34 0 ▶sub serialize {
Subroutine serialize: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my $self = shift;
36 0 my $data = shift;
37 0 return JSON::encode_json($data);
38 }
39  
40 2 1;
41  
42 __END__
« Presto/ArgProcessor.pm ↑ Summary Presto/Client/ContentHandlers/XMLSimple.pm »