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

filter: Statementstmt 98.0% 198 / 202 Branchbran 93.3% 140 / 150 Conditioncond 84.0% 121 / 144 MC/DCmcdc 69.6% 55 / 79 Subroutinesub 95.8% 23 / 24 Podpod 100% 5 / 5 totaltotal 89.7% 542 / 604 CC 124 SCAR 31.4
CC
124
Cov
93%
__ANON__
46.3
violates
28.1
__ANON__
13.0
CRAP 23.1
↑ Summary
1 package Perl::Critic::Policy::ValuesAndExpressions::ProhibitDescendingRanges 0.001;
2  
3 # ABSTRACT: Do not write a range that counts down: Perl gives an empty list for 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 2 ▶use Scalar::Util qw{looks_like_number};
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use Perl::Critic::Utils qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 :characters
17 :severities
18 is_method_call
19 is_perl_builtin
20 is_perl_builtin_with_list_context
21 is_perl_builtin_with_zero_and_or_one_arguments
22 precedence_of
23 2 };
24 2 ▶use parent qw{Perl::Critic::Policy};
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26  
27  
28 2 Readonly::Scalar my $EXPL => q{Perl's .. counts only up, so a range whose left end is greater than its right end gives an empty list. To count down, write reverse( LOW .. HIGH )};
29  
30 # Operators that bind tighter than .. have a lower number here.
31 2 Readonly::Scalar my $RANGE => precedence_of(q{..});
32  
33 2 Readonly::Hash my %RANGE_OPERATOR => map { $_ => 1 } qw{.. ...};
34  
35 # Statement modifiers, and the words of the compound statements that take one.
36 2 Readonly::Hash my %SCALAR_MODIFIER => map { $_ => 1 } qw{if unless while until};
37 2 Readonly::Hash my %LIST_MODIFIER => map { $_ => 1 } qw{for foreach};
38  
39 # The operators that a list goes on past, to the left: a comma list and the
40 # branches of a ternary have the context of the whole expression.
41 2 Readonly::Hash my %LIST_SEPARATOR => map { $_ => 1 } ( $COMMA, $FATCOMMA, q{?}, $COLON );
42  
43 # Words that an expression follows, and that are not a term of it.
44 2 Readonly::Hash my %NOT_A_TERM => map { $_ => 1 } qw{if unless while until for foreach my our local state return};
45  
46 # The blocks whose value is a list, and the blocks after which a list follows.
47 2 Readonly::Hash my %LIST_BLOCK => map { $_ => 1 } qw{map};
48 2 Readonly::Hash my %BLOCK_THEN_LIST => map { $_ => 1 } qw{map grep sort};
49  
50 3 ▶sub supported_parameters {
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod documented
51 return (
52 {
53 3 name => 'largest_end',
54 description => 'The largest right end to report for a range whose left end is an expression',
55 default_string => '1',
56 behavior => 'integer',
57 },
58 );
59 }
60  
61  
62 79 ▶sub default_severity { return $SEVERITY_HIGH }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
63  
64  
65 0 ▶sub default_themes { return qw{bugs} }
Subroutine default_themes: not called CC=1 SCAR=6.9
Pod documented
66  
67  
68 130 ▶sub applies_to { return 'PPI::Token::Operator' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
69  
70 309 ▶my $is_operator = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
71 309 my ( $e, $content ) = @_;
72 309 ▶ return $e && $e->isa('PPI::Token::Operator') && $e->content eq $content;
Condition100%6/6
$e && $e->isa('PPI::Token::Operator') && $e->content eq $content
!ll&&!rl&&r
1896456
$e and $e->isa("PPI::Token::Operator")
!ll&&!rl&&r
10683120
MC/DC100%3/3
$e && $e->isa('PPI::Token::Operator') && $e->content eq $content
$e $e->isa("PPI::Token::Operator") $e->content eq $content
Truth table100%4/4
A and B && C
A= $eB= $e->isa("PPI::Token::Operator")C= $e->content eq $content
ABCresult
0XX0
10X0
1100
1111
73 2 };
74  
75 83 ▶my $binds_tighter = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
76 83 my ($operator) = @_;
77 83 my $precedence = precedence_of($operator);
78 83 ▶ return defined $precedence && $precedence < $RANGE;
Condition66%2/3
defined $precedence && $precedence < $RANGE
!ll&&!rl&&r
0749
MC/DC50%1/2
defined $precedence && $precedence < $RANGE
defined $precedence $precedence < $RANGE
Truth table66%2/3
A && B
A= defined $precedenceB= $precedence < $RANGE
ABresult
0X0
100
111
79 2 };
80  
81 6 ▶my $follows_word = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
82 6 my ( $e, $words ) = @_;
83 6 my $word = $e->sprevious_sibling;
84 6 ▶ return $word && $word->isa('PPI::Token::Word') && $words->{ $word->content } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$word && $word->isa('PPI::Token::Word') && $$words{$word->content} ? : 4 2 6
Condition83%5/6
$word and $word->isa("PPI::Token::Word") and $$words{$word->content}
!ll&&!rl&&r
114
$word and $word->isa("PPI::Token::Word")
!ll&&!rl&&r
105
MC/DC66%2/3
$word and $word->isa("PPI::Token::Word") and $$words{$word->content}
$word $word->isa("PPI::Token::Word") $$words{$word->content}
Truth table75%3/4
A and B and C
A= $wordB= $word->isa("PPI::Token::Word")C= $$words{$word->content}
ABCresult
0XX0
10X0
1100
1111
85 2 };
86  
87 # The elements of the left operand of $elem, and the element before them. An
88 # element binds to the operand if it is a term, or an operator that binds
89 # tighter than .., which is where Perl would end the operand.
90 191 ▶my $left_operand = sub {
Subroutine __ANON__: called CC=11 SCAR=24.2
91 191 my ($elem) = @_;
92 191 my @operand;
93 191 my $before = $elem->sprevious_sibling;
94 191 ▶ while ($before) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before) 240 109 349
95 240 my $binds = 1;
96 240 ▶ if ( $before->isa('PPI::Token::Operator') ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($before->isa('PPI::Token::Operator')) { } 73 167 240
elsif ($before->isa('PPI::Token::Structure')) { } 0 167 167
elsif ($before->isa('PPI::Token::Word')) { } 14 153 167
elsif ($before->isa('PPI::Structure::Block')) { } 4 149 153
97 73 $binds = $binds_tighter->($before);
98 }
99 elsif ( $before->isa('PPI::Token::Structure') ) {
100 0 $binds = 0;
101 }
102 elsif ( $before->isa('PPI::Token::Word') ) {
103 14 my $after = $before->snext_sibling;
104 14 ▶ $binds = !$NOT_A_TERM{ $before->content }
Condition75%9/12
!$NOT_A_TERM{$before->content} && (is_method_call($before) || is_perl_builtin_with_zero_and_or_one_arguments($before) || $after && $after->isa('PPI::Structure::List'))
!ll&&!rl&&r
932
is_method_call($before) or is_perl_builtin_with_zero_and_or_one_arguments($before) or $after and $after->isa("PPI::Structure::List")
l!l&&r!l&&!r
203
is_method_call($before) or is_perl_builtin_with_zero_and_or_one_arguments($before)
l!l&&r!l&&!r
113
$after and $after->isa("PPI::Structure::List")
!ll&&!rl&&r
030
MC/DC60%3/5
!$NOT_A_TERM{$before->content} && (is_method_call($before) || is_perl_builtin_with_zero_and_or_one_arguments($before) || $after && $after->isa('PPI::Structure::List'))
!$NOT_A_TERM{$before->content} is_method_call($before) is_perl_builtin_with_zero_and_or_one_arguments($before) $after $after->isa("PPI::Structure::List")
Truth table66%4/6
not(A) && B or C or D and E
A= !$NOT_A_TERM{$before->content}B= is_method_call($before)C= is_perl_builtin_with_zero_and_or_one_arguments($before)D= $afterE= $after->isa("PPI::Structure::List")
ABCDEresult
0XXXX0
1000X0
100100
11XXX1
101XX1
100111
105 && ( is_method_call($before) || is_perl_builtin_with_zero_and_or_one_arguments($before) || ( $after && $after->isa('PPI::Structure::List') ) );
106 }
107 elsif ( $before->isa('PPI::Structure::Block') ) {
108  
109 # The block of map, grep or sort ends the operand: the list follows it.
110 4 $binds = !$follows_word->( $before, \%BLOCK_THEN_LIST );
111 }
112 240 ▶ last unless $binds;
Branch: 1 branch
BranchTrueFalseTotal
unless $binds 82 158 240
113 158 unshift @operand, $before;
114 158 $before = $before->sprevious_sibling;
115 }
116 191 return ( \@operand, $before );
117 2 };
118  
119 180 ▶my $right_operand = sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
120 180 my ($elem) = @_;
121 180 my @operand;
122 180 my $after = $elem->snext_sibling;
123 180 ▶ while ($after) {
Branch: 1 branch
BranchTrueFalseTotal
if ($after) 212 107 319
124 212 my $binds = 1;
125 212 ▶ if ( $after->isa('PPI::Token::Operator') ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($after->isa('PPI::Token::Operator')) { } 10 202 212
elsif ($after->isa('PPI::Token::Structure')) { } 65 137 202
elsif ($after->isa('PPI::Token::Word')) { } 1 136 137
126 10 $binds = $binds_tighter->($after);
127 }
128 elsif ( $after->isa('PPI::Token::Structure') ) {
129 65 $binds = 0;
130 }
131 elsif ( $after->isa('PPI::Token::Word') ) {
132 1 ▶ $binds = !( $SCALAR_MODIFIER{ $after->content } || $LIST_MODIFIER{ $after->content } );
Condition33%1/3
$SCALAR_MODIFIER{$after->content} || $LIST_MODIFIER{$after->content}
l!l&&r!l&&!r
100
MC/DC0%0/2
$SCALAR_MODIFIER{$after->content} || $LIST_MODIFIER{$after->content}
$SCALAR_MODIFIER{$after->content} $LIST_MODIFIER{$after->content}
Truth table33%1/3
A || B
A= $SCALAR_MODIFIER{$after->content}B= $LIST_MODIFIER{$after->content}
ABresult
1X1
011
000
133 }
134 212 ▶ last unless $binds;
Branch: 1 branch
BranchTrueFalseTotal
unless $binds 73 139 212
135 139 push @operand, $after;
136 139 $after = $after->snext_sibling;
137 }
138 180 return ( \@operand, $after );
139 2 };
140  
141 # The source of a run of sibling elements, with the whitespace between them.
142 172 ▶my $source = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
143 172 my (@elements) = @_;
144 172 my ( $first, $last ) = @elements[ 0, -1 ];
145 172 my $text = q{};
146 172 ▶ for ( my $e = $first; $e; $e = $e->next_sibling ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e) 206 0 206
147 206 $text .= $e->content;
148 206 ▶ last if $e == $last;
Branch: 1 branch
BranchTrueFalseTotal
if $e == $last 172 34 206
149 }
150 172 return $text;
151 2 };
152  
153 # The value of an operand that is one literal, as { value => ..., number => 1 }
154 # for a number and { value => ... } for a string, or undef for anything else.
155 264 ▶my $literal = sub {
Subroutine __ANON__: called CC=13 SCAR=25.7
156 264 my (@operand) = @_;
157  
158 264 my $sign = 1;
159 264 ▶ if ( @operand == 2 && $is_operator->( $operand[0], q{-} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@operand == 2 and &$is_operator($operand[0], "-")) 3 261 264
Condition100%3/3
@operand == 2 and &$is_operator($operand[0], "-")
!ll&&!rl&&r
25923
MC/DC100%2/2
@operand == 2 and &$is_operator($operand[0], "-")
@operand == 2 &$is_operator($operand[0], "-")
Truth table100%3/3
A and B
A= @operand == 2B= &$is_operator($operand[0], "-")
ABresult
0X0
100
111
160 3 $sign = -1;
161 3 shift @operand;
162 }
163 264 ▶ return if @operand != 1;
Branch: 1 branch
BranchTrueFalseTotal
if @operand != 1 8 256 264
164 256 my ($e) = @operand;
165  
166 256 ▶ if ( $e->isa('PPI::Token::Number') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->isa("PPI::Token::Number")) 171 85 256
167  
168 # A version string is a literal, and not a number that the policy can compare.
169 171 ▶ return {} if $e->isa('PPI::Token::Number::Version');
Branch: 1 branch
BranchTrueFalseTotal
if $e->isa("PPI::Token::Number::Version") 1 170 171
170 170 my $value = $e->literal;
171 170 ▶ return defined $value ? { value => $sign * $value, number => 1 } : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 170 0 170
172 }
173  
174 # -'a' is the string '-a', which is not a number the policy can compare.
175 85 ▶ return if $sign < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $sign < 0 1 84 85
176 84 ▶ return { value => $e->literal } if $e->isa('PPI::Token::Quote::Single') || $e->isa('PPI::Token::Quote::Literal');
Branch: 1 branch
BranchTrueFalseTotal
if $e->isa("PPI::Token::Quote::Single") or $e->isa("PPI::Token::Quote::Literal") 57 27 84
Condition100%3/3
$e->isa("PPI::Token::Quote::Single") or $e->isa("PPI::Token::Quote::Literal")
l!l&&r!l&&!r
431427
MC/DC100%2/2
$e->isa("PPI::Token::Quote::Single") or $e->isa("PPI::Token::Quote::Literal")
$e->isa("PPI::Token::Quote::Single") $e->isa("PPI::Token::Quote::Literal")
Truth table100%3/3
A or B
A= $e->isa("PPI::Token::Quote::Single")B= $e->isa("PPI::Token::Quote::Literal")
ABresult
1X1
011
000
177 27 ▶ if ( $e->isa('PPI::Token::Quote::Double') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->isa("PPI::Token::Quote::Double")) 4 23 27
178 4 my $string = $e->string;
179 4 ▶ return if $e->interpolations || index( $string, q{\\} ) >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $e->interpolations or index($string, "\\") != -1 1 3 4
Condition66%2/3
$e->interpolations or index($string, "\\") != -1
l!l&&r!l&&!r
103
MC/DC50%1/2
$e->interpolations or index($string, "\\") != -1
$e->interpolations index($string, "\\") != -1
Truth table66%2/3
A or B
A= $e->interpolationsB= index($string, "\\") != -1
ABresult
1X1
011
000
180 3 return { value => $string };
181 }
182 23 return;
183 2 };
184  
185 # Whether a word gives list context to the expression after it.
186 17 ▶my $gives_a_list = sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
187 17 my ($word) = @_;
188 17 my $name = $word->content;
189 17 ▶ return 0 if $SCALAR_MODIFIER{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $SCALAR_MODIFIER{$name} 6 11 17
190 11 ▶ return 1 if $LIST_MODIFIER{$name} || $name eq 'return' || is_method_call($word);
Branch: 1 branch
BranchTrueFalseTotal
if $LIST_MODIFIER{$name} or $name eq "return" or is_method_call($word) 5 6 11
Condition100%6/6
$LIST_MODIFIER{$name} or $name eq "return" or is_method_call($word)
l!l&&r!l&&!r
416
$LIST_MODIFIER{$name} or $name eq "return"
l!l&&r!l&&!r
227
MC/DC100%3/3
$LIST_MODIFIER{$name} or $name eq "return" or is_method_call($word)
$LIST_MODIFIER{$name} $name eq "return" is_method_call($word)
Truth table100%4/4
A or B or C
A= $LIST_MODIFIER{$name}B= $name eq "return"C= is_method_call($word)
ABCresult
1XX1
01X1
0011
0000
191 6 ▶ return 1 if is_perl_builtin_with_list_context($word);
Branch: 1 branch
BranchTrueFalseTotal
if is_perl_builtin_with_list_context($word) 3 3 6
192 3 ▶ return is_perl_builtin($word) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
is_perl_builtin($word) ? : 1 2 3
193 2 };
194  
195 3 ▶my $after_list_cast = sub {
Subroutine __ANON__: called CC=4 SCAR=14.1
196 3 my ($e) = @_;
197 3 my $cast = $e->sprevious_sibling;
198 3 ▶ return $cast && $cast->isa('PPI::Token::Cast') && $cast->content =~ m/\A[\@%]\z/xs ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$cast && $cast->isa('PPI::Token::Cast') && $cast->content =~ /\A[\@%]\z/aasx ? : 2 1 3
Condition66%4/6
$cast and $cast->isa("PPI::Token::Cast") and $cast->content =~ /\A[\@%]\z/aasx
!ll&&!rl&&r
102
$cast and $cast->isa("PPI::Token::Cast")
!ll&&!rl&&r
012
MC/DC33%1/3
$cast and $cast->isa("PPI::Token::Cast") and $cast->content =~ /\A[\@%]\z/aasx
$cast $cast->isa("PPI::Token::Cast") $cast->content =~ /\A[\@%]\z/aasx
Truth table50%2/4
A and B and C
A= $castB= $cast->isa("PPI::Token::Cast")C= $cast->content =~ /\A[\@%]\z/aasx
ABCresult
0XX0
10X0
1100
1111
199 2 };
200  
201 # Whether a subscript takes a slice rather than one element: after an array or
202 # a hash, after @{...} or %{...}, or after ->@ or ->%.
203 7 ▶my $is_slice = sub {
Subroutine __ANON__: called CC=8 SCAR=21.6
204 7 my ($subscript) = @_;
205 7 my $before = $subscript->sprevious_sibling;
206 7 ▶ return 0 unless $before;
Branch: 1 branch
BranchTrueFalseTotal
unless $before 0 7 7
207 7 ▶ return 1 if $before->isa('PPI::Token::Symbol') && $before->content =~ m/\A[\@%]/xs;
Branch: 1 branch
BranchTrueFalseTotal
if $before->isa("PPI::Token::Symbol") and $before->content =~ /\A[\@%]/aasx 3 4 7
Condition100%3/3
$before->isa("PPI::Token::Symbol") and $before->content =~ /\A[\@%]/aasx
!ll&&!rl&&r
223
MC/DC100%2/2
$before->isa("PPI::Token::Symbol") and $before->content =~ /\A[\@%]/aasx
$before->isa("PPI::Token::Symbol") $before->content =~ /\A[\@%]/aasx
Truth table100%3/3
A and B
A= $before->isa("PPI::Token::Symbol")B= $before->content =~ /\A[\@%]/aasx
ABresult
0X0
100
111
208 4 ▶ return 1 if $before->isa('PPI::Token::Cast') && $before->content =~ m/\A[\@%]\z/xs;
Branch: 1 branch
BranchTrueFalseTotal
if $before->isa("PPI::Token::Cast") and $before->content =~ /\A[\@%]\z/aasx 1 3 4
Condition66%2/3
$before->isa("PPI::Token::Cast") and $before->content =~ /\A[\@%]\z/aasx
!ll&&!rl&&r
301
MC/DC50%1/2
$before->isa("PPI::Token::Cast") and $before->content =~ /\A[\@%]\z/aasx
$before->isa("PPI::Token::Cast") $before->content =~ /\A[\@%]\z/aasx
Truth table66%2/3
A and B
A= $before->isa("PPI::Token::Cast")B= $before->content =~ /\A[\@%]\z/aasx
ABresult
0X0
100
111
209 3 ▶ return $before->isa('PPI::Structure::Block') && $after_list_cast->($before) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$before->isa('PPI::Structure::Block') && &$after_list_cast($before) ? : 0 3 3
Condition33%1/3
$before->isa("PPI::Structure::Block") and &$after_list_cast($before)
!ll&&!rl&&r
300
MC/DC0%0/2
$before->isa("PPI::Structure::Block") and &$after_list_cast($before)
$before->isa("PPI::Structure::Block") &$after_list_cast($before)
Truth table33%1/3
A and B
A= $before->isa("PPI::Structure::Block")B= &$after_list_cast($before)
ABresult
0X0
100
111
210 2 };
211  
212 # Whether the range at $at, whose left operand starts after $before, is in
213 # list context. It walks out to the left, past a comma list, a ternary and a
214 # bare parenthesised group, to the first thing that gives an expression a
215 # context. Where it cannot tell, the answer is no, so that a flip-flop is never
216 # reported.
217 101 ▶my $in_list_context = sub { ## no critic (ProhibitSingleUseLexicalSubs) Inlined, it takes the score of violates past 40 for CognitiveComplexity.
Subroutine __ANON__: called CC=45 SCAR=38.4
218 101 my ( $at, $before ) = @_;
219 101 while (1) {
220 158 ▶ if ( !$before ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($before) 80 78 158
221 80 my $statement = $at->parent;
222 80 ▶ my $holder = $statement ? $statement->parent : undef;
Branch: 1 branch
BranchTrueFalseTotal
$statement ? : 80 0 80
223 80 ▶ return 0 unless $holder;
Branch: 1 branch
BranchTrueFalseTotal
unless $holder 0 80 80
224  
225 80 ▶ return 1 if $holder->isa('PPI::Structure::Constructor');
Branch: 1 branch
BranchTrueFalseTotal
if $holder->isa("PPI::Structure::Constructor") 3 77 80
226 77 ▶ return 0 if $holder->isa('PPI::Structure::Subscript') && !$is_slice->($holder);
Branch: 1 branch
BranchTrueFalseTotal
if $holder->isa("PPI::Structure::Subscript") and not &$is_slice($holder) 3 74 77
Condition100%3/3
$holder->isa("PPI::Structure::Subscript") and not &$is_slice($holder)
!ll&&!rl&&r
7133
MC/DC100%2/2
$holder->isa("PPI::Structure::Subscript") and not &$is_slice($holder)
$holder->isa("PPI::Structure::Subscript") not &$is_slice($holder)
Truth table100%3/3
A and not(B)
A= $holder->isa("PPI::Structure::Subscript")B= not &$is_slice($holder)
ABresult
0X0
100
111
227 74 ▶ return 1 if $holder->isa('PPI::Structure::Subscript');
Branch: 1 branch
BranchTrueFalseTotal
if $holder->isa("PPI::Structure::Subscript") 3 71 74
228 71 ▶ return 0 if $holder->isa('PPI::Structure::Block') && !$follows_word->( $holder, \%LIST_BLOCK );
Branch: 1 branch
BranchTrueFalseTotal
if $holder->isa("PPI::Structure::Block") and not &$follows_word($holder, \%LIST_BLOCK) 1 70 71
Condition100%3/3
$holder->isa("PPI::Structure::Block") and not &$follows_word($holder, \%LIST_BLOCK)
!ll&&!rl&&r
6911
MC/DC100%2/2
$holder->isa("PPI::Structure::Block") and not &$follows_word($holder, \%LIST_BLOCK)
$holder->isa("PPI::Structure::Block") not &$follows_word($holder, \%LIST_BLOCK)
Truth table100%3/3
A and not(B)
A= $holder->isa("PPI::Structure::Block")B= not &$follows_word($holder, \%LIST_BLOCK)
ABresult
0X0
100
111
229 70 ▶ return 1 if $holder->isa('PPI::Structure::Block');
Branch: 1 branch
BranchTrueFalseTotal
if $holder->isa("PPI::Structure::Block") 1 69 70
230 69 ▶ return 0 unless $holder->isa('PPI::Structure::List');
Branch: 1 branch
BranchTrueFalseTotal
unless $holder->isa("PPI::Structure::List") 8 61 69
231  
232 61 my $compound = $holder->parent;
233 61 ▶ return 0 if $compound->isa('PPI::Statement::Compound') && $compound->type ne 'foreach';
Branch: 1 branch
BranchTrueFalseTotal
if $compound->isa("PPI::Statement::Compound") and $compound->type ne "foreach" 0 61 61
Condition66%2/3
$compound->isa("PPI::Statement::Compound") and $compound->type ne "foreach"
!ll&&!rl&&r
5470
MC/DC0%0/2
$compound->isa("PPI::Statement::Compound") and $compound->type ne "foreach"
$compound->isa("PPI::Statement::Compound") $compound->type ne "foreach"
Truth table66%2/3
A and B
A= $compound->isa("PPI::Statement::Compound")B= $compound->type ne "foreach"
ABresult
0X0
100
111
234 61 ▶ return 1 if $compound->isa('PPI::Statement::Compound');
Branch: 1 branch
BranchTrueFalseTotal
if $compound->isa("PPI::Statement::Compound") 7 54 61
235  
236 # The list of a call: of a word, of a code reference, or of &name.
237 54 my $caller = $holder->sprevious_sibling;
238 54 ▶ return 0 if $caller && $caller->isa('PPI::Token::Word') && !$gives_a_list->($caller);
Branch: 1 branch
BranchTrueFalseTotal
if $caller and $caller->isa("PPI::Token::Word") and not &$gives_a_list($caller) 1 53 54
Condition100%6/6
$caller and $caller->isa("PPI::Token::Word") and not &$gives_a_list($caller)
!ll&&!rl&&r
4851
$caller and $caller->isa("PPI::Token::Word")
!ll&&!rl&&r
1476
MC/DC100%3/3
$caller and $caller->isa("PPI::Token::Word") and not &$gives_a_list($caller)
$caller $caller->isa("PPI::Token::Word") not &$gives_a_list($caller)
Truth table100%4/4
A and B and not(C)
A= $callerB= $caller->isa("PPI::Token::Word")C= not &$gives_a_list($caller)
ABCresult
0XX0
10X0
1100
1111
239 53 ▶ return 1 if $caller && ( $caller->isa('PPI::Token::Word') || $is_operator->( $caller, q{->} ) || ( $caller->isa('PPI::Token::Symbol') && index( $caller->content, q{&} ) == 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
if $caller and $caller->isa("PPI::Token::Word") || &$is_operator($caller, "->") || $caller->isa("PPI::Token::Symbol") && index($caller->content, "&") == 0 7 46 53
Condition91%11/12
$caller and $caller->isa("PPI::Token::Word") || &$is_operator($caller, "->") || $caller->isa("PPI::Token::Symbol") && index($caller->content, "&") == 0
!ll&&!rl&&r
1457
$caller->isa("PPI::Token::Word") or &$is_operator($caller, "->") or $caller->isa("PPI::Token::Symbol") and index($caller->content, "&") == 0
l!l&&r!l&&!r
6145
$caller->isa("PPI::Token::Word") or &$is_operator($caller, "->")
l!l&&r!l&&!r
5146
$caller->isa("PPI::Token::Symbol") and index($caller->content, "&") == 0
!ll&&!rl&&r
4501
MC/DC80%4/5
$caller and $caller->isa("PPI::Token::Word") || &$is_operator($caller, "->") || $caller->isa("PPI::Token::Symbol") && index($caller->content, "&") == 0
$caller $caller->isa("PPI::Token::Word") &$is_operator($caller, "->") $caller->isa("PPI::Token::Symbol") index($caller->content, "&") == 0
Truth table83%5/6
A and B or C or D and E
A= $callerB= $caller->isa("PPI::Token::Word")C= &$is_operator($caller, "->")D= $caller->isa("PPI::Token::Symbol")E= index($caller->content, "&") == 0
ABCDEresult
0XXXX0
1000X0
100100
11XXX1
101XX1
100111
240  
241 # A bare group, which has the context of the place where it is.
242 46 my ( undef, $past ) = $right_operand->($holder);
243 46 ▶ return 0 if $is_operator->( $past, q{?} );
Branch: 1 branch
BranchTrueFalseTotal
if &$is_operator($past, "?") 1 45 46
244  
245 # ( LIST )[ ... ], which PPI gives as a list and then a subscript,
246 # or a list and then an anonymous array.
247 45 my $next = $holder->snext_sibling;
248 45 ▶ return 1 if $next && ( $next->isa('PPI::Structure::Subscript') || $next->isa('PPI::Structure::Constructor') ) && $next->start->content eq q{[};
Branch: 1 branch
BranchTrueFalseTotal
if $next and $next->isa("PPI::Structure::Subscript") || $next->isa("PPI::Structure::Constructor") and $next->start->content eq "[" 1 44 45
Condition77%7/9
$next and $next->isa("PPI::Structure::Subscript") || $next->isa("PPI::Structure::Constructor") and $next->start->content eq "["
!ll&&!rl&&r
4401
$next and $next->isa("PPI::Structure::Subscript") || $next->isa("PPI::Structure::Constructor")
!ll&&!rl&&r
1431
$next->isa("PPI::Structure::Subscript") or $next->isa("PPI::Structure::Constructor")
l!l&&r!l&&!r
0143
MC/DC50%2/4
$next and $next->isa("PPI::Structure::Subscript") || $next->isa("PPI::Structure::Constructor") and $next->start->content eq "["
$next $next->isa("PPI::Structure::Subscript") $next->isa("PPI::Structure::Constructor") $next->start->content eq "["
Truth table50%3/6
A and B or C and D
A= $nextB= $next->isa("PPI::Structure::Subscript")C= $next->isa("PPI::Structure::Constructor")D= $next->start->content eq "["
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
249  
250 44 ( undef, $before ) = $left_operand->($holder);
251 44 $at = $holder;
252 44 next;
253 }
254  
255 78 ▶ if ( $is_operator->( $before, q{=} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$is_operator($before, "=")) 50 28 78
256  
257 # An array, a hash, a list or a slice on the left takes a list.
258 50 my $lhs = $before->sprevious_sibling;
259 50 ▶ return 0 unless $lhs;
Branch: 1 branch
BranchTrueFalseTotal
unless $lhs 0 50 50
260 50 ▶ return 1 if $lhs->isa('PPI::Structure::List');
Branch: 1 branch
BranchTrueFalseTotal
if $lhs->isa("PPI::Structure::List") 1 49 50
261 49 ▶ return 1 if $lhs->isa('PPI::Token::Symbol') && $lhs->content =~ m/\A[\@%]/xs;
Branch: 1 branch
BranchTrueFalseTotal
if $lhs->isa("PPI::Token::Symbol") and $lhs->content =~ /\A[\@%]/aasx 45 4 49
Condition100%3/3
$lhs->isa("PPI::Token::Symbol") and $lhs->content =~ /\A[\@%]/aasx
!ll&&!rl&&r
2245
MC/DC100%2/2
$lhs->isa("PPI::Token::Symbol") and $lhs->content =~ /\A[\@%]/aasx
$lhs->isa("PPI::Token::Symbol") $lhs->content =~ /\A[\@%]/aasx
Truth table100%3/3
A and B
A= $lhs->isa("PPI::Token::Symbol")B= $lhs->content =~ /\A[\@%]/aasx
ABresult
0X0
100
111
262 4 ▶ return 1 if ( $lhs->isa('PPI::Token::Symbol') || $lhs->isa('PPI::Structure::Block') ) && $after_list_cast->($lhs);
Branch: 1 branch
BranchTrueFalseTotal
if $lhs->isa("PPI::Token::Symbol") || $lhs->isa("PPI::Structure::Block") and &$after_list_cast($lhs) 2 2 4
Condition100%6/6
$lhs->isa("PPI::Token::Symbol") || $lhs->isa("PPI::Structure::Block") and &$after_list_cast($lhs)
!ll&&!rl&&r
112
$lhs->isa("PPI::Token::Symbol") or $lhs->isa("PPI::Structure::Block")
l!l&&r!l&&!r
211
MC/DC100%3/3
$lhs->isa("PPI::Token::Symbol") || $lhs->isa("PPI::Structure::Block") and &$after_list_cast($lhs)
$lhs->isa("PPI::Token::Symbol") $lhs->isa("PPI::Structure::Block") &$after_list_cast($lhs)
Truth table80%4/5
A or B and C
A= $lhs->isa("PPI::Token::Symbol")B= $lhs->isa("PPI::Structure::Block")C= &$after_list_cast($lhs)
ABCresult
00X0
1X00
0100
1X11
0111
263 2 ▶ return 1 if $lhs->isa('PPI::Structure::Subscript') && $is_slice->($lhs);
Branch: 1 branch
BranchTrueFalseTotal
if $lhs->isa("PPI::Structure::Subscript") and &$is_slice($lhs) 1 1 2
Condition66%2/3
$lhs->isa("PPI::Structure::Subscript") and &$is_slice($lhs)
!ll&&!rl&&r
101
MC/DC50%1/2
$lhs->isa("PPI::Structure::Subscript") and &$is_slice($lhs)
$lhs->isa("PPI::Structure::Subscript") &$is_slice($lhs)
Truth table66%2/3
A and B
A= $lhs->isa("PPI::Structure::Subscript")B= &$is_slice($lhs)
ABresult
0X0
100
111
264 1 return 0;
265 }
266  
267 28 ▶ if ( $before->isa('PPI::Token::Operator') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before->isa("PPI::Token::Operator")) 14 14 28
268  
269 # A range operator here ends an earlier range in the same list.
270 14 ▶ return 0 unless $LIST_SEPARATOR{ $before->content } || $RANGE_OPERATOR{ $before->content };
Branch: 1 branch
BranchTrueFalseTotal
unless $LIST_SEPARATOR{$before->content} or $RANGE_OPERATOR{$before->content} 1 13 14
Condition100%3/3
$LIST_SEPARATOR{$before->content} or $RANGE_OPERATOR{$before->content}
l!l&&r!l&&!r
941
MC/DC100%2/2
$LIST_SEPARATOR{$before->content} or $RANGE_OPERATOR{$before->content}
$LIST_SEPARATOR{$before->content} $RANGE_OPERATOR{$before->content}
Truth table100%3/3
A or B
A= $LIST_SEPARATOR{$before->content}B= $RANGE_OPERATOR{$before->content}
ABresult
1X1
011
000
271 13 $at = $before;
272 13 ( undef, $before ) = $left_operand->($before);
273 13 next;
274 }
275  
276 14 ▶ return 0 if $before->isa('PPI::Token::Word') && !$gives_a_list->($before);
Branch: 1 branch
BranchTrueFalseTotal
if $before->isa("PPI::Token::Word") and not &$gives_a_list($before) 6 8 14
Condition100%3/3
$before->isa("PPI::Token::Word") and not &$gives_a_list($before)
!ll&&!rl&&r
356
MC/DC100%2/2
$before->isa("PPI::Token::Word") and not &$gives_a_list($before)
$before->isa("PPI::Token::Word") not &$gives_a_list($before)
Truth table100%3/3
A and not(B)
A= $before->isa("PPI::Token::Word")B= not &$gives_a_list($before)
ABresult
0X0
100
111
277 8 ▶ return 1 if $before->isa('PPI::Token::Word') || $before->isa('PPI::Structure::Block');
Branch: 1 branch
BranchTrueFalseTotal
if $before->isa("PPI::Token::Word") or $before->isa("PPI::Structure::Block") 8 0 8
Condition66%2/3
$before->isa("PPI::Token::Word") or $before->isa("PPI::Structure::Block")
l!l&&r!l&&!r
530
MC/DC0%0/2
$before->isa("PPI::Token::Word") or $before->isa("PPI::Structure::Block")
$before->isa("PPI::Token::Word") $before->isa("PPI::Structure::Block")
Truth table66%2/3
A or B
A= $before->isa("PPI::Token::Word")B= $before->isa("PPI::Structure::Block")
ABresult
1X1
011
000
278 0 return 0;
279 }
280 0 return 0;
281 2 };
282  
283  
284 259 ▶sub violates {
Subroutine violates: called CC=28 SCAR=33.3
Pod documented
285 259 my ( $self, $elem ) = @_;
286 259 ▶ return () unless $RANGE_OPERATOR{ $elem->content };
Branch: 1 branch
BranchTrueFalseTotal
unless $RANGE_OPERATOR{$elem->content} 125 134 259
287  
288 134 my ( $left_elements, $before ) = $left_operand->($elem);
289 134 my ( $right_elements, $after ) = $right_operand->($elem);
290 134 ▶ return () unless @$left_elements && @$right_elements;
Branch: 1 branch
BranchTrueFalseTotal
unless @$left_elements and @$right_elements 1 133 134
Condition66%2/3
@$left_elements and @$right_elements
!ll&&!rl&&r
10133
MC/DC50%1/2
@$left_elements and @$right_elements
@$left_elements @$right_elements
Truth table66%2/3
A and B
A= @$left_elementsB= @$right_elements
ABresult
0X0
100
111
291  
292 # The condition of a ternary is in boolean context: a flip-flop.
293 133 ▶ return () if $is_operator->( $after, q{?} );
Branch: 1 branch
BranchTrueFalseTotal
if &$is_operator($after, "?") 1 132 133
294  
295 # What Perl gives for the range, as the end of the message.
296 132 my $left = $literal->(@$left_elements);
297 132 my $right = $literal->(@$right_elements);
298 132 ▶ return () unless defined $right;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $right 8 124 132
299 124 my $gives;
300 124 ▶ if ( !defined $left ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $left) { } 22 102 124
301 22 ▶ return () unless $right->{number};
Branch: 1 branch
BranchTrueFalseTotal
unless $right->{"number"} 2 20 22
302 20 my $end = int $right->{value};
303 20 ▶ return () if $end < 0 || $end > $self->{_largest_end};
Branch: 1 branch
BranchTrueFalseTotal
if $end < 0 or $end > $self->{"_largest_end"} 6 14 20
Condition100%3/3
$end < 0 or $end > $self->{"_largest_end"}
l!l&&r!l&&!r
2414
MC/DC100%2/2
$end < 0 or $end > $self->{"_largest_end"}
$end < 0 $end > $self->{"_largest_end"}
Truth table100%3/3
A or B
A= $end < 0B= $end > $self->{"_largest_end"}
ABresult
1X1
011
000
304 14 $gives = 'gives an empty list when ' . $source->(@$left_elements) . " is more than $end";
305 }
306 else {
307 102 my ( $from, $to ) = ( $left->{value}, $right->{value} );
308 102 ▶ return () unless defined $from && defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from and defined $to 1 101 102
Condition66%2/3
defined $from and defined $to
!ll&&!rl&&r
10101
MC/DC50%1/2
defined $from and defined $to
defined $from defined $to
Truth table66%2/3
A and B
A= defined $fromB= defined $to
ABresult
0X0
100
111
309  
310 # Perl counts by numbers, as pp_flop decides, with a number at either
311 # end, or two strings that look like numbers where the left one does
312 # not start with 0.
313 101 ▶ if ( $left->{number} || $right->{number} || ( looks_like_number($from) && index( $from, q{0} ) != 0 && looks_like_number($to) ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($left->{'number'} or $right->{'number'} or &looks_like_number($from) and index($from, '0') != 0 and &looks_like_number($to)) { } 75 26 101
elsif (length $from > length $to) { } 3 23 26
Condition91%11/12
$left->{"number"} or $right->{"number"} or &looks_like_number($from) and index($from, 0) != 0 and &looks_like_number($to)
l!l&&r!l&&!r
73226
$left->{"number"} or $right->{"number"}
l!l&&r!l&&!r
72128
&looks_like_number($from) and index($from, 0) != 0 and &looks_like_number($to)
!ll&&!rl&&r
2602
&looks_like_number($from) and index($from, 0) != 0
!ll&&!rl&&r
2512
MC/DC80%4/5
$left->{"number"} or $right->{"number"} or &looks_like_number($from) and index($from, 0) != 0 and &looks_like_number($to)
$left->{"number"} $right->{"number"} &looks_like_number($from) index($from, 0) != 0 &looks_like_number($to)
Truth table83%5/6
A or B or C and D and E
A= $left->{"number"}B= $right->{"number"}C= &looks_like_number($from)D= index($from, 0) != 0E= &looks_like_number($to)
ABCDEresult
1XXXX1
01XXX1
001111
000XX0
0010X0
001100
314 75 ▶ return () unless looks_like_number($from) && looks_like_number($to);
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($from) and &looks_like_number($to) 1 74 75
Condition66%2/3
&looks_like_number($from) and &looks_like_number($to)
!ll&&!rl&&r
1074
MC/DC50%1/2
&looks_like_number($from) and &looks_like_number($to)
&looks_like_number($from) &looks_like_number($to)
Truth table66%2/3
A and B
A= &looks_like_number($from)B= &looks_like_number($to)
ABresult
0X0
100
111
315 74 ▶ return () if int $from <= int $to;
Branch: 1 branch
BranchTrueFalseTotal
if int $from <= int $to 6 68 74
316 68 $gives = 'gives an empty list';
317 }
318 elsif ( length $from > length $to ) {
319 3 $gives = 'gives an empty list';
320 }
321 else {
322 23 ▶ return () if length $from < length $to || $from le $to;
Branch: 1 branch
BranchTrueFalseTotal
if length $from < length $to or $from le $to 7 16 23
Condition100%3/3
length $from < length $to or $from le $to
l!l&&r!l&&!r
3416
MC/DC100%2/2
length $from < length $to or $from le $to
length $from < length $to $from le $to
Truth table100%3/3
A or B
A= length $from < length $toB= $from le $to
ABresult
1X1
011
000
323  
324 # The same length, and $from sorts after $to. Perl counts up from
325 # $from by the magic increment, never meets $to, and stops before
326 # the first string that is longer. A string that is not letters
327 # then digits does not increment, so Perl gives it alone.
328 16 ▶ my $last = $from =~ m/\A[[:alpha:]]*[[:digit:]]*\z/xs ? join q{}, map { m/[[:digit:]]/xs ? q{9} : m/[[:upper:]]/xs ? q{Z} : q{z} } split m//xs, $from : $from;
Branch: 3 branches
BranchTrueFalseTotal
$from =~ /\A[[:alpha:]]*[[:digit:]]*\z/aasx ? : 14 2 16
/[[:digit:]]/aasx ? : 2 16 18
/[[:upper:]]/aasx ? : 3 13 16
329 16 ▶ $gives = $last eq $from ? "gives only ('$from')" : "gives every string from '$from' up to '$last', and never reaches '$to'";
Branch: 1 branch
BranchTrueFalseTotal
$last eq $from ? : 12 4 16
330 }
331 }
332  
333 101 ▶ return () unless $in_list_context->( $elem, $before );
Branch: 1 branch
BranchTrueFalseTotal
unless &$in_list_context($elem, $before) 22 79 101
334  
335 79 my $range = join q{ }, $source->(@$left_elements), $elem->content, $source->(@$right_elements);
336 79 return $self->violation( "$range $gives", $EXPL, $elem );
337 }
338  
339 2 1;
340  
341 __END__
↑ Summary