File Coverage

blib/lib/App/Presto/Client/ContentHandlers/JSON.pm
Criterion Covered Total %
statement 12 26 46.1
branch 1 6 16.6
condition 0 2 0.0
subroutine 5 8 62.5
pod 0 4 0.0
total 18 46 39.1


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