blib/lib/Tree/Serial.pm

filter: Statementstmt 13.5% 10 / 74 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 23.0% 3 / 13 Podpod 66.6% 2 / 3 totaltotal 11.9% 15 / 126 CC 16 SCAR 32.4
CC
16
Cov
9%
strs2hash
56.0
strs2lol
42.0
_init
12.0
CRAP 25.6
↑ Summary
1 package Tree::Serial;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use List::Util qw(min reduce sum zip);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION=0.20;
9  
10 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
11 0 my ($class,$data) = @_;
12 0 my $self = {};
13 0 bless $self, $class;
14 0 $self->_init($data);
15 0 return $self;
16 }
17  
18 0 ▶sub _init {
Subroutine _init: not called CC=3 SCAR=24.8
19 0 my ($self,$data) = @_;
20 my %data = (
21 separator => '.',
22 degree => 2,
23 traversal => 0,
24 0 ▶ (defined $data) ? (%{$data}) : (),
Branch: 1 branch
BranchTrueFalseTotal
defined $data ? : 0 0 0
25 );
26 0 ▶ (exists $data{showMissing}) && do {$self->{showMissing} = $data{showMissing}};
Branch: 1 branch
BranchTrueFalseTotal
exists $data{"showMissing"} and do { $self->{"showMissing"} = $data{"showMissing"} } 0 0 0
27 0 @{$self}{qw(separator degree traversal)} = @data{qw(separator degree traversal)};
28 }
29  
30 0 ▶sub _eatWhileNot {
Subroutine _eatWhileNot: not called CC=2 SCAR=17.9
31 0 my ($pred,$acc,$el) = @_;
32 0 my @larger = (@{$acc->[1]}, $el);
33 0 ▶ return ($pred->(\@larger)) ? ([[@{$acc->[0]}, \@larger],[]]) : ([$acc->[0], \@larger]);
Branch: 1 branch
BranchTrueFalseTotal
&$pred(\@larger) ? : 0 0 0
34 }
35  
36 0 ▶sub _chunkBy {
Subroutine _chunkBy: not called CC=1 SCAR=6.9
37 0 my ($pred,$aref) = @_;
38 0 ▶ my $reduction = reduce { _eatWhileNot($pred, $a, $b) } [[],[]], @{$aref};
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 0 return $reduction->[0];
40 }
41  
42 0 ▶sub _isKAry {
Subroutine _isKAry: not called CC=2 SCAR=17.9
43 0 my ($separator,$degree,$aref) = @_;
44 0 ▶ return ((sum map { ($_ eq $separator) ? (-1) : ($degree-1) } @{$aref}) == -1);
Branch: 1 branch
BranchTrueFalseTotal
$_ eq $separator ? : 0 0 0
45 }
46  
47 0 ▶sub _chunkKAry {
Subroutine _chunkKAry: not called CC=1 SCAR=6.9
48 0 my ($separator,$degree,$aref) = @_;
49 0 ▶ my $pred = sub { _isKAry($separator,$degree,$_[0]) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 return _chunkBy($pred,$aref);
51 }
52  
53 0 ▶sub strs2hash {
Subroutine strs2hash: not called CC=7 SCAR=40.3
Pod documented
54 0 my ($self, $aref) = @_;
55 0 ▶ (! scalar @{$aref}) && return {};
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$aref;} or return {} 0 0 0
56 0 ▶ ($aref->[0] eq $self->{separator}) && do {
Branch: 1 branch
BranchTrueFalseTotal
$aref->[0] eq $self->{"separator"} and do { exists $self->{"showMissing"} and defined $self->{"showMissing"} and return {"name", $self->{"showMissing"}}; exists $self->{"showMissing"} and return {}; return } 0 0 0
57 0 ▶ (exists $self->{showMissing} && defined $self->{showMissing}) && return {name => $self->{showMissing}};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"showMissing"} and defined $self->{"showMissing"} and return {"name", $self->{"showMissing"}} 0 0 0
Condition0%0/3
exists $self->{"showMissing"} and defined $self->{"showMissing"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"showMissing"} and defined $self->{"showMissing"}
exists $self->{"showMissing"} defined $self->{"showMissing"}
Truth table0%0/3
A and B
A= exists $self->{"showMissing"}B= defined $self->{"showMissing"}
ABresult
0X0
100
111
58 0 ▶ (exists $self->{showMissing}) && return {};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"showMissing"} and return {} 0 0 0
59 0 return;
60 };
61 0 my @rest = @{$aref}[1..scalar @{$aref}-1];
62 0 my @chunks = @{_chunkKAry($self->{separator}, $self->{degree}, \@rest)};
63 0 ▶ (! exists $self->{showMissing}) && do {@chunks = grep {$_->[0] ne $self->{separator}} @chunks};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"showMissing"} or do { @chunks = grep({$_->[0] ne $self->{"separator"};} @chunks) } 0 0 0
64 my %h = (
65 name => $aref->[0],
66 0 map {$_->[0] => strs2hash($self,$_->[1])} zip [0..$#chunks], \@chunks,
67 );
68 0 return \%h;
69 }
70  
71 0 ▶sub strs2lol {
Subroutine strs2lol: not called CC=6 SCAR=37.4
Pod documented
72 0 my ($self, $aref) = @_;
73 0 ▶ (! scalar @{$aref}) && return [];
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$aref;} or return [] 0 0 0
74 0 ▶ ($aref->[0] eq $self->{separator}) && do {
Branch: 1 branch
BranchTrueFalseTotal
$aref->[0] eq $self->{"separator"} and do { exists $self->{"showMissing"} and defined $self->{"showMissing"} and return [$self->{"showMissing"}]; exists $self->{"showMissing"} and return []; return } 0 0 0
75 0 ▶ (exists $self->{showMissing} && defined $self->{showMissing}) && return [$self->{showMissing}];
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"showMissing"} and defined $self->{"showMissing"} and return [$self->{"showMissing"}] 0 0 0
Condition0%0/3
exists $self->{"showMissing"} and defined $self->{"showMissing"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"showMissing"} and defined $self->{"showMissing"}
exists $self->{"showMissing"} defined $self->{"showMissing"}
Truth table0%0/3
A and B
A= exists $self->{"showMissing"}B= defined $self->{"showMissing"}
ABresult
0X0
100
111
76 0 ▶ (exists $self->{showMissing}) && return [];
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"showMissing"} and return [] 0 0 0
77 0 return;
78 };
79 0 my @rest = @{$aref}[1..scalar @{$aref}-1];
80 0 my $chunks = _chunkKAry($self->{separator}, $self->{degree}, \@rest);
81 0 my @others = map {strs2lol($self,$_)} @{$chunks};
82 0 splice(@others,min(scalar @others, $self->{traversal}),0,$aref->[0]);
83 0 return \@others;
84 }
85  
86 1 1;
87  
88 __END__
↑ Summary