| 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
| |||||||||||||||||||||
| 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
Condition0%0/2
&JSON::decode_json($content) || 1
MC/DC0%0/1
&JSON::decode_json($content) || 1
&JSON::decode_json($content)
Truth table0%0/2
A
A= &JSON::decode_json($content)
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||