blib/lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitDefinedBeforeLength.pm

filter: Statementstmt 98.5% 140 / 142 Branchbran 89.0% 89 / 100 Conditioncond 75.4% 77 / 102 MC/DCmcdc 62.7% 37 / 59 Subroutinesub 95.2% 20 / 21 Podpod 100% 5 / 5 totaltotal 85.7% 368 / 429 CC 85 SCAR 25.3
CC
85
Cov
89%
_is_boolean
24.4
_continues_term
14.8
_is_boolean_place
13.8
CRAP 12.5
↑ Summary
1 package Perl::Critic::Policy::ValuesAndExpressions::ProhibitDefinedBeforeLength;
2 2 $Perl::Critic::Policy::ValuesAndExpressions::ProhibitDefinedBeforeLength::VERSION = '0.002';
3 # ABSTRACT: Test the value, not its length, and shape it before measuring it.
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use re '/aa';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Perl::Critic::Utils qw{ :severities is_hash_key is_method_call };
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use parent qw{Perl::Critic::Policy};
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18  
19 2 Readonly::Scalar my $PAIR_DESC => 'defined before length on the same value';
20 2 Readonly::Scalar my $PAIR_EXPL => 'In a boolean context use the value alone; where the length matters, shape the value first ($x //= q{})';
21 2 Readonly::Scalar my $BARE_DESC => 'length in a boolean context';
22 2 Readonly::Scalar my $BARE_EXPL => 'The value alone is false for undef and the empty string, and needs no call';
23  
24 # The operators that join the two halves of a pair, positive and negated.
25 2 Readonly::Hash my %AND => map { $_ => 1 } qw{&& and};
26 2 Readonly::Hash my %OR => map { $_ => 1 } qw{|| or};
27 2 Readonly::Hash my %NOT => map { $_ => 1 } ( q{!}, 'not' );
28  
29 # The operators a condition is built from. A length joined to others by these
30 # is still a condition if the whole chain is one.
31 2 Readonly::Hash my %LOGICAL => map { $_ => 1 } ( qw{&& || // and or xor not}, q{!} );
32  
33 # The operators before which a chain is a value rather than a condition: an
34 # assignment takes it, a comma passes it, and ?: picks it as a branch. Any
35 # other operator to the left belongs to another operand of the chain.
36 2 Readonly::Hash my %VALUE_STARTS => map { $_ => 1 } ( qw{= += -= *= /= .= %= x= **= //= ||= &&= |= &= ^= <<= >>= => ? :}, q{,} );
37  
38 # What makes the rest of a statement its condition.
39 2 Readonly::Hash my %MODIFIER => map { $_ => 1 } qw{if unless while until};
40  
41 # The list functions whose block is a test of each element.
42 2 Readonly::Hash my %TESTS_EACH => map { $_ => 1 } qw{grep first any all none notall};
43  
44 2 ▶sub supported_parameters { return () }
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod documented
45 51 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
46 0 ▶sub default_themes { return qw{troglodyne performance maintenance} }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
47 73 ▶sub applies_to { return 'PPI::Token::Word' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
48  
49 247 ▶sub violates {
Subroutine violates: called CC=8 SCAR=20.8
Pod documented
50 247 my ( $self, $elem, undef ) = @_;
51  
52 247 ▶ return () if is_hash_key($elem) || is_method_call($elem);
Branch: 1 branch
BranchTrueFalseTotal
if is_hash_key($elem) or is_method_call($elem) 17 230 247
Condition100%3/3
is_hash_key($elem) or is_method_call($elem)
l!l&&r!l&&!r
125230
MC/DC100%2/2
is_hash_key($elem) or is_method_call($elem)
is_hash_key($elem) is_method_call($elem)
Truth table100%3/3
A or B
A= is_hash_key($elem)B= is_method_call($elem)
ABresult
1X1
011
000
53  
54 230 ▶ if ( $elem->content eq 'defined' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->content eq "defined") 25 205 230
55 25 ▶ return () unless _pair($elem);
Branch: 1 branch
BranchTrueFalseTotal
unless _pair($elem) 4 21 25
56 21 return $self->violation( $PAIR_DESC, $PAIR_EXPL, $elem );
57 }
58  
59 205 ▶ return () unless $elem->content eq 'length';
Branch: 1 branch
BranchTrueFalseTotal
unless $elem->content eq "length" 135 70 205
60 70 ▶ return () if _second_half_of_a_pair($elem);
Branch: 1 branch
BranchTrueFalseTotal
if _second_half_of_a_pair($elem) 21 49 70
61  
62 49 my ( undef, $after ) = _operand($elem);
63 49 ▶ return () unless _is_boolean( $elem, $after );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_boolean($elem, $after) 19 30 49
64 30 return $self->violation( $BARE_DESC, $BARE_EXPL, $elem );
65 }
66  
67 # The length a defined is paired with, or nothing: `defined $x && length $x`,
68 # or its negation `!defined $x || !length $x`, on the same operand.
69 49 ▶sub _pair {
Subroutine _pair: called CC=11 SCAR=24.8
70 49 my ($defined) = @_;
71  
72 49 my $negated = _is_not( $defined->sprevious_sibling );
73  
74 49 my ( $operand, $after ) = _operand($defined);
75 49 ▶ return unless $after && $after->isa('PPI::Token::Operator');
Branch: 1 branch
BranchTrueFalseTotal
unless $after and $after->isa("PPI::Token::Operator") 0 49 49
Condition33%1/3
$after and $after->isa("PPI::Token::Operator")
!ll&&!rl&&r
0049
MC/DC0%0/2
$after and $after->isa("PPI::Token::Operator")
$after $after->isa("PPI::Token::Operator")
Truth table33%1/3
A and B
A= $afterB= $after->isa("PPI::Token::Operator")
ABresult
0X0
100
111
76 49 ▶ return unless $negated ? $OR{ $after->content } : $AND{ $after->content };
Branch: 2 branches
BranchTrueFalseTotal
unless $negated ? $OR{$after->content} : $AND{$after->content} 0 49 49
$negated ? : 4 45 49
77  
78 49 my $length = $after->snext_sibling;
79 49 ▶ if ($negated) {
Branch: 1 branch
BranchTrueFalseTotal
if ($negated) 4 45 49
80 4 ▶ return unless _is_not($length);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_not($length) 0 4 4
81 4 $length = $length->snext_sibling;
82 }
83 49 ▶ return unless $length && $length->isa('PPI::Token::Word') && $length->content eq 'length';
Branch: 1 branch
BranchTrueFalseTotal
unless $length and $length->isa("PPI::Token::Word") and $length->content eq "length" 1 48 49
Condition66%4/6
$length and $length->isa("PPI::Token::Word") and $length->content eq "length"
!ll&&!rl&&r
1048
$length and $length->isa("PPI::Token::Word")
!ll&&!rl&&r
0148
MC/DC33%1/3
$length and $length->isa("PPI::Token::Word") and $length->content eq "length"
$length $length->isa("PPI::Token::Word") $length->content eq "length"
Truth table50%2/4
A and B and C
A= $lengthB= $length->isa("PPI::Token::Word")C= $length->content eq "length"
ABCresult
0XX0
10X0
1100
1111
84  
85 48 my ($measured) = _operand($length);
86 48 ▶ return unless $measured eq $operand;
Branch: 1 branch
BranchTrueFalseTotal
unless $measured eq $operand 6 42 48
87 42 return $length;
88 }
89  
90 # Reported already, as the pair.
91 70 ▶sub _second_half_of_a_pair {
Subroutine _second_half_of_a_pair: called CC=6 SCAR=17.9
92 70 my ($length) = @_;
93  
94 70 my $sibling = $length->sprevious_sibling;
95 70 ▶ while ($sibling) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sibling) 203 49 252
96 203 ▶ if ( $sibling->isa('PPI::Token::Word') && $sibling->content eq 'defined' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sibling->isa("PPI::Token::Word") and $sibling->content eq "defined") 24 179 203
Condition100%3/3
$sibling->isa("PPI::Token::Word") and $sibling->content eq "defined"
!ll&&!rl&&r
1285124
MC/DC100%2/2
$sibling->isa("PPI::Token::Word") and $sibling->content eq "defined"
$sibling->isa("PPI::Token::Word") $sibling->content eq "defined"
Truth table100%3/3
A and B
A= $sibling->isa("PPI::Token::Word")B= $sibling->content eq "defined"
ABresult
0X0
100
111
97 24 my $paired = _pair($sibling);
98 24 ▶ return 1 if $paired && $paired == $length;
Branch: 1 branch
BranchTrueFalseTotal
if $paired and $paired == $length 21 3 24
Condition66%2/3
$paired and $paired == $length
!ll&&!rl&&r
3021
MC/DC50%1/2
$paired and $paired == $length
$paired $paired == $length
Truth table66%2/3
A and B
A= $pairedB= $paired == $length
ABresult
0X0
100
111
99 }
100 182 $sibling = $sibling->sprevious_sibling;
101 }
102 49 return 0;
103 }
104  
105 # Whether the value of a term is only tested for truth. $start is the term's
106 # first element and $after the first sibling past it.
107 52 ▶sub _is_boolean {
Subroutine _is_boolean: called CC=23 SCAR=31.9
108 52 my ( $start, $after ) = @_;
109  
110 52 my $before = $start->sprevious_sibling;
111 52 ▶ return 1 if _is_not($before);
Branch: 1 branch
BranchTrueFalseTotal
if _is_not($before) 3 49 52
112  
113 # What the term is used for, from what is right beside it: `?` tests it,
114 # and any other operator that is not logical uses its value.
115 49 ▶ if ( $after && $after->isa('PPI::Token::Operator') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($after and $after->isa("PPI::Token::Operator")) 13 36 49
Condition100%3/3
$after and $after->isa("PPI::Token::Operator")
!ll&&!rl&&r
162013
MC/DC100%2/2
$after and $after->isa("PPI::Token::Operator")
$after $after->isa("PPI::Token::Operator")
Truth table100%3/3
A and B
A= $afterB= $after->isa("PPI::Token::Operator")
ABresult
0X0
100
111
116 13 ▶ return 1 if $after->content eq q{?};
Branch: 1 branch
BranchTrueFalseTotal
if $after->content eq "?" 4 9 13
117 9 ▶ return 0 unless $LOGICAL{ $after->content };
Branch: 1 branch
BranchTrueFalseTotal
unless $LOGICAL{$after->content} 5 4 9
118 }
119 40 ▶ return 0 if $before && $before->isa('PPI::Token::Operator') && !$LOGICAL{ $before->content };
Branch: 1 branch
BranchTrueFalseTotal
if $before and $before->isa("PPI::Token::Operator") and not $LOGICAL{$before->content} 3 37 40
Condition100%6/6
$before and $before->isa("PPI::Token::Operator") and not $LOGICAL{$before->content}
!ll&&!rl&&r
26113
$before and $before->isa("PPI::Token::Operator")
!ll&&!rl&&r
141214
MC/DC100%3/3
$before and $before->isa("PPI::Token::Operator") and not $LOGICAL{$before->content}
$before $before->isa("PPI::Token::Operator") not $LOGICAL{$before->content}
Truth table100%4/4
A and B and not(C)
A= $beforeB= $before->isa("PPI::Token::Operator")C= not $LOGICAL{$before->content}
ABCresult
0XX0
10X0
1100
1111
120  
121 # Then along the chain of logical operators it is part of.
122 37 my $left = $before;
123 37 ▶ while ($left) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left) 59 17 76
124 59 ▶ return 1 if $left->isa('PPI::Token::Word') && $MODIFIER{ $left->content };
Branch: 1 branch
BranchTrueFalseTotal
if $left->isa("PPI::Token::Word") and $MODIFIER{$left->content} 13 46 59
Condition100%3/3
$left->isa("PPI::Token::Word") and $MODIFIER{$left->content}
!ll&&!rl&&r
37913
MC/DC100%2/2
$left->isa("PPI::Token::Word") and $MODIFIER{$left->content}
$left->isa("PPI::Token::Word") $MODIFIER{$left->content}
Truth table100%3/3
A and B
A= $left->isa("PPI::Token::Word")B= $MODIFIER{$left->content}
ABresult
0X0
100
111
125 46 ▶ return 0 if $left->isa('PPI::Token::Word') && $left->content eq 'return';
Branch: 1 branch
BranchTrueFalseTotal
if $left->isa("PPI::Token::Word") and $left->content eq "return" 3 43 46
Condition100%3/3
$left->isa("PPI::Token::Word") and $left->content eq "return"
!ll&&!rl&&r
3763
MC/DC100%2/2
$left->isa("PPI::Token::Word") and $left->content eq "return"
$left->isa("PPI::Token::Word") $left->content eq "return"
Truth table100%3/3
A and B
A= $left->isa("PPI::Token::Word")B= $left->content eq "return"
ABresult
0X0
100
111
126 43 ▶ return 0 if $left->isa('PPI::Token::Operator') && $VALUE_STARTS{ $left->content };
Branch: 1 branch
BranchTrueFalseTotal
if $left->isa("PPI::Token::Operator") and $VALUE_STARTS{$left->content} 4 39 43
Condition100%3/3
$left->isa("PPI::Token::Operator") and $VALUE_STARTS{$left->content}
!ll&&!rl&&r
22174
MC/DC100%2/2
$left->isa("PPI::Token::Operator") and $VALUE_STARTS{$left->content}
$left->isa("PPI::Token::Operator") $VALUE_STARTS{$left->content}
Truth table100%3/3
A and B
A= $left->isa("PPI::Token::Operator")B= $VALUE_STARTS{$left->content}
ABresult
0X0
100
111
127 39 $left = $left->sprevious_sibling;
128 }
129  
130 17 my $right = $after;
131 17 ▶ while ($right) {
Branch: 1 branch
BranchTrueFalseTotal
if ($right) 1 16 17
132 1 ▶ return 1 if $right->isa('PPI::Token::Operator') && $right->content eq q{?};
Branch: 1 branch
BranchTrueFalseTotal
if $right->isa("PPI::Token::Operator") and $right->content eq "?" 0 1 1
Condition33%1/3
$right->isa("PPI::Token::Operator") and $right->content eq "?"
!ll&&!rl&&r
100
MC/DC0%0/2
$right->isa("PPI::Token::Operator") and $right->content eq "?"
$right->isa("PPI::Token::Operator") $right->content eq "?"
Truth table33%1/3
A and B
A= $right->isa("PPI::Token::Operator")B= $right->content eq "?"
ABresult
0X0
100
111
133 1 ▶ last if $right->isa('PPI::Token::Operator') && $right->content =~ m/\A(?:,|=>|:)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $right->isa("PPI::Token::Operator") and $right->content =~ /\A(?:,|=>|:)\z/aa 0 1 1
Condition33%1/3
$right->isa("PPI::Token::Operator") and $right->content =~ /\A(?:,|=>|:)\z/aa
!ll&&!rl&&r
100
MC/DC0%0/2
$right->isa("PPI::Token::Operator") and $right->content =~ /\A(?:,|=>|:)\z/aa
$right->isa("PPI::Token::Operator") $right->content =~ /\A(?:,|=>|:)\z/aa
Truth table33%1/3
A and B
A= $right->isa("PPI::Token::Operator")B= $right->content =~ /\A(?:,|=>|:)\z/aa
ABresult
0X0
100
111
134 1 ▶ last if $right->isa('PPI::Token::Word') && $MODIFIER{ $right->content };
Branch: 1 branch
BranchTrueFalseTotal
if $right->isa("PPI::Token::Word") and $MODIFIER{$right->content} 1 0 1
Condition33%1/3
$right->isa("PPI::Token::Word") and $MODIFIER{$right->content}
!ll&&!rl&&r
001
MC/DC0%0/2
$right->isa("PPI::Token::Word") and $MODIFIER{$right->content}
$right->isa("PPI::Token::Word") $MODIFIER{$right->content}
Truth table33%1/3
A and B
A= $right->isa("PPI::Token::Word")B= $MODIFIER{$right->content}
ABresult
0X0
100
111
135 0 $right = $right->snext_sibling;
136 }
137  
138 17 return _is_boolean_place($start);
139 }
140  
141 # The chain reached the edge of its statement, so the statement's place decides.
142 17 ▶sub _is_boolean_place {
Subroutine _is_boolean_place: called CC=13 SCAR=26.2
143 17 my ($start) = @_;
144  
145 17 ▶ my $statement = $start->parent or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $statement = $start->parent or return 0 17 0 17
146 17 ▶ my $holder = $statement->parent or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $holder = $statement->parent or return 0 17 0 17
147  
148 17 ▶ return 1 if $holder->isa('PPI::Structure::Condition');
Branch: 1 branch
BranchTrueFalseTotal
if $holder->isa("PPI::Structure::Condition") 6 11 17
149  
150 # Parenthesised: the list is the term, one level out. After return it is a
151 # value like any other term. After any other word, it is the argument list
152 # of a call.
153 11 ▶ if ( $holder->isa('PPI::Structure::List') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($holder->isa("PPI::Structure::List")) 5 6 11
154 5 my $before = $holder->sprevious_sibling;
155 5 ▶ return 0 if $before && $before->isa('PPI::Token::Word') && $before->content ne 'return';
Branch: 1 branch
BranchTrueFalseTotal
if $before and $before->isa("PPI::Token::Word") and $before->content ne "return" 2 3 5
Condition83%5/6
$before and $before->isa("PPI::Token::Word") and $before->content ne "return"
!ll&&!rl&&r
122
$before and $before->isa("PPI::Token::Word")
!ll&&!rl&&r
014
MC/DC66%2/3
$before and $before->isa("PPI::Token::Word") and $before->content ne "return"
$before $before->isa("PPI::Token::Word") $before->content ne "return"
Truth table75%3/4
A and B and C
A= $beforeB= $before->isa("PPI::Token::Word")C= $before->content ne "return"
ABCresult
0XX0
10X0
1100
1111
156 3 return _is_boolean( $holder, $holder->snext_sibling );
157 }
158  
159 # The last statement of a grep block is its test.
160 6 ▶ if ( $holder->isa('PPI::Structure::Block') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($holder->isa("PPI::Structure::Block")) 5 1 6
161 5 my $call = $holder->sprevious_sibling;
162 5 ▶ return 0 unless $call && $call->isa('PPI::Token::Word') && $TESTS_EACH{ $call->content };
Branch: 1 branch
BranchTrueFalseTotal
unless $call and $call->isa("PPI::Token::Word") and $TESTS_EACH{$call->content} 1 4 5
Condition50%3/6
$call and $call->isa("PPI::Token::Word") and $TESTS_EACH{$call->content}
!ll&&!rl&&r
014
$call and $call->isa("PPI::Token::Word")
!ll&&!rl&&r
005
MC/DC33%1/3
$call and $call->isa("PPI::Token::Word") and $TESTS_EACH{$call->content}
$call $call->isa("PPI::Token::Word") $TESTS_EACH{$call->content}
Truth table50%2/4
A and B and C
A= $callB= $call->isa("PPI::Token::Word")C= $TESTS_EACH{$call->content}
ABCresult
0XX0
10X0
1100
1111
163 4 my @statements = $holder->schildren;
164 4 ▶ return $statements[-1] == $statement ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$statements[-1] == $statement ? : 4 0 4
165 }
166  
167 1 return 0;
168 }
169  
170 # The operand of a named unary op, as text with the whitespace taken out, and
171 # the first sibling after it. defined($x) is the list's contents; defined $x
172 # runs until an operator other than -> or anything that cannot be part of a
173 # term. No operand at all is $_, as perl reads it.
174 146 ▶sub _operand {
Subroutine _operand: called CC=7 SCAR=19.5
175 146 my ($op) = @_;
176  
177 146 my $next = $op->snext_sibling;
178  
179 146 ▶ if ( $next && $next->isa('PPI::Structure::List') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next and $next->isa("PPI::Structure::List")) 9 137 146
Condition100%3/3
$next and $next->isa("PPI::Structure::List")
!ll&&!rl&&r
41339
MC/DC100%2/2
$next and $next->isa("PPI::Structure::List")
$next $next->isa("PPI::Structure::List")
Truth table100%3/3
A and B
A= $nextB= $next->isa("PPI::Structure::List")
ABresult
0X0
100
111
180 9 my $inside = join( q{}, map { $_->content } $next->schildren );
181 9 ▶ return ( _squash( length $inside ? $inside : '$_' ), $next->snext_sibling );
Branch: 1 branch
BranchTrueFalseTotal
length $inside ? : 9 0 9
182 }
183  
184 137 my @term;
185 137 ▶ while ( $next && _continues_term( $next, \@term ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next and _continues_term($next, \@term)) 197 137 334
Condition100%3/3
$next and _continues_term($next, \@term)
!ll&&!rl&&r
22115197
MC/DC100%2/2
$next and _continues_term($next, \@term)
$next _continues_term($next, \@term)
Truth table100%3/3
A and B
A= $nextB= _continues_term($next, \@term)
ABresult
0X0
100
111
186 197 push( @term, $next );
187 197 $next = $next->snext_sibling;
188 }
189  
190 137 my $text = join( q{}, map { $_->content } @term );
191 137 ▶ return ( _squash( length $text ? $text : '$_' ), $next );
Branch: 1 branch
BranchTrueFalseTotal
length $text ? : 131 6 137
192 }
193  
194 # A term is a variable, a quoted string or a call, then any run of subscripts,
195 # derefs, and method calls with their arguments. A word is part of it only as
196 # a function or method name.
197 312 ▶sub _continues_term {
Subroutine _continues_term: called CC=14 SCAR=27.0
198 312 my ( $elem, $term ) = @_;
199  
200 312 my $last = $term->[-1];
201 312 ▶ return _starts_term($elem) unless $last;
Branch: 1 branch
BranchTrueFalseTotal
unless $last 133 179 312
202  
203 179 ▶ return 1 if $elem->isa('PPI::Structure::Subscript');
Branch: 1 branch
BranchTrueFalseTotal
if $elem->isa("PPI::Structure::Subscript") 27 152 179
204 152 ▶ return 1 if $elem->isa('PPI::Token::Operator') && $elem->content eq '->';
Branch: 1 branch
BranchTrueFalseTotal
if $elem->isa("PPI::Token::Operator") and $elem->content eq "->" 24 128 152
Condition100%3/3
$elem->isa("PPI::Token::Operator") and $elem->content eq "->"
!ll&&!rl&&r
646424
MC/DC100%2/2
$elem->isa("PPI::Token::Operator") and $elem->content eq "->"
$elem->isa("PPI::Token::Operator") $elem->content eq "->"
Truth table100%3/3
A and B
A= $elem->isa("PPI::Token::Operator")B= $elem->content eq "->"
ABresult
0X0
100
111
205 128 ▶ return 1 if $last->isa('PPI::Token::Cast') && ( $elem->isa('PPI::Token::Symbol') || $elem->isa('PPI::Structure::Block') );
Branch: 1 branch
BranchTrueFalseTotal
if $last->isa("PPI::Token::Cast") and $elem->isa("PPI::Token::Symbol") || $elem->isa("PPI::Structure::Block") 4 124 128
Condition50%3/6
$last->isa("PPI::Token::Cast") and $elem->isa("PPI::Token::Symbol") || $elem->isa("PPI::Structure::Block")
!ll&&!rl&&r
12404
$elem->isa("PPI::Token::Symbol") or $elem->isa("PPI::Structure::Block")
l!l&&r!l&&!r
400
MC/DC33%1/3
$last->isa("PPI::Token::Cast") and $elem->isa("PPI::Token::Symbol") || $elem->isa("PPI::Structure::Block")
$last->isa("PPI::Token::Cast") $elem->isa("PPI::Token::Symbol") $elem->isa("PPI::Structure::Block")
Truth table50%2/4
A and B or C
A= $last->isa("PPI::Token::Cast")B= $elem->isa("PPI::Token::Symbol")C= $elem->isa("PPI::Structure::Block")
ABCresult
0XX0
1000
11X1
1011
206  
207 124 ▶ my $after_arrow = $last->isa('PPI::Token::Operator') && $last->content eq '->';
Condition66%2/3
$last->isa('PPI::Token::Operator') && $last->content eq '->'
!ll&&!rl&&r
11905
MC/DC50%1/2
$last->isa('PPI::Token::Operator') && $last->content eq '->'
$last->isa('PPI::Token::Operator') $last->content eq '->'
Truth table66%2/3
A && B
A= $last->isa('PPI::Token::Operator')B= $last->content eq '->'
ABresult
0X0
100
111
208 124 ▶ return 1 if $after_arrow && ( $elem->isa('PPI::Token::Word') || $elem->isa('PPI::Structure::List') );
Branch: 1 branch
BranchTrueFalseTotal
if $after_arrow and $elem->isa("PPI::Token::Word") || $elem->isa("PPI::Structure::List") 5 119 124
Condition50%3/6
$after_arrow and $elem->isa("PPI::Token::Word") || $elem->isa("PPI::Structure::List")
!ll&&!rl&&r
11905
$elem->isa("PPI::Token::Word") or $elem->isa("PPI::Structure::List")
l!l&&r!l&&!r
500
MC/DC33%1/3
$after_arrow and $elem->isa("PPI::Token::Word") || $elem->isa("PPI::Structure::List")
$after_arrow $elem->isa("PPI::Token::Word") $elem->isa("PPI::Structure::List")
Truth table50%2/4
A and B or C
A= $after_arrowB= $elem->isa("PPI::Token::Word")C= $elem->isa("PPI::Structure::List")
ABCresult
0XX0
1000
11X1
1011
209 119 ▶ return 1 if $last->isa('PPI::Token::Word') && $elem->isa('PPI::Structure::List');
Branch: 1 branch
BranchTrueFalseTotal
if $last->isa("PPI::Token::Word") and $elem->isa("PPI::Structure::List") 6 113 119
Condition100%3/3
$last->isa("PPI::Token::Word") and $elem->isa("PPI::Structure::List")
!ll&&!rl&&r
10856
MC/DC100%2/2
$last->isa("PPI::Token::Word") and $elem->isa("PPI::Structure::List")
$last->isa("PPI::Token::Word") $elem->isa("PPI::Structure::List")
Truth table100%3/3
A and B
A= $last->isa("PPI::Token::Word")B= $elem->isa("PPI::Structure::List")
ABresult
0X0
100
111
210  
211 113 return 0;
212 }
213  
214 133 ▶sub _starts_term {
Subroutine _starts_term: called CC=8 SCAR=21.2
215 133 my ($elem) = @_;
216  
217 133 ▶ return 1 if $elem->isa('PPI::Token::Symbol') || $elem->isa('PPI::Token::Magic') || $elem->isa('PPI::Token::Cast');
Branch: 1 branch
BranchTrueFalseTotal
if $elem->isa("PPI::Token::Symbol") or $elem->isa("PPI::Token::Magic") or $elem->isa("PPI::Token::Cast") 125 8 133
Condition83%5/6
$elem->isa("PPI::Token::Symbol") or $elem->isa("PPI::Token::Magic") or $elem->isa("PPI::Token::Cast")
l!l&&r!l&&!r
12148
$elem->isa("PPI::Token::Symbol") or $elem->isa("PPI::Token::Magic")
l!l&&r!l&&!r
121012
MC/DC66%2/3
$elem->isa("PPI::Token::Symbol") or $elem->isa("PPI::Token::Magic") or $elem->isa("PPI::Token::Cast")
$elem->isa("PPI::Token::Symbol") $elem->isa("PPI::Token::Magic") $elem->isa("PPI::Token::Cast")
Truth table75%3/4
A or B or C
A= $elem->isa("PPI::Token::Symbol")B= $elem->isa("PPI::Token::Magic")C= $elem->isa("PPI::Token::Cast")
ABCresult
1XX1
01X1
0011
0000
218 8 ▶ return 1 if $elem->isa('PPI::Token::Quote');
Branch: 1 branch
BranchTrueFalseTotal
if $elem->isa("PPI::Token::Quote") 0 8 8
219 8 ▶ return 1 if $elem->isa('PPI::Token::Word') && !$MODIFIER{ $elem->content } && $elem->content !~ m/\A(?:for|foreach|x)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $elem->isa("PPI::Token::Word") and not $MODIFIER{$elem->content} and not $elem->content =~ /\A(?:for|foreach|x)\z/aa 6 2 8
Condition66%4/6
$elem->isa("PPI::Token::Word") and not $MODIFIER{$elem->content} and not $elem->content =~ /\A(?:for|foreach|x)\z/aa
!ll&&!rl&&r
206
$elem->isa("PPI::Token::Word") and not $MODIFIER{$elem->content}
!ll&&!rl&&r
206
MC/DC33%1/3
$elem->isa("PPI::Token::Word") and not $MODIFIER{$elem->content} and not $elem->content =~ /\A(?:for|foreach|x)\z/aa
$elem->isa("PPI::Token::Word") not $MODIFIER{$elem->content} not $elem->content =~ /\A(?:for|foreach|x)\z/aa
Truth table50%2/4
A and not(B) and not(C)
A= $elem->isa("PPI::Token::Word")B= not $MODIFIER{$elem->content}C= not $elem->content =~ /\A(?:for|foreach|x)\z/aa
ABCresult
0XX0
10X0
1100
1111
220 2 return 0;
221 }
222  
223 105 ▶sub _is_not {
Subroutine _is_not: called CC=3 SCAR=11.0
224 105 my ($elem) = @_;
225 105 ▶ return $elem && $elem->isa('PPI::Token::Operator') && $NOT{ $elem->content };
Condition100%6/6
$elem && $elem->isa('PPI::Token::Operator') && $NOT{$elem->content}
!ll&&!rl&&r
623211
$elem and $elem->isa("PPI::Token::Operator")
!ll&&!rl&&r
214143
MC/DC100%3/3
$elem && $elem->isa('PPI::Token::Operator') && $NOT{$elem->content}
$elem $elem->isa("PPI::Token::Operator") $NOT{$elem->content}
Truth table100%4/4
A and B && C
A= $elemB= $elem->isa("PPI::Token::Operator")C= $NOT{$elem->content}
ABCresult
0XX0
10X0
1100
1111
226 }
227  
228 146 ▶sub _squash {
Subroutine _squash: called CC=1 SCAR=0.0
229 146 my ($text) = @_;
230 146 $text =~ s/\s+//g;
231 146 return $text;
232 }
233  
234 2 1;
235  
236 __END__
↑ Summary