Carton/Util.pm untested

filter: Statementstmt 0.0% 0 / 22 Branchbran n/a Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 40 CC 1 SCAR 6.9
CC
1
Cov
0%
load_json
2.0
dump_json
2.0
from_json
2.0
CRAP 2.0
1 package Carton::Util;
2 use strict;
3 use warnings;
4  
5 sub load_json {
6 my $file = shift;
7  
8 open my $fh, "<", $file or die "$file: $!";
9 from_json(join '', <$fh>);
10 }
11  
12 sub dump_json {
13 my($data, $file) = @_;
14  
15 open my $fh, ">", $file or die "$file: $!";
16 binmode $fh;
17 print $fh to_json($data);
18 }
19  
20 sub from_json {
21 require JSON::PP;
22 JSON::PP->new->utf8->decode($_[0])
23 }
24  
25 sub to_json {
26 my($data) = @_;
27 require JSON::PP;
28 JSON::PP->new->utf8->pretty->canonical->encode($data);
29 }
30  
31 1;