assign/Array.pm

filter: Statementstmt 98.7% 78 / 79 Branchbran 82.3% 28 / 34 Conditioncond 71.4% 5 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 90.3% 121 / 134 CC 22 SCAR 23.0
CC
22
Cov
92%
parse_elem
14.5
gen_code
9.0
BEGIN
1.0
CRAP 10.0
↑ Summary assign/Struct.pm »
1 6 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package assign::Array;
3  
4 6 ▶use assign::Struct;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use base 'assign::Struct';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use assign::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 ▶use XXX;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 71 ▶sub parse_elem {
Subroutine parse_elem: called CC=14 SCAR=26.8
Pod undocumented
12 71 my ($self) = @_;
13 71 my $in = $self->{in};
14 71 my $elems = $self->{elems};
15 71 ▶ while (@$in) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$in) 117 3 120
16 117 my $tok = shift(@$in);
17 117 my $type = ref($tok);
18 117 ▶ next if $type eq 'PPI::Token::Whitespace';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "PPI::Token::Whitespace" 49 68 117
19  
20 68 ▶ if ($type eq 'PPI::Token::Symbol') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "PPI::Token::Symbol") 62 6 68
21 62 my $str = $tok->content;
22 62 ▶ if ($str =~ /^[\$\@]\w+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^[\$\@]\w+$/) 62 0 62
23 62 my $elem = $self->get_var($str);
24 62 push @$elems, $elem;
25 62 return 1;
26 }
27 }
28  
29 # Parse @$a in the following if-statement.
30 6 ▶ if ($type eq 'PPI::Token::Cast') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "PPI::Token::Cast") 1 5 6
31 1 ▶ $tok->content eq '@' or
Branch: 1 branch
BranchTrueFalseTotal
$tok->content eq "\@" or XXX($tok, "unexpected token") 1 0 1
32 XXX $tok, "unexpected token";
33 1 $tok = shift(@$in);
34 1 $type = ref($tok);
35 1 my $str = $tok->content;
36 1 ▶ $type eq 'PPI::Token::Symbol' and $str =~ /^\$\w+$/ or
Branch: 1 branch
BranchTrueFalseTotal
$type eq "PPI::Token::Symbol" and $str =~ /^\$\w+$/ or XXX($tok, "unexpected token") 1 0 1
Condition33%1/3
$type eq "PPI::Token::Symbol" and $str =~ /^\$\w+$/
!ll&&!rl&&r
001
MC/DC0%0/2
$type eq "PPI::Token::Symbol" and $str =~ /^\$\w+$/
$type eq "PPI::Token::Symbol" $str =~ /^\$\w+$/
Truth table33%1/3
A and B
A= $type eq "PPI::Token::Symbol"B= $str =~ /^\$\w+$/
ABresult
0X0
100
111
37 XXX $tok, "unexpected token";
38 1 my $elem = $self->get_var($str);
39 1 $elem->{cast} = 1;
40 1 push @$elems, $elem;
41 1 return 1;
42 }
43  
44 5 ▶ if ($type eq 'PPI::Token::Number') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "PPI::Token::Number") 2 3 5
45 2 my $str = $tok->content;
46 2 ▶ if ($str =~ /^[1-9][0-9]*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /^[1-9][0-9]*$/) 2 0 2
47 2 push @$elems, assign::skip_num->new($str);
48 2 return 1;
49 }
50 }
51 3 ▶ if ($type eq 'PPI::Token::Magic') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "PPI::Token::Magic") 3 0 3
52 3 my $str = $tok->content;
53 3 ▶ if ($str eq '_') {
Branch: 1 branch
BranchTrueFalseTotal
if ($str eq "_") 2 1 3
54 2 push @$elems, assign::skip->new;
55 2 return 1;
56 }
57 1 ▶ if ($str eq '$_') {
Branch: 1 branch
BranchTrueFalseTotal
if ($str eq "\$_") 1 0 1
58 1 push @$elems, assign::var->new($str);
59 1 return 1;
60 }
61 }
62 0 XXX $tok, "unexpected token";
63 }
64 3 return 0;
65 }
66  
67 23 ▶sub gen_code {
Subroutine gen_code: called CC=9 SCAR=22.0
Pod undocumented
68 23 my ($self, $decl, $oper, $from, $init) = @_;
69  
70 23 my $code = [ @$init ];
71 23 my $elems = $self->{elems};
72  
73 23 ▶ if ($decl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decl) 21 2 23
74 push @$code,
75 "$decl(" .
76 join(', ',
77 map $_->val,
78 57 grep {$_->val ne '$_'}
79 21 grep {$_->val =~ /^[\$\@]/}
80 @$elems
81 ) .
82 ');';
83 }
84  
85 23 my $i = 0;
86 23 for my $elem (@$elems) {
87 68 my $type = ref $elem;
88 68 ▶ if ($type eq 'assign::skip') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "assign::skip") 2 66 68
89 2 $i++;
90 2 next;
91 }
92 66 ▶ if ($type eq 'assign::skip_num') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "assign::skip_num") 2 64 66
93 2 $i += $elem->val;
94 2 next;
95 }
96  
97 64 my $var = $elem->val;
98 64 ▶ my $def = $elem->{def} // '';
Condition100%2/2
$elem->{"def"} // ""
l!l
460
MC/DC100%1/1
$elem->{"def"} // ""
$elem->{"def"}
Truth table100%2/2
A
A= $elem->{"def"}
Aresult
11
00
99 64 ▶ $def &&= " // $def";
Condition100%2/2
$def &&= " // $def"
!ll
604
MC/DC100%1/1
$def &&= " // $def"
$def
Truth table100%2/2
A
A= $def
Aresult
00
11
100  
101 push @$code,
102 ($elem->sigil eq '@')
103 ? "$var $oper \@$from\[$i..\@$from-1\]$def;" :
104 ($elem->{cast})
105 64 ▶ ? "$var $oper \[\@$from\[$i..\@$from-1\]\]$def;" :
Branch: 2 branches
BranchTrueFalseTotal
$elem->sigil eq '@' ? : 1 63 64
$elem->{'cast'} ? : 1 62 63
106 "$var $oper $from\->[$i]$def;";
107  
108 64 $i++;
109 }
110  
111 23 return join "\n", @$code;
112 }
113  
114 6 1;
↑ Summary assign/Struct.pm »