blib/lib/App/sdif/LabelStack.pm

filter: Statementstmt 54.6% 77 / 141 Branchbran 42.8% 18 / 42 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 64.0% 16 / 25 Podpod 0.0% 0 / 19 totaltotal 48.5% 115 / 237 CC 25 SCAR 15.4
CC
25
Cov
52%
push
12.0
unshift
12.0
newlabel
9.7
CRAP 4.6
« blib/lib/App/sdif.pm ↑ Summary blib/lib/App/cdif/Command/OSAscript.pm »
1 package App::sdif::LabelStack;
2  
3 25 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 25 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 56 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod undocumented
10 56 my $class = shift;
11 56 my $obj = bless {
12 LABELS => [],
13 COUNTS => {},
14 LISTS => [],
15 OPTION => { UNIQUE => 1 },
16 ATTR => {},
17 }, $class;
18  
19 56 ▶ $obj->option(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 56 0 56
20  
21 56 ▶ if (my $initial_label = $obj->option('START')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $initial_label = $obj->option("START")) 56 0 56
22 56 $obj->newlabel($initial_label);
23 }
24  
25 56 $obj;
26 }
27  
28 360 ▶sub option { splice @_, 1, 0, 'OPTION' ; goto &__attr }
Subroutine option: called CC=1 SCAR=0.0
Pod undocumented
29 0 ▶sub attr { splice @_, 1, 0, 'ATTR' ; goto &__attr }
Subroutine attr: not called CC=1 SCAR=6.9
Pod undocumented
30 360 ▶sub __attr {
Subroutine __attr: called CC=4 SCAR=13.9
31 360 my $obj = shift;
32 360 my $attr_name = shift;
33  
34 360 ▶ return undef if @_ < 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 1 0 360 360
35 360 ▶ return $obj->{$attr_name}->{+shift} if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 304 56 360
36  
37 56 my $hash = $obj->{$attr_name};
38 56 ▶ while (my($name, $value) = splice @_, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 56 56 112
39 56 $hash->{$name} = $value;
40 }
41  
42 56 $obj;
43 }
44  
45 98 ▶sub exists {
Subroutine exists: called CC=1 SCAR=0.0
Pod undocumented
46 98 my $obj = shift;
47 98 my $label = shift;
48 98 $obj->{COUNTS}->{$label};
49 }
50  
51 0 ▶sub count {
Subroutine count: not called CC=1 SCAR=6.9
Pod undocumented
52 0 my $obj = shift;
53 0 scalar @{$obj->{LISTS}};
54 }
55  
56 124 ▶sub newlabel {
Subroutine newlabel: called CC=5 SCAR=22.7
Pod undocumented
57 124 my $obj = shift;
58 124 my $label = shift;
59 124 ▶ if (my $order = $obj->option('ORDER')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $order = $obj->option("ORDER")) 0 124 124
60 0 for my $l (@$order) {
61 0 ▶ last if $l eq $label;
Branch: 1 branch
BranchTrueFalseTotal
if $l eq $label 0 0 0
62 0 ▶ $obj->exists($l) or $obj->_createlabel($l);
Branch: 1 branch
BranchTrueFalseTotal
$obj->exists($l) or $obj->_createlabel($l) 0 0 0
63 }
64 }
65 124 $obj->_createlabel($label);
66 124 $obj;
67 }
68  
69 124 ▶sub _createlabel {
Subroutine _createlabel: called CC=3 SCAR=11.5
70 124 my $obj = shift;
71 124 my $label = shift;
72 124 ▶ if ($obj->option('UNIQUE') and $obj->{COUNTS}->{$label}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->option("UNIQUE") and $obj->{"COUNTS"}{$label}) 0 124 124
Condition33%1/3
$obj->option("UNIQUE") and $obj->{"COUNTS"}{$label}
!ll&&!rl&&r
01240
MC/DC0%0/2
$obj->option("UNIQUE") and $obj->{"COUNTS"}{$label}
$obj->option("UNIQUE") $obj->{"COUNTS"}{$label}
Truth table33%1/3
A and B
A= $obj->option("UNIQUE")B= $obj->{"COUNTS"}{$label}
ABresult
0X0
100
111
73 0 croak "Duplicated label: $label\n";
74 }
75 124 $obj->{COUNTS}->{$label}++;
76 124 push @{$obj->{LABELS}}, $label;
77 124 push @{$obj->{LISTS}}, [];
78 124 $obj;
79 }
80  
81 343 ▶sub append {
Subroutine append: called CC=3 SCAR=11.0
Pod undocumented
82 343 my $obj = shift;
83 343 my($label, $line) = @_;
84 343 ▶ if ($obj->labels == 0 or $label ne $obj->lastlabel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->labels == 0 or $label ne $obj->lastlabel) 68 275 343
Condition66%2/3
$obj->labels == 0 or $label ne $obj->lastlabel
l!l&&r!l&&!r
068275
MC/DC50%1/2
$obj->labels == 0 or $label ne $obj->lastlabel
$obj->labels == 0 $label ne $obj->lastlabel
Truth table66%2/3
A or B
A= $obj->labels == 0B= $label ne $obj->lastlabel
ABresult
1X1
011
000
85 68 $obj->newlabel($label);
86 }
87 343 push @{$obj->{LISTS}->[-1]}, $line;
88 343 $obj;
89 }
90  
91 511 ▶sub labels {
Subroutine labels: called CC=2 SCAR=8.5
Pod undocumented
92 511 my $obj = shift;
93 511 ▶ if (@_ == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 0) { } 511 0 511
94 511 @{$obj->{LABELS}};
95 } else {
96 0 map { @{$obj->{LABELS}[$_]} } @_;
97 }
98 }
99  
100 822 ▶sub lastlabel {
Subroutine lastlabel: called CC=1 SCAR=0.0
Pod undocumented
101 822 my $obj = shift;
102 822 $obj->{LABELS}->[-1];
103 }
104  
105 36 ▶sub lists {
Subroutine lists: called CC=2 SCAR=8.5
Pod undocumented
106 36 my $obj = shift;
107 36 ▶ if (@_ == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 0) { } 36 0 36
108 36 @{$obj->{LISTS}};
109 } else {
110 0 map { @{$obj->{LISTS}[$_]} } @_;
111 }
112 }
113  
114 0 ▶sub blocks {
Subroutine blocks: not called CC=1 SCAR=6.9
Pod undocumented
115 0 my $obj = shift;
116 0 map { join '', @$_ } $obj->lists;
117 }
118  
119 0 ▶sub listpair {
Subroutine listpair: not called CC=1 SCAR=6.9
Pod undocumented
120 0 my $obj = shift;
121 0 my @labels = $obj->labels;
122 0 map { $labels[$_] => $obj->{LISTS}[$_] } keys @labels;
123 }
124  
125 0 ▶sub blockpair {
Subroutine blockpair: not called CC=1 SCAR=6.9
Pod undocumented
126 0 my $obj = shift;
127 0 my @labels = $obj->labels;
128 0 my @blocks = $obj->blocks;
129 0 map { $labels[$_] => $blocks[$_] } keys @labels;
130 }
131  
132 168 ▶sub match {
Subroutine match: called CC=3 SCAR=11.3
Pod undocumented
133 168 my $obj = shift;
134 168 my $cond = shift;
135 168 my @labels = $obj->labels;
136 168 my @index = do {
137 168 ▶ if (ref($cond) eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $cond eq 'CODE') { } 0 168 168
elsif (ref $cond eq 'Regexp') { } 128 40 168
138 grep {
139 0 local $_ = $labels[$_];
140 0 $cond->();
141 }
142 keys @labels;
143 } elsif (ref $cond eq 'Regexp') {
144 128 grep { $labels[$_] =~ $cond } keys @labels;
145 } else {
146 40 grep { $labels[$_] eq $cond } keys @labels;
147 }
148 };
149 168 @{$obj->{LISTS}}[ @index ];
150 }
151  
152 168 ▶sub collect {
Subroutine collect: called CC=2 SCAR=6.9
Pod undocumented
153 168 my $obj = shift;
154 168 my @list = map { @$_ } $obj->match(@_);
155 168 ▶ wantarray ? @list : join '', @list;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 60 108 168
156 }
157  
158 0 ▶sub push {
Subroutine push: not called CC=3 SCAR=24.8
Pod undocumented
159 0 my $obj = CORE::shift;
160 0 ▶ croak "Invalid argument." if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 0 0
161 0 ▶ while (my($label, $data) = splice @_, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 0 0 0
162 0 CORE::push @{$obj->{LABELS}}, $label;
163 0 CORE::push @{$obj->{LISTS}}, $data;
164 0 $obj->{COUNTS}{$label}++;
165 }
166 0 $obj;
167 }
168  
169 0 ▶sub pop {
Subroutine pop: not called CC=2 SCAR=17.9
Pod undocumented
170 0 my $obj = CORE::shift;
171 0 ▶ return () if $obj->count == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->count == 0 0 0 0
172 0 my $label = CORE::pop @{$obj->{LABELS}};
173 0 my $entry = CORE::pop @{$obj->{LISTS}};
174 0 $obj->{COUNTS}{$label}--;
175 0 ($label, $entry);
176 }
177  
178 0 ▶sub unshift {
Subroutine unshift: not called CC=3 SCAR=24.8
Pod undocumented
179 0 my $obj = CORE::shift;
180 0 ▶ croak "Invalid argument." if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 0 0
181 0 ▶ while (my($label, $data) = splice @_, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 0 0 0
182 0 CORE::unshift @{$obj->{LABELS}}, $label;
183 0 CORE::unshift @{$obj->{LISTS}}, $data;
184 0 $obj->{COUNTS}{$label}++;
185 }
186 0 $obj;
187 }
188  
189 0 ▶sub shift {
Subroutine shift: not called CC=2 SCAR=17.9
Pod undocumented
190 0 my $obj = CORE::shift;
191 0 ▶ return () if $obj->count == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->count == 0 0 0 0
192 0 my $label = CORE::shift @{$obj->{LABELS}};
193 0 my $entry = CORE::shift @{$obj->{LISTS}};
194 0 $obj->{COUNTS}{$label}--;
195 0 ($label, $entry);
196 }
197  
198 25 1;
« blib/lib/App/sdif.pm ↑ Summary blib/lib/App/cdif/Command/OSAscript.pm »