File Coverage

blib/lib/App/PAIA/JSON.pm
Criterion Covered Total %
statement 18 23 78.2
branch 1 4 25.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 25 35 71.4


line stmt bran cond sub pod time code
1             package App::PAIA::JSON;
2 4     4   15 use strict;
  4         4  
  4         101  
3 4     4   36 use v5.10;
  4         8  
  4         173  
4              
5             our $VERSION = '0.29';
6              
7 4     4   17 use parent 'Exporter';
  4         5  
  4         25  
8             our @EXPORT = qw(decode_json encode_json);
9 4     4   2617 use JSON::PP qw();
  4         37302  
  4         565  
10              
11             sub decode_json {
12 21     21 0 41 my $json = shift;
13 21         26 my $data = eval { JSON::PP->new->utf8->relaxed->decode($json); };
  21         112  
14 21 50       10832 if ($@) {
15 0         0 my $msg = reverse $@;
16 0         0 $msg =~ s/.+? ta //sm;
17 0         0 $msg = "JSON error: " . scalar reverse($msg);
18 0 0       0 $msg .= " in " . shift if @_;
19 0         0 die "$msg\n";
20             }
21 21         51 return $data;
22             }
23              
24             sub encode_json {
25 18     18 0 117 JSON::PP->new->utf8->pretty->encode($_[0]);
26             }
27              
28             1;
29             __END__