blib/lib/JSON/Conditional.pm

filter: Statementstmt 69.2% 27 / 39 Branchbran 42.8% 6 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.8% 9 / 11 Podpod 100% 5 / 5 totaltotal 64.8% 48 / 74 CC 9 SCAR 12.0
CC
9
Cov
61%
encode_file
6.0
decode_file
6.0
decode
4.1
CRAP 3.3
↑ Summary
1 package JSON::Conditional;
2 14 ▶use 5.006; use strict; use warnings; our $VERSION = '1.03';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use JSON; use base 'Struct::Conditional';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 14 our $JSON;
6  
7 14 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 $JSON = JSON->new->pretty(1)->allow_blessed->convert_blessed;
9 }
10  
11 1 ▶sub encode {
Subroutine encode: called CC=2 SCAR=8.1
Pod documented
12 1 ▶ if ($_[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2]) 0 1 1
13 0 $_[0]->encode_file($_[1], $_[2]);
14 }
15 1 $JSON->encode($_[1]);
16 }
17  
18 0 ▶sub encode_file {
Subroutine encode_file: not called CC=2 SCAR=17.9
Pod documented
19 0 ▶ open my $file, '>', $_[2] or die "cannot open file $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $file, ">", $_[2] or die "cannot open file $!" 0 0 0
20 0 print $file $_[0]->encode($_[1]);
21 0 close $file;
22 0 return $file;
23 }
24  
25 15 ▶sub decode {
Subroutine decode: called CC=3 SCAR=14.2
Pod documented
26 15 ▶ if ( $_[1] !~ m/\n/ && -f $_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $_[1] =~ /\n/ and -f $_[1]) 0 15 15
Condition33%1/3
not $_[1] =~ /\n/ and -f $_[1]
!ll&&!rl&&r
1500
MC/DC0%0/2
not $_[1] =~ /\n/ and -f $_[1]
not $_[1] =~ /\n/ -f $_[1]
Truth table33%1/3
not(A) and B
A= not $_[1] =~ /\n/B= -f $_[1]
ABresult
0X0
100
111
27 0 return $_[0]->decode_file($_[1]);
28 }
29 15 $JSON->decode($_[1]);
30 }
31  
32 0 ▶sub decode_file {
Subroutine decode_file: not called CC=2 SCAR=17.9
Pod documented
33 0 ▶ open my $file, '<', $_[1] or die "cannot open file $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $file, "<", $_[1] or die "cannot open file $!" 0 0 0
34 0 my $content = do { local $/; <$file> };
35 0 close $file;
36 0 return $_[0]->decode($content);
37 }
38  
39 15 ▶sub compile {
Subroutine compile: called CC=4 SCAR=14.1
Pod documented
40 15 my ($self, $json, $params, $return_struct, $out_file) = @_;
41 15 ▶ $json = $self->decode($json)
Branch: 1 branch
BranchTrueFalseTotal
unless ref $json 15 0 15
42 unless ref $json;
43 15 ▶ $params = $self->decode($params) unless ref $params;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $params 0 15 15
44 15 $json = $self->SUPER::compile($json, $params);
45 15 ▶ return $return_struct
Branch: 1 branch
BranchTrueFalseTotal
$return_struct ? : 14 1 15
46 ? $json
47 : $self->encode($json, $out_file);
48 }
49  
50 14 1;
51  
52 __END__
↑ Summary