Catmandu/Exporter/JSON.pm

filter: Statementstmt 96.2% 51 / 53 Branchbran 81.8% 18 / 22 Conditioncond 41.6% 5 / 12 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 2 totaltotal 80.1% 89 / 111 CC 16 SCAR 16.1
CC
16
Cov
85%
_build_json
10.0
add
6.1
commit
4.2
CRAP 5.0
« Catmandu/Fix/Bind/iterate.pm ↑ Summary Catmandu/Pluggable.pm »
1 package Catmandu::Exporter::JSON;
2  
3 14 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 14 our $VERSION = '1.2025';
6  
7 14 ▶use Cpanel::JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 14 with 'Catmandu::Exporter';
12  
13 12 ▶has line_delimited => (is => 'ro', default => sub {0});
Subroutine __ANON__: called CC=1 SCAR=0.0
14 33 ▶has array => (is => 'ro', default => sub {1});
Subroutine __ANON__: called CC=1 SCAR=0.0
15 34 ▶has pretty => (is => 'ro', default => sub {0});
Subroutine __ANON__: called CC=1 SCAR=0.0
16 34 ▶has indent => (is => 'ro', default => sub {0});
Subroutine __ANON__: called CC=1 SCAR=0.0
17 34 ▶has space_before => (is => 'ro', default => sub {0});
Subroutine __ANON__: called CC=1 SCAR=0.0
18 34 ▶has space_after => (is => 'ro', default => sub {0});
Subroutine __ANON__: called CC=1 SCAR=0.0
19 33 ▶has canonical => (is => 'ro', default => sub {0});
Subroutine __ANON__: called CC=1 SCAR=0.0
20 14 has json => (is => 'lazy');
21  
22 25 ▶sub _build_json {
Subroutine _build_json: called CC=8 SCAR=23.0
23 25 my ($self) = @_;
24 25 ▶ Cpanel::JSON::XS->new->utf8(0)
Branch: 4 branches
BranchTrueFalseTotal
$self->line_delimited ? : 13 12 25
$self->line_delimited ? : 13 12 25
$self->line_delimited ? : 13 12 25
$self->line_delimited ? : 13 12 25
Condition33%3/9
$self->pretty or $self->indent
l!l&&r!l&&!r
0012
$self->pretty or $self->space_before
l!l&&r!l&&!r
0012
$self->pretty or $self->space_after
l!l&&r!l&&!r
0012
MC/DC0%0/2
$self->pretty or $self->indent
$self->pretty $self->indent
MC/DC0%0/2
$self->pretty or $self->space_before
$self->pretty $self->space_before
MC/DC0%0/2
$self->pretty or $self->space_after
$self->pretty $self->space_after
Truth table33%1/3
A or B
A= $self->prettyB= $self->indent
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $self->prettyB= $self->space_before
ABresult
1X1
011
000
Truth table33%1/3
A or B
A= $self->prettyB= $self->space_after
ABresult
1X1
011
000
25 ->allow_nonref->pretty($self->line_delimited ? 0 : $self->pretty)
26 ->indent($self->line_delimited ? 0 : $self->pretty || $self->indent)
27 ->space_before($self->line_delimited ? 0 : $self->pretty
28 || $self->space_before)
29 ->space_after($self->line_delimited ? 0 : $self->pretty
30 || $self->space_after)->canonical($self->canonical);
31 }
32  
33 278 ▶sub add {
Subroutine add: called CC=6 SCAR=18.2
Pod undocumented
34 278 my ($self, $data) = @_;
35 278 my $fh = $self->fh;
36 278 my $json = $self->json->encode($data);
37 278 ▶ if ($self->line_delimited) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->line_delimited) 21 257 278
38 21 print $fh $json;
39 21 print $fh "\n";
40 21 return;
41 }
42  
43 257 ▶ if ($self->pretty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->pretty) 0 257 257
44 0 chomp $json;
45 }
46 257 ▶ if ($self->array) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->array) 257 0 257
47 257 ▶ if ($self->count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->count) { } 245 12 257
48 245 print $fh ",";
49 245 ▶ print $fh "\n" if $self->pretty;
Branch: 1 branch
BranchTrueFalseTotal
if $self->pretty 0 245 245
50 }
51 else {
52 12 print $fh "[";
53 }
54 }
55 257 print $fh $json;
56 }
57  
58 33 ▶sub commit {
Subroutine commit: called CC=4 SCAR=14.3
Pod undocumented
59 33 my ($self, $data) = @_;
60 33 ▶ if (!$self->line_delimited && $self->array) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->line_delimited and $self->array) 12 21 33
Condition66%2/3
not $self->line_delimited and $self->array
!ll&&!rl&&r
21012
MC/DC50%1/2
not $self->line_delimited and $self->array
not $self->line_delimited $self->array
Truth table66%2/3
not(A) and B
A= not $self->line_delimitedB= $self->array
ABresult
0X0
100
111
61 12 my $fh = $self->fh;
62 12 ▶ unless ($self->count) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->count) 0 12 12
63 0 print $fh "[";
64 }
65 12 print $fh "]\n";
66 }
67 }
68  
69 14 1;
70  
71 __END__
« Catmandu/Fix/Bind/iterate.pm ↑ Summary Catmandu/Pluggable.pm »