Policy/Compatibility/PerlMinimumVersionAndWhy.pm

filter: Statementstmt 16.3% 59 / 360 Branchbran 0.7% 1 / 138 Conditioncond 0.0% 0 / 219 MC/DCmcdc 0.0% 0 / 106 Subroutinesub 19.2% 16 / 83 Podpod 66.6% 2 / 3 totaltotal 8.5% 78 / 909 SCAR 97.5
CC
149
Cov
8%
__ANON__
132.0
_arg_is_array_elem
110.0
__ANON__
110.0
CRAP 17229.9
↑ Summary Policy/CodeLayout/RequireFinalSemicolon.pm »
1 # Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde
2  
3 # Perl-Critic-Pulp is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by the
5 # Free Software Foundation; either version 3, or (at your option) any later
6 # version.
7 #
8 # Perl-Critic-Pulp is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 # for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.
15  
16 package Perl::Critic::Policy::Compatibility::PerlMinimumVersionAndWhy;
17 40 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 40 ▶use version (); # but don't import qv()
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 # 1.208 for PPI::Token::QuoteLike::Regexp get_modifiers()
23 40 ▶use PPI 1.208;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # 1.084 for Perl::Critic::Document highest_explicit_perl_version()
26 40 ▶use Perl::Critic::Policy 1.084;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 40 ▶use base 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 40 ▶use Perl::Critic::Utils qw(parse_arg_list);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 40 ▶use Perl::Critic::Pulp::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 # uncomment this to run the ### lines
32 # use Smart::Comments;
33  
34 40 our $VERSION = 99;
35  
36 40 use constant supported_parameters =>
37 ({ name => 'above_version',
38 description => 'Check only things above this version of Perl.',
39 behavior => 'string',
40 parser => \&Perl::Critic::Pulp::Utils::parameter_parse_version,
41 },
42 { name => 'skip_checks',
43 description => 'Version checks to skip (space separated list).',
44 behavior => 'string',
45 40 ▶ });
Subroutine BEGIN: called CC=1 SCAR=0.0
46 40 ▶use constant default_severity => $Perl::Critic::Utils::SEVERITY_LOW;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 40 ▶use constant default_themes => qw(pulp compatibility);
Subroutine BEGIN: called CC=1 SCAR=0.0
48 40 ▶use constant applies_to => 'PPI::Document';
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50  
51 sub initialize_if_enabled {
52 2 ▶ my ($self, $config) = @_;
Subroutine initialize_if_enabled: called CC=2 SCAR=8.4
Pod documented
53 # ask that Perl::MinimumVersion is available and still has its
54 # undocumented %CHECKS to mangle below
55 2 ▶ eval { require Perl::MinimumVersion;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Perl::MinimumVersion; scalar %Perl::MinimumVersion::CHECKS } } or return 0 2 0 2
56 0 scalar %Perl::MinimumVersion::CHECKS }
57 or return 0;
58  
59 0 _setup_extra_checks();
60 }
61  
62 sub violates {
63 0 ▶ my ($self, $document) = @_;
Subroutine violates: not called CC=11 SCAR=46.9
Pod documented
64  
65 0 my %skip_checks;
66 0 ▶ if (defined (my $skip_checks = $self->{_skip_checks})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $skip_checks = $self->{"_skip_checks"})) 0 0 0
67 0 @skip_checks{split / /, $self->{_skip_checks}} = (); # hash slice
68 }
69  
70 0 my $pmv = Perl::MinimumVersion->new ($document);
71 0 my $config_above_version = $self->{'_above_version'};
72 0 my $explicit_version = _highest_explicit_perl_version($document);
73  
74 0 my @violations;
75 0 foreach my $check (sort keys %Perl::MinimumVersion::CHECKS) {
76 0 ▶ next if exists $skip_checks{$check};
Branch: 1 branch
BranchTrueFalseTotal
if exists $skip_checks{$check} 0 0 0
77 0 ▶ next if $check eq '_constant_hash'; # better by ConstantPragmaHash
Branch: 1 branch
BranchTrueFalseTotal
if $check eq "_constant_hash" 0 0 0
78 # next if $check =~ /_pragmas$/; # usually impossible in earlier
79 0 ▶ next if $check =~ /_modules$/; # wrong for dual-life stuff
Branch: 1 branch
BranchTrueFalseTotal
if $check =~ /_modules$/ 0 0 0
80  
81 0 my $check_version = $Perl::MinimumVersion::CHECKS{$check};
82 0 ▶ next if (defined $explicit_version
Branch: 1 branch
BranchTrueFalseTotal
if defined $explicit_version and $check_version <= $explicit_version 0 0 0
Condition0%0/3
defined $explicit_version and $check_version <= $explicit_version
!ll&&!rl&&r
000
MC/DC0%0/2
defined $explicit_version and $check_version <= $explicit_version
defined $explicit_version $check_version <= $explicit_version
Truth table0%0/3
A and B
A= defined $explicit_versionB= $check_version <= $explicit_version
ABresult
0X0
100
111
83 && $check_version <= $explicit_version);
84 0 ▶ next if (defined $config_above_version
Branch: 1 branch
BranchTrueFalseTotal
if defined $config_above_version and $check_version <= $config_above_version 0 0 0
Condition0%0/3
defined $config_above_version and $check_version <= $config_above_version
!ll&&!rl&&r
000
MC/DC0%0/2
defined $config_above_version and $check_version <= $config_above_version
defined $config_above_version $check_version <= $config_above_version
Truth table0%0/3
A and B
A= defined $config_above_versionB= $check_version <= $config_above_version
ABresult
0X0
100
111
85 && $check_version <= $config_above_version);
86 ### $check
87  
88 0 ▶ my $elem = do {
Condition0%0/2
do { || (next)
l!l
00
MC/DC0%0/1
do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x15\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"} local *PPI::Node::find_any = \&PPI::Node::find_first; $pmv->$check } || (next)
do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x15\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"} local *PPI::Node::find_any = \&PPI::Node::find_first; $pmv->$check }
Truth table0%0/2
A
A= do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x15\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"} local *PPI::Node::find_any = \&PPI::Node::find_first; $pmv->$check }
Aresult
11
00
89 40 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
90 0 local *PPI::Node::find_any = \&PPI::Node::find_first;
91 0 $pmv->$check
92 } || next;
93 # require Data::Dumper;
94 # print Data::Dumper::Dumper($elem);
95 # print $elem->location,"\n";
96 0 push @violations,
97 $self->violation ("$check requires $check_version",
98 '',
99 $elem);
100 }
101 0 return @violations;
102 }
103  
104 40 my $v5010 = version->new('5.010');
105  
106 # Some controversy:
107 # https://github.com/Perl-Critic/Perl-Critic/issues/270
108 # http://elliotlovesperl.com/2009/05/17/the-problem-with-modernperl/
109 #
110 sub _highest_explicit_perl_version {
111 0 ▶ my ($document) = @_;
Subroutine _highest_explicit_perl_version: not called CC=3 SCAR=24.8
112 ### _highest_explicit_perl_version() ...
113 0 my $ver = $document->highest_explicit_perl_version;
114 0 ▶ if ($ver < $v5010
Branch: 1 branch
BranchTrueFalseTotal
if ($ver < $v5010 and Perl::Critic::Policy::Compatibility::Gtk2Constants::_document_uses_module($document, "Modern::Perl")) 0 0 0
Condition0%0/3
$ver < $v5010 and Perl::Critic::Policy::Compatibility::Gtk2Constants::_document_uses_module($document, "Modern::Perl")
!ll&&!rl&&r
000
MC/DC0%0/2
$ver < $v5010 and Perl::Critic::Policy::Compatibility::Gtk2Constants::_document_uses_module($document, "Modern::Perl")
$ver < $v5010 Perl::Critic::Policy::Compatibility::Gtk2Constants::_document_uses_module($document, "Modern::Perl")
Truth table0%0/3
A and B
A= $ver < $v5010B= Perl::Critic::Policy::Compatibility::Gtk2Constants::_document_uses_module($document, "Modern::Perl")
ABresult
0X0
100
111
115 && Perl::Critic::Policy::Compatibility::Gtk2Constants::_document_uses_module($document,'Modern::Perl')) {
116 ### increase to 5.010 ...
117 0 $ver = $v5010;
118 }
119 0 return $ver;
120 }
121  
122  
123 #---------------------------------------------------------------------------
124 # Crib note: $document->find_first wanted func returning undef means the
125 # element is unwanted and also don't descend into its sub-elements.
126 #
127  
128 sub _setup_extra_checks {
129  
130 # 5.12.0
131 0 ▶ my $v5012 = version->new('5.012');
Subroutine _setup_extra_checks: not called CC=3 SCAR=24.8
132 0 $Perl::MinimumVersion::CHECKS{_Pulp__keys_of_array} = $v5012;
133 0 $Perl::MinimumVersion::CHECKS{_Pulp__values_of_array} = $v5012;
134 0 $Perl::MinimumVersion::CHECKS{_Pulp__each_of_array} = $v5012;
135  
136 # 5.10.0
137 0 ▶ unless (eval { Perl::MinimumVersion->VERSION(1.28); 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { "Perl::MinimumVersion"->VERSION("1.28"); 1 } }) 0 0 0
138 # fixed in 1.28 up
139 0 $Perl::MinimumVersion::CHECKS{_Pulp__5010_magic__fix} = $v5010;
140 0 $Perl::MinimumVersion::CHECKS{_Pulp__5010_operators__fix} = $v5010;
141 }
142 0 $Perl::MinimumVersion::CHECKS{_Pulp__5010_qr_m_propagate_properly} = $v5010;
143 0 $Perl::MinimumVersion::CHECKS{_Pulp__5010_stacked_filetest} = $v5010;
144  
145 # 5.8.0
146 0 my $v5008 = version->new('5.008');
147 0 $Perl::MinimumVersion::CHECKS{_Pulp__fat_comma_across_newline} = $v5008;
148 0 $Perl::MinimumVersion::CHECKS{_Pulp__eval_line_directive_first_thing} = $v5008;
149  
150 # 5.6.0
151 0 my $v5006 = version->new('5.006');
152 0 $Perl::MinimumVersion::CHECKS{_Pulp__exists_subr} = $v5006;
153 0 $Perl::MinimumVersion::CHECKS{_Pulp__exists_array_elem} = $v5006;
154 0 $Perl::MinimumVersion::CHECKS{_Pulp__delete_array_elem} = $v5006;
155 0 $Perl::MinimumVersion::CHECKS{_Pulp__0b_number} = $v5006;
156 0 $Perl::MinimumVersion::CHECKS{_Pulp__syswrite_length_optional} = $v5006;
157 0 $Perl::MinimumVersion::CHECKS{_Pulp__open_my_filehandle} = $v5006;
158 0 $Perl::MinimumVersion::CHECKS{_Pulp__var_method_without_parens} = $v5006;
159  
160 # 5.005
161 0 my $v5005 = version->new('5.005');
162 0 ▶ unless (exists
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Perl::MinimumVersion::CHECKS{"_bareword_ends_with_double_colon"}) 0 0 0
163 $Perl::MinimumVersion::CHECKS{_bareword_ends_with_double_colon}) {
164 # adopted into Perl::MinimumVersion 1.28
165 0 $Perl::MinimumVersion::CHECKS{_Pulp__bareword_double_colon} = $v5005;
166 }
167 0 $Perl::MinimumVersion::CHECKS{_Pulp__my_list_with_undef} = $v5005;
168  
169 # 5.004
170 0 my $v5004 = version->new('5.004');
171 0 $Perl::MinimumVersion::CHECKS{_Pulp__special_literal__PACKAGE__} = $v5004;
172 0 $Perl::MinimumVersion::CHECKS{_Pulp__use_version_number} = $v5004;
173 0 $Perl::MinimumVersion::CHECKS{_Pulp__for_loop_variable_using_my} = $v5004;
174 0 $Perl::MinimumVersion::CHECKS{_Pulp__arrow_coderef_call} = $v5004;
175 0 $Perl::MinimumVersion::CHECKS{_Pulp__sysseek_builtin} = $v5004;
176  
177 # UNIVERSAL.pm
178 0 $Perl::MinimumVersion::CHECKS{_Pulp__UNIVERSAL_methods_5004} = $v5004;
179 0 $Perl::MinimumVersion::CHECKS{_Pulp__UNIVERSAL_methods_5010} = $v5010;
180  
181 # pack()/unpack()
182 0 $Perl::MinimumVersion::CHECKS{_Pulp__pack_format_5004} = $v5004;
183 0 $Perl::MinimumVersion::CHECKS{_Pulp__pack_format_5006} = $v5006;
184 0 $Perl::MinimumVersion::CHECKS{_Pulp__pack_format_5008} = $v5008;
185 0 $Perl::MinimumVersion::CHECKS{_Pulp__pack_format_5010} = $v5010;
186 }
187  
188 {
189 # Perl::MinimumVersion prior to 1.28 had 'PPI::Token::Operator' and
190 # 'PPI::Token::Magic' swapped between the respective operator/magic tests
191  
192 package Perl::MinimumVersion;
193 40 ▶ use vars qw(%MATCHES);
Subroutine BEGIN: called CC=1 SCAR=0.0
194 sub _Pulp__5010_operators__fix {
195 shift->Document->find_first
196 (sub {
197 $_[1]->isa('PPI::Token::Operator')
198 and
199 0 ▶ $MATCHES{_perl_5010_operators}->{$_[1]->content};
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Operator") and $Perl::MinimumVersion::MATCHES{"_perl_5010_operators"}{$_[1]->content} 0 0 0
200 0 ▶ } );
Subroutine _Pulp__5010_operators__fix: not called CC=1 SCAR=6.9
201 }
202 sub _Pulp__5010_magic__fix {
203 shift->Document->find_first
204 (sub {
205 $_[1]->isa('PPI::Token::Magic')
206 and
207 0 ▶ $MATCHES{_perl_5010_magic}->{$_[1]->content};
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[1]->isa("PPI::Token::Magic") and $Perl::MinimumVersion::MATCHES{"_perl_5010_magic"}{$_[1]->content} 0 0 0
208 0 ▶ } );
Subroutine _Pulp__5010_magic__fix: not called CC=1 SCAR=6.9
209 }
210 }
211  
212 40 sub Perl::MinimumVersion::_Pulp__5010_qr_m_propagate_properly {
213 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__5010_qr_m_propagate_properly: not called CC=1 SCAR=6.9
214 ### _Pulp__5010_qr_m_propagate_properly() check ...
215 $pmv->Document->find_first
216 (sub {
217 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
218 0 ▶ $elem->isa('PPI::Token::QuoteLike::Regexp') || return 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Token::QuoteLike::Regexp") or return 0 0 0 0
219 0 my %modifiers = $elem->get_modifiers;
220 ### content: $elem->content
221 ### modifiers: \%modifiers
222 0 ▶ return ($modifiers{'m'} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$modifiers{'m'} ? : 0 0 0
223 0 });
224 }
225  
226 # new in 5.010 as described in perlfunc.pod
227 sub Perl::MinimumVersion::_Pulp__5010_stacked_filetest {
228 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__5010_stacked_filetest: not called CC=1 SCAR=6.9
229 ### _Pulp__5010_stacked_filetest() check ...
230 $pmv->Document->find_first
231 (sub {
232 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
233 0 ▶ return (_elem_is_filetest_operator($elem) # -X
Branch: 1 branch
BranchTrueFalseTotal
_elem_is_filetest_operator($elem) && ($elem = $elem->snext_sibling) && _elem_is_filetest_operator($elem) ? : 0 0 0
Condition0%0/6
_elem_is_filetest_operator($elem) and $elem = $elem->snext_sibling and _elem_is_filetest_operator($elem)
!ll&&!rl&&r
000
_elem_is_filetest_operator($elem) and $elem = $elem->snext_sibling
!ll&&!rl&&r
000
MC/DC0%0/3
_elem_is_filetest_operator($elem) and $elem = $elem->snext_sibling and _elem_is_filetest_operator($elem)
_elem_is_filetest_operator($elem) $elem = $elem->snext_sibling _elem_is_filetest_operator($elem)
Truth table0%0/4
A and B and C
A= _elem_is_filetest_operator($elem)B= $elem = $elem->snext_siblingC= _elem_is_filetest_operator($elem)
ABCresult
0XX0
10X0
1100
1111
234 && ($elem = $elem->snext_sibling) # has a next sibling
235 && _elem_is_filetest_operator($elem) # -X
236 ? 1 : 0);
237 0 });
238 }
239 # $elem is a PPI::Element
240 # Return true if it's a -X operator.
241 sub _elem_is_filetest_operator {
242 0 ▶ my ($elem) = @_;
Subroutine _elem_is_filetest_operator: not called CC=2 SCAR=17.9
243 0 ▶ return ($elem->isa('PPI::Token::Operator')
Condition0%0/3
$elem->isa('PPI::Token::Operator') && $elem =~ /^-./
!ll&&!rl&&r
000
MC/DC0%0/2
$elem->isa('PPI::Token::Operator') && $elem =~ /^-./
$elem->isa('PPI::Token::Operator') $elem =~ /^-./
Truth table0%0/3
A && B
A= $elem->isa('PPI::Token::Operator')B= $elem =~ /^-./
ABresult
0X0
100
111
244 && $elem =~ /^-./);
245 }
246  
247  
248 #-----------------------------------------------------------------------------
249 # foo \n => fat comma across newline new in 5.8.0
250 # extra code in 5.8 toke.c under comment "not a keyword" checking for =>
251 #
252  
253 sub Perl::MinimumVersion::_Pulp__fat_comma_across_newline {
254 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__fat_comma_across_newline: not called CC=1 SCAR=6.9
255 ### _Pulp__fat_comma_across_newline() check
256 $pmv->Document->find_first
257 (sub {
258 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=8 SCAR=42.8
259 ### elem: "$elem"
260 0 ▶ if ($elem->isa('PPI::Token::Operator')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Operator") and $elem->content eq "=>") 0 0 0
Condition0%0/3
$elem->isa("PPI::Token::Operator") and $elem->content eq "=>"
!ll&&!rl&&r
000
MC/DC0%0/2
$elem->isa("PPI::Token::Operator") and $elem->content eq "=>"
$elem->isa("PPI::Token::Operator") $elem->content eq "=>"
Truth table0%0/3
A and B
A= $elem->isa("PPI::Token::Operator")B= $elem->content eq "=>"
ABresult
0X0
100
111
261 && $elem->content eq '=>') {
262 0 my ($prev, $saw_newline) = sprevious_sibling_and_newline($elem);
263 ### prev: "$prev"
264 ### $saw_newline
265 0 ▶ if ($saw_newline
Branch: 1 branch
BranchTrueFalseTotal
if ($saw_newline and $prev and $prev->isa("PPI::Token::Word") and not $prev =~ /^-/ and not Perl::Critic::Utils::is_method_call($prev)) 0 0 0
Condition0%0/12
$saw_newline and $prev and $prev->isa("PPI::Token::Word") and not $prev =~ /^-/ and not Perl::Critic::Utils::is_method_call($prev)
!ll&&!rl&&r
000
$saw_newline and $prev and $prev->isa("PPI::Token::Word") and not $prev =~ /^-/
!ll&&!rl&&r
000
$saw_newline and $prev and $prev->isa("PPI::Token::Word")
!ll&&!rl&&r
000
$saw_newline and $prev
!ll&&!rl&&r
000
MC/DC0%0/5
$saw_newline and $prev and $prev->isa("PPI::Token::Word") and not $prev =~ /^-/ and not Perl::Critic::Utils::is_method_call($prev)
$saw_newline $prev $prev->isa("PPI::Token::Word") not $prev =~ /^-/ not Perl::Critic::Utils::is_method_call($prev)
Truth table0%0/6
A and B and C and not(D) and not(E)
A= $saw_newlineB= $prevC= $prev->isa("PPI::Token::Word")D= not $prev =~ /^-/E= not Perl::Critic::Utils::is_method_call($prev)
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
266 && $prev
267 && $prev->isa('PPI::Token::Word')
268 && $prev !~ /^-/ # -foo self-quotes
269 && ! Perl::Critic::Utils::is_method_call($prev)) { # ->foo
270 0 return 1; # found
271 }
272 }
273 0 return 0; # continue searching
274 0 });
275 }
276  
277 sub sprevious_sibling_and_newline {
278 0 ▶ my ($elem) = @_;
Subroutine sprevious_sibling_and_newline: not called CC=5 SCAR=34.0
Pod undocumented
279 ### sprevious_sibling_and_newline()
280 0 my $saw_newline;
281 0 for (;;) {
282 0 ▶ $elem = $elem->previous_sibling || last;
Condition0%0/2
$elem->previous_sibling || (last)
l!l
00
MC/DC0%0/1
$elem->previous_sibling || (last)
$elem->previous_sibling
Truth table0%0/2
A
A= $elem->previous_sibling
Aresult
11
00
283 0 ▶ if ($elem->isa('PPI::Token::Whitespace')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::Whitespace')) { } 0 0 0
elsif ($elem->isa('PPI::Token::Comment')) { } 0 0 0
284 0 ▶ $saw_newline ||= ($elem->content =~ /\n/);
Condition0%0/3
$saw_newline ||= $elem->content =~ /\n/
l!l&&r!l&&!r
000
MC/DC0%0/2
$saw_newline ||= $elem->content =~ /\n/
$saw_newline $elem->content =~ /\n/
Truth table0%0/3
A ||= B
A= $saw_newlineB= $elem->content =~ /\n/
ABresult
1X1
011
000
285 } elsif ($elem->isa('PPI::Token::Comment')) {
286 0 $saw_newline = 1;
287 } else {
288 0 last;
289 }
290 }
291 0 return ($elem, $saw_newline);
292 }
293  
294 #-----------------------------------------------------------------------------
295  
296 # delete $array[0] and exists $array[0] new in 5.6.0
297 # two functions so the "exists" or "delete" appears in the check name
298 #
299 sub Perl::MinimumVersion::_Pulp__exists_array_elem {
300 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__exists_array_elem: not called CC=1 SCAR=6.9
301 ### _Pulp__exists_array_elem() check
302 0 return _exists_or_delete_array_elem ($pmv, 'exists');
303 }
304 sub Perl::MinimumVersion::_Pulp__delete_array_elem {
305 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__delete_array_elem: not called CC=1 SCAR=6.9
306 ### _Pulp__delete_array_elem() check
307 0 return _exists_or_delete_array_elem ($pmv, 'delete');
308 }
309 sub _exists_or_delete_array_elem {
310 0 ▶ my ($pmv, $which) = @_;
Subroutine _exists_or_delete_array_elem: not called CC=1 SCAR=6.9
311 ### _exists_or_delete_array_elem()
312 $pmv->Document->find_first
313 (sub {
314 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
315 0 ▶ if ($elem->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::Word') and $elem eq $which and Perl::Critic::Utils::is_function_call($elem) and _arg_is_array_elem($elem->snext_sibling)) { } 0 0 0
Condition0%0/9
$elem->isa("PPI::Token::Word") and $elem eq $which and Perl::Critic::Utils::is_function_call($elem) and _arg_is_array_elem($elem->snext_sibling)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq $which and Perl::Critic::Utils::is_function_call($elem)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq $which
!ll&&!rl&&r
000
MC/DC0%0/4
$elem->isa("PPI::Token::Word") and $elem eq $which and Perl::Critic::Utils::is_function_call($elem) and _arg_is_array_elem($elem->snext_sibling)
$elem->isa("PPI::Token::Word") $elem eq $which Perl::Critic::Utils::is_function_call($elem) _arg_is_array_elem($elem->snext_sibling)
Truth table0%0/5
A and B and C and D
A= $elem->isa("PPI::Token::Word")B= $elem eq $whichC= Perl::Critic::Utils::is_function_call($elem)D= _arg_is_array_elem($elem->snext_sibling)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
316 && $elem eq $which
317 && Perl::Critic::Utils::is_function_call($elem)
318 && _arg_is_array_elem($elem->snext_sibling)) {
319 0 return 1;
320 } else {
321 0 return 0;
322 }
323 0 });
324 }
325 sub _arg_is_array_elem {
326 0 ▶ my ($elem) = @_;
Subroutine _arg_is_array_elem: not called CC=10 SCAR=47.0
327 ### _arg_is_array_elem: "$elem"
328  
329 0 ▶ (($elem = _descend_through_lists($elem))
Branch: 1 branch
BranchTrueFalseTotal
$elem = _descend_through_lists($elem) and $elem->isa("PPI::Token::Symbol") and $elem->raw_type eq "\$" and $elem = $elem->snext_sibling or return 0 0 0 0
Condition0%0/9
$elem = _descend_through_lists($elem) and $elem->isa("PPI::Token::Symbol") and $elem->raw_type eq "\$" and $elem = $elem->snext_sibling
!ll&&!rl&&r
000
$elem = _descend_through_lists($elem) and $elem->isa("PPI::Token::Symbol") and $elem->raw_type eq "\$"
!ll&&!rl&&r
000
$elem = _descend_through_lists($elem) and $elem->isa("PPI::Token::Symbol")
!ll&&!rl&&r
000
MC/DC0%0/4
$elem = _descend_through_lists($elem) and $elem->isa("PPI::Token::Symbol") and $elem->raw_type eq "\$" and $elem = $elem->snext_sibling
$elem = _descend_through_lists($elem) $elem->isa("PPI::Token::Symbol") $elem->raw_type eq "\$" $elem = $elem->snext_sibling
Truth table0%0/5
A and B and C and D
A= $elem = _descend_through_lists($elem)B= $elem->isa("PPI::Token::Symbol")C= $elem->raw_type eq "\$"D= $elem = $elem->snext_sibling
ABCDresult
0XXX0
10XX0
110X0
11100
11111
330 && $elem->isa('PPI::Token::Symbol')
331 && $elem->raw_type eq '$'
332 && ($elem = $elem->snext_sibling))
333 or return 0;
334  
335 0 my $ret = 0;
336 0 for (;;) {
337 0 ▶ if ($elem->isa('PPI::Structure::Subscript')) {
Branch: 3 branches
BranchTrueFalseTotal
if ($elem->isa('PPI::Structure::Subscript')) { } 0 0 0
elsif ($elem->isa('PPI::Structure::List')) { } 0 0 0
elsif ($elem->isa('PPI::Token::Operator') and $elem eq '->') { } 0 0 0
338 # adjacent $x{key}[123]
339 0 $ret = ($elem->start eq '[');
340 } elsif ($elem->isa('PPI::Structure::List')) {
341 # $x[0]->() function call
342 0 return 0;
343 ▶ } elsif ($elem->isa('PPI::Token::Operator')
Condition0%0/3
$elem->isa("PPI::Token::Operator") and $elem eq "->"
!ll&&!rl&&r
000
MC/DC0%0/2
$elem->isa("PPI::Token::Operator") and $elem eq "->"
$elem->isa("PPI::Token::Operator") $elem eq "->"
Truth table0%0/3
A and B
A= $elem->isa("PPI::Token::Operator")B= $elem eq "->"
ABresult
0X0
100
111
344 && $elem eq '->') {
345 # subscript ->, continue
346 } else {
347 # anything else below -> precedence, stop
348 0 last;
349 }
350 0 ▶ $elem = $elem->snext_sibling || last;
Condition0%0/2
$elem->snext_sibling || (last)
l!l
00
MC/DC0%0/1
$elem->snext_sibling || (last)
$elem->snext_sibling
Truth table0%0/2
A
A= $elem->snext_sibling
Aresult
11
00
351 }
352 ### $ret
353 0 return $ret;
354 }
355  
356 sub _descend_through_lists {
357 0 ▶ my ($elem) = @_;
Subroutine _descend_through_lists: not called CC=5 SCAR=34.0
358 0 ▶ while ($elem
Branch: 1 branch
BranchTrueFalseTotal
if ($elem and $elem->isa("PPI::Structure::List") || $elem->isa("PPI::Statement::Expression") || $elem->isa("PPI::Statement")) 0 0 0
Condition0%0/9
$elem and $elem->isa("PPI::Structure::List") || $elem->isa("PPI::Statement::Expression") || $elem->isa("PPI::Statement")
!ll&&!rl&&r
000
$elem->isa("PPI::Structure::List") or $elem->isa("PPI::Statement::Expression") or $elem->isa("PPI::Statement")
l!l&&r!l&&!r
000
$elem->isa("PPI::Structure::List") or $elem->isa("PPI::Statement::Expression")
l!l&&r!l&&!r
000
MC/DC0%0/4
$elem and $elem->isa("PPI::Structure::List") || $elem->isa("PPI::Statement::Expression") || $elem->isa("PPI::Statement")
$elem $elem->isa("PPI::Structure::List") $elem->isa("PPI::Statement::Expression") $elem->isa("PPI::Statement")
Truth table0%0/5
A and B or C or D
A= $elemB= $elem->isa("PPI::Structure::List")C= $elem->isa("PPI::Statement::Expression")D= $elem->isa("PPI::Statement")
ABCDresult
0XXX0
10000
11XX1
101X1
10011
359 && ($elem->isa('PPI::Structure::List')
360 || $elem->isa('PPI::Statement::Expression')
361 || $elem->isa('PPI::Statement'))) {
362 0 $elem = $elem->schild(0);
363 }
364 0 return $elem;
365 }
366  
367 # exists(&subr) new in 5.6.0
368 #
369 sub Perl::MinimumVersion::_Pulp__exists_subr {
370 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__exists_subr: not called CC=1 SCAR=6.9
371 ### _Pulp__exists_subr() check
372 $pmv->Document->find_first
373 (sub {
374 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
375 0 ▶ if ($elem->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::Word') and $elem eq 'exists' and Perl::Critic::Utils::is_function_call($elem) and $elem = _symbol_or_list_symbol($elem->snext_sibling) and $elem->symbol_type eq '&') { } 0 0 0
Condition0%0/12
$elem->isa("PPI::Token::Word") and $elem eq "exists" and Perl::Critic::Utils::is_function_call($elem) and $elem = _symbol_or_list_symbol($elem->snext_sibling) and $elem->symbol_type eq "&"
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq "exists" and Perl::Critic::Utils::is_function_call($elem) and $elem = _symbol_or_list_symbol($elem->snext_sibling)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq "exists" and Perl::Critic::Utils::is_function_call($elem)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq "exists"
!ll&&!rl&&r
000
MC/DC0%0/5
$elem->isa("PPI::Token::Word") and $elem eq "exists" and Perl::Critic::Utils::is_function_call($elem) and $elem = _symbol_or_list_symbol($elem->snext_sibling) and $elem->symbol_type eq "&"
$elem->isa("PPI::Token::Word") $elem eq "exists" Perl::Critic::Utils::is_function_call($elem) $elem = _symbol_or_list_symbol($elem->snext_sibling) $elem->symbol_type eq "&"
Truth table0%0/6
A and B and C and D and E
A= $elem->isa("PPI::Token::Word")B= $elem eq "exists"C= Perl::Critic::Utils::is_function_call($elem)D= $elem = _symbol_or_list_symbol($elem->snext_sibling)E= $elem->symbol_type eq "&"
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
376 && $elem eq 'exists'
377 && Perl::Critic::Utils::is_function_call($elem)
378 && ($elem = _symbol_or_list_symbol($elem->snext_sibling))
379 && $elem->symbol_type eq '&') {
380 0 return 1;
381 } else {
382 0 return 0;
383 }
384 0 });
385 }
386  
387 # 0b110011 binary literals new in 5.6.0
388 #
389 sub Perl::MinimumVersion::_Pulp__0b_number {
390 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__0b_number: not called CC=1 SCAR=6.9
391 ### _Pulp__0b_number() check
392 $pmv->Document->find_first
393 (sub {
394 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
395 0 ▶ if ($elem->isa('PPI::Token::Number::Binary')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::Number::Binary')) { } 0 0 0
396 0 return 1;
397 } else {
398 0 return 0;
399 }
400 0 });
401 }
402  
403 # syswrite($fh,$str) length optional in 5.6.0
404 #
405 sub Perl::MinimumVersion::_Pulp__syswrite_length_optional {
406 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__syswrite_length_optional: not called CC=1 SCAR=6.9
407 ### _Pulp__syswrite_length_optional() check
408 $pmv->Document->find_first
409 (sub {
410 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
411 0 my @args;
412 0 ▶ if ($elem->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::Word') and $elem eq 'syswrite' and Perl::Critic::Utils::is_function_call($elem) and (@args = Perl::Critic::Utils::parse_arg_list($elem)) == 2) { } 0 0 0
Condition0%0/9
$elem->isa("PPI::Token::Word") and $elem eq "syswrite" and Perl::Critic::Utils::is_function_call($elem) and (@args = Perl::Critic::Utils::parse_arg_list($elem)) == 2
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq "syswrite" and Perl::Critic::Utils::is_function_call($elem)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq "syswrite"
!ll&&!rl&&r
000
MC/DC0%0/4
$elem->isa("PPI::Token::Word") and $elem eq "syswrite" and Perl::Critic::Utils::is_function_call($elem) and (@args = Perl::Critic::Utils::parse_arg_list($elem)) == 2
$elem->isa("PPI::Token::Word") $elem eq "syswrite" Perl::Critic::Utils::is_function_call($elem) (@args = Perl::Critic::Utils::parse_arg_list($elem)) == 2
Truth table0%0/5
A and B and C and D
A= $elem->isa("PPI::Token::Word")B= $elem eq "syswrite"C= Perl::Critic::Utils::is_function_call($elem)D= (@args = Perl::Critic::Utils::parse_arg_list($elem)) == 2
ABCDresult
0XXX0
10XX0
110X0
11100
11111
413 && $elem eq 'syswrite'
414 && Perl::Critic::Utils::is_function_call($elem)
415 && (@args = Perl::Critic::Utils::parse_arg_list($elem)) == 2) {
416 0 return 1;
417 } else {
418 0 return 0;
419 }
420 0 });
421 }
422  
423 # open(my $fh,...) auto-creating a handle glob new in 5.6.0
424 #
425 40 my %open_func = (open => 1,
426 opendir => 1,
427 pipe => 2,
428 socketpair => 2,
429 sysopen => 1,
430 socket => 1,
431 accept => 1);
432 sub Perl::MinimumVersion::_Pulp__open_my_filehandle {
433 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__open_my_filehandle: not called CC=1 SCAR=6.9
434 ### _Pulp__open_my_filehandle() check
435 $pmv->Document->find_first
436 (sub {
437 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=11 SCAR=48.8
438 0 my ($count, $my, $fh);
439 0 ▶ unless ($elem->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem->isa("PPI::Token::Word") and $count = $open_func{$elem} and Perl::Critic::Utils::is_function_call($elem)) 0 0 0
Condition0%0/6
$elem->isa("PPI::Token::Word") and $count = $open_func{$elem} and Perl::Critic::Utils::is_function_call($elem)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $count = $open_func{$elem}
!ll&&!rl&&r
000
MC/DC0%0/3
$elem->isa("PPI::Token::Word") and $count = $open_func{$elem} and Perl::Critic::Utils::is_function_call($elem)
$elem->isa("PPI::Token::Word") $count = $open_func{$elem} Perl::Critic::Utils::is_function_call($elem)
Truth table0%0/4
A and B and C
A= $elem->isa("PPI::Token::Word")B= $count = $open_func{$elem}C= Perl::Critic::Utils::is_function_call($elem)
ABCresult
0XX0
10X0
1100
1111
440 && ($count = $open_func{$elem})
441 && Perl::Critic::Utils::is_function_call($elem)) {
442 0 return 0;
443 }
444 0 $my = $elem->snext_sibling;
445  
446 # with parens is
447 # PPI::Token::Word 'open'
448 # PPI::Structure::List ( ... )
449 # PPI::Statement::Variable
450 # PPI::Token::Word 'my'
451 # PPI::Token::Symbol '$fh'
452 # PPI::Token::Operator ','
453 #
454 0 ▶ if ($my->isa('PPI::Structure::List')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($my->isa("PPI::Structure::List")) 0 0 0
455 0 ▶ $my = $my->schild(0) || return 0;
Condition0%0/2
$my->schild(0) || (return 0)
l!l
00
MC/DC0%0/1
$my->schild(0) || (return 0)
$my->schild(0)
Truth table0%0/2
A
A= $my->schild(0)
Aresult
11
00
456 }
457 0 ▶ if ($my->isa('PPI::Statement::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($my->isa("PPI::Statement::Variable")) 0 0 0
458 0 ▶ $my = $my->schild(0) || return 0;
Condition0%0/2
$my->schild(0) || (return 0)
l!l
00
MC/DC0%0/1
$my->schild(0) || (return 0)
$my->schild(0)
Truth table0%0/2
A
A= $my->schild(0)
Aresult
11
00
459 }
460  
461 0 foreach (1 .. $count) {
462 ### my: "$my"
463 0 ▶ if (_is_uninitialized_my($my)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_uninitialized_my($my)) 0 0 0
464 0 return 1;
465 }
466 0 ▶ $my = _skip_to_next_arg($my) || last;
Condition0%0/2
_skip_to_next_arg($my) || (last)
l!l
00
MC/DC0%0/1
_skip_to_next_arg($my) || (last)
_skip_to_next_arg($my)
Truth table0%0/2
A
A= _skip_to_next_arg($my)
Aresult
11
00
467 }
468 0 return 0;
469 0 });
470 }
471  
472 sub _is_uninitialized_my {
473 0 ▶ my ($my) = @_;
Subroutine _is_uninitialized_my: not called CC=8 SCAR=42.8
474 0 my ($fh, $after);
475 0 ▶ return ($my->isa('PPI::Token::Word')
Condition0%0/21
$my->isa('PPI::Token::Word') && $my eq 'my' && ($fh = $my->snext_sibling) && $fh->isa('PPI::Token::Symbol') && $fh->symbol_type eq '$' && !(($after = $fh->snext_sibling) && $after->isa('PPI::Token::Operator') && $after eq '=')
!ll&&!rl&&r
000
$my->isa("PPI::Token::Word") and $my eq "my" and $fh = $my->snext_sibling and $fh->isa("PPI::Token::Symbol") and $fh->symbol_type eq "\$"
!ll&&!rl&&r
000
$my->isa("PPI::Token::Word") and $my eq "my" and $fh = $my->snext_sibling and $fh->isa("PPI::Token::Symbol")
!ll&&!rl&&r
000
$my->isa("PPI::Token::Word") and $my eq "my" and $fh = $my->snext_sibling
!ll&&!rl&&r
000
$my->isa("PPI::Token::Word") and $my eq "my"
!ll&&!rl&&r
000
($after = $fh->snext_sibling) && $after->isa('PPI::Token::Operator') && $after eq '='
!ll&&!rl&&r
000
$after = $fh->snext_sibling and $after->isa("PPI::Token::Operator")
!ll&&!rl&&r
000
MC/DC0%0/8
$my->isa('PPI::Token::Word') && $my eq 'my' && ($fh = $my->snext_sibling) && $fh->isa('PPI::Token::Symbol') && $fh->symbol_type eq '$' && !(($after = $fh->snext_sibling) && $after->isa('PPI::Token::Operator') && $after eq '=')
$my->isa("PPI::Token::Word") $my eq "my" $fh = $my->snext_sibling $fh->isa("PPI::Token::Symbol") $fh->symbol_type eq "\$" $after = $fh->snext_sibling $after->isa("PPI::Token::Operator") $after eq '='
Truth table0%0/9
A and B and C and D and E && not(F and G && H)
A= $my->isa("PPI::Token::Word")B= $my eq "my"C= $fh = $my->snext_siblingD= $fh->isa("PPI::Token::Symbol")E= $fh->symbol_type eq "\$"F= $after = $fh->snext_siblingG= $after->isa("PPI::Token::Operator")H= $after eq '='
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111111110
111110XX1
1111110X1
111111101
476 && $my eq 'my'
477 && ($fh = $my->snext_sibling)
478 && $fh->isa('PPI::Token::Symbol')
479 && $fh->symbol_type eq '$'
480 && ! (($after = $fh->snext_sibling)
481 && $after->isa('PPI::Token::Operator')
482 && $after eq '='));
483 }
484  
485 # FIXME: is this enough for prototyped funcalls in the args?
486 sub _skip_to_next_arg {
487 0 ▶ my ($elem) = @_;
Subroutine _skip_to_next_arg: not called CC=4 SCAR=30.0
488 0 for (;;) {
489 0 ▶ my $next = $elem->snext_sibling || return undef;
Condition0%0/2
$elem->snext_sibling || (return undef)
l!l
00
MC/DC0%0/1
$elem->snext_sibling || (return undef)
$elem->snext_sibling
Truth table0%0/2
A
A= $elem->snext_sibling
Aresult
11
00
490 0 ▶ if ($elem->isa('PPI::Token::Operator')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Operator") and $Perl::Critic::Pulp::Utils::COMMA{$elem}) 0 0 0
Condition0%0/3
$elem->isa("PPI::Token::Operator") and $Perl::Critic::Pulp::Utils::COMMA{$elem}
!ll&&!rl&&r
000
MC/DC0%0/2
$elem->isa("PPI::Token::Operator") and $Perl::Critic::Pulp::Utils::COMMA{$elem}
$elem->isa("PPI::Token::Operator") $Perl::Critic::Pulp::Utils::COMMA{$elem}
Truth table0%0/3
A and B
A= $elem->isa("PPI::Token::Operator")B= $Perl::Critic::Pulp::Utils::COMMA{$elem}
ABresult
0X0
100
111
491 && $Perl::Critic::Pulp::Utils::COMMA{$elem}) {
492 0 return $next;
493 }
494 0 $elem = $next;
495 }
496 }
497  
498 # $obj->$method; omit parens new in 5.6.0
499 # previously required parens like $obj->$method();
500 #
501 sub Perl::MinimumVersion::_Pulp__var_method_without_parens {
502 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__var_method_without_parens: not called CC=1 SCAR=6.9
503 ### _Pulp__var_method_without_parens() ...
504 $pmv->Document->find_first
505 (sub {
506 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
507 0 my $next;
508 0 ▶ if ($elem->isa('PPI::Token::Symbol')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::Symbol') and $elem->symbol_type eq '$' and Perl::Critic::Utils::is_method_call($elem) and not +($next = $elem->snext_sibling) && $next->isa('PPI::Structure::List')) { } 0 0 0
Condition0%0/12
$elem->isa("PPI::Token::Symbol") and $elem->symbol_type eq "\$" and Perl::Critic::Utils::is_method_call($elem) and not +($next = $elem->snext_sibling) && $next->isa("PPI::Structure::List")
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Symbol") and $elem->symbol_type eq "\$" and Perl::Critic::Utils::is_method_call($elem)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Symbol") and $elem->symbol_type eq "\$"
!ll&&!rl&&r
000
($next = $elem->snext_sibling) && $next->isa('PPI::Structure::List')
!ll&&!rl&&r
000
MC/DC0%0/5
$elem->isa("PPI::Token::Symbol") and $elem->symbol_type eq "\$" and Perl::Critic::Utils::is_method_call($elem) and not +($next = $elem->snext_sibling) && $next->isa("PPI::Structure::List")
$elem->isa("PPI::Token::Symbol") $elem->symbol_type eq "\$" Perl::Critic::Utils::is_method_call($elem) ($next = $elem->snext_sibling) $next->isa('PPI::Structure::List')
Truth table0%0/6
A and B and C and not(D && E)
A= $elem->isa("PPI::Token::Symbol")B= $elem->symbol_type eq "\$"C= Perl::Critic::Utils::is_method_call($elem)D= ($next = $elem->snext_sibling)E= $next->isa('PPI::Structure::List')
ABCDEresult
0XXXX0
10XXX0
110XX0
111110
1110X1
111101
509 && $elem->symbol_type eq '$'
510 && Perl::Critic::Utils::is_method_call($elem)
511 # must be followed by "()" for earlier perl, so if not then it
512 # means 5.6.0 required
513 && ! (($next = $elem->snext_sibling)
514 && $next->isa('PPI::Structure::List'))) {
515 0 return 1;
516 } else {
517 0 return 0;
518 }
519 0 });
520 }
521  
522 #-----------------------------------------------------------------------------
523 # Foo::Bar:: bareword new in 5.005
524 # generally a compile-time syntax error in 5.004
525 #
526 sub Perl::MinimumVersion::_Pulp__bareword_double_colon {
527 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__bareword_double_colon: not called CC=1 SCAR=6.9
528 ### _Pulp__bareword_double_colon() check
529 $pmv->Document->find_first
530 (sub {
531 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
532 0 ▶ if ($elem->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::Word') and $elem =~ /::$/) { } 0 0 0
Condition0%0/3
$elem->isa("PPI::Token::Word") and $elem =~ /::$/
!ll&&!rl&&r
000
MC/DC0%0/2
$elem->isa("PPI::Token::Word") and $elem =~ /::$/
$elem->isa("PPI::Token::Word") $elem =~ /::$/
Truth table0%0/3
A and B
A= $elem->isa("PPI::Token::Word")B= $elem =~ /::$/
ABresult
0X0
100
111
533 && $elem =~ /::$/) {
534 0 return 1;
535 } else {
536 0 return 0;
537 }
538 0 });
539 }
540  
541 # my ($x, undef, $y), undef in a my() list new in 5.005
542 # usually something like my (undef, $x) = @values
543 #
544 sub Perl::MinimumVersion::_Pulp__my_list_with_undef {
545 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__my_list_with_undef: not called CC=1 SCAR=6.9
546 ### _Pulp__my_list_with_undef() check
547 $pmv->Document->find_first
548 (sub {
549 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
550 0 ▶ if ($elem->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::Word') and $elem eq 'my' and _list_contains_undef($elem->snext_sibling)) { } 0 0 0
Condition0%0/6
$elem->isa("PPI::Token::Word") and $elem eq "my" and _list_contains_undef($elem->snext_sibling)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq "my"
!ll&&!rl&&r
000
MC/DC0%0/3
$elem->isa("PPI::Token::Word") and $elem eq "my" and _list_contains_undef($elem->snext_sibling)
$elem->isa("PPI::Token::Word") $elem eq "my" _list_contains_undef($elem->snext_sibling)
Truth table0%0/4
A and B and C
A= $elem->isa("PPI::Token::Word")B= $elem eq "my"C= _list_contains_undef($elem->snext_sibling)
ABCresult
0XX0
10X0
1100
1111
551 && $elem eq 'my'
552 && _list_contains_undef ($elem->snext_sibling)) {
553 0 return 1;
554 } else {
555 0 return 0;
556 }
557 0 });
558 }
559  
560 # $elem is a PPI::Element or false
561 # return true if it's a list and there's an 'undef' element in the list
562 #
563 # PPI::Structure::List ( ... )
564 # PPI::Statement::Expression
565 # PPI::Token::Symbol '$x'
566 # PPI::Token::Operator ','
567 # PPI::Token::Word 'undef'
568 # PPI::Token::Operator ','
569 # PPI::Token::Symbol '$y'
570 #
571 # Or for multi-parens: my ((undef)) with PPI::Statement in the middle
572 #
573 # PPI::Structure::List ( ... )
574 # PPI::Statement
575 # PPI::Structure::List ( ... )
576 # PPI::Statement::Expression
577 # PPI::Token::Word 'undef'
578 #
579 sub _list_contains_undef {
580 0 ▶ my ($elem) = @_;
Subroutine _list_contains_undef: not called CC=9 SCAR=45.0
581 ### _list_contains_undef: "$elem"
582 0 ▶ $elem or return;
Branch: 1 branch
BranchTrueFalseTotal
$elem or return 0 0 0
583 0 ▶ $elem->isa('PPI::Structure::List') or return;
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Structure::List") or return 0 0 0
584 0 my @search = ($elem);
585 0 ▶ while (@search) {
Branch: 1 branch
BranchTrueFalseTotal
if (@search) 0 0 0
586 0 $elem = pop @search;
587 ### elem: "$elem"
588 0 ▶ if ($elem->isa('PPI::Structure::List')
Branch: 2 branches
BranchTrueFalseTotal
if ($elem->isa('PPI::Structure::List') or $elem->isa('PPI::Statement::Expression') or $elem->isa('PPI::Statement')) { } 0 0 0
elsif ($elem->isa('PPI::Token::Word') and $elem eq 'undef') { } 0 0 0
Condition0%0/6
$elem->isa("PPI::Structure::List") or $elem->isa("PPI::Statement::Expression") or $elem->isa("PPI::Statement")
l!l&&r!l&&!r
000
$elem->isa("PPI::Structure::List") or $elem->isa("PPI::Statement::Expression")
l!l&&r!l&&!r
000
MC/DC0%0/3
$elem->isa("PPI::Structure::List") or $elem->isa("PPI::Statement::Expression") or $elem->isa("PPI::Statement")
$elem->isa("PPI::Structure::List") $elem->isa("PPI::Statement::Expression") $elem->isa("PPI::Statement")
Truth table0%0/4
A or B or C
A= $elem->isa("PPI::Structure::List")B= $elem->isa("PPI::Statement::Expression")C= $elem->isa("PPI::Statement")
ABCresult
1XX1
01X1
0011
0000
589 || $elem->isa('PPI::Statement::Expression')
590 || $elem->isa('PPI::Statement')) {
591 0 push @search, $elem->schildren;
592 ▶ } elsif ($elem->isa('PPI::Token::Word')
Condition0%0/3
$elem->isa("PPI::Token::Word") and $elem eq "undef"
!ll&&!rl&&r
000
MC/DC0%0/2
$elem->isa("PPI::Token::Word") and $elem eq "undef"
$elem->isa("PPI::Token::Word") $elem eq "undef"
Truth table0%0/3
A and B
A= $elem->isa("PPI::Token::Word")B= $elem eq "undef"
ABresult
0X0
100
111
593 && $elem eq 'undef') {
594 0 return 1;
595 }
596 }
597 }
598  
599  
600 #-----------------------------------------------------------------------------
601 # pack() / unpack()
602 #
603 # Nothing new in 5.12, nothing new in 5.14.
604  
605 sub Perl::MinimumVersion::_Pulp__pack_format_5004 {
606 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__pack_format_5004: not called CC=1 SCAR=6.9
607 # w - BER integer
608 0 return _pack_format ($pmv, qr/w/);
609 }
610 sub Perl::MinimumVersion::_Pulp__pack_format_5006 {
611 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__pack_format_5006: not called CC=1 SCAR=6.9
612 # Z - asciz
613 # q - signed quad
614 # Q - unsigned quad
615 # ! - native size
616 # / - counted string
617 # # - comment
618 0 return _pack_format ($pmv, qr{[ZqQ!/#]});
619 }
620 sub Perl::MinimumVersion::_Pulp__pack_format_5008 {
621 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__pack_format_5008: not called CC=1 SCAR=6.9
622 # F - NV
623 # D - long double
624 # j - IV
625 # J - UV
626 # ( - group
627 # [ - in a repeat count like "L[20]"
628 0 return _pack_format ($pmv, qr/[FDjJ([]/);
629 }
630 sub Perl::MinimumVersion::_Pulp__pack_format_5010 {
631 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__pack_format_5010: not called CC=1 SCAR=6.9
632 # < - little endian
633 # > - big endian
634 0 return _pack_format ($pmv, qr/[<>]/);
635 }
636 # Think nothing new in 5012 ...
637  
638 40 my %pack_func = (pack => 1, unpack => 1);
639 sub _pack_format {
640 0 ▶ my ($pmv, $regexp) = @_;
Subroutine _pack_format: not called CC=1 SCAR=6.9
641 0 require Perl::Critic::Policy::Miscellanea::TextDomainPlaceholders;
642 $pmv->Document->find_first
643 (sub {
644 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
645  
646 0 ▶ $elem->isa ('PPI::Token::Word') || return 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Token::Word") or return 0 0 0 0
647 0 ▶ $pack_func{$elem->content} || return 0;
Branch: 1 branch
BranchTrueFalseTotal
$pack_func{$elem->content} or return 0 0 0 0
648 0 ▶ Perl::Critic::Utils::is_function_call($elem) || return 0;
Branch: 1 branch
BranchTrueFalseTotal
Perl::Critic::Utils::is_function_call($elem) or return 0 0 0 0
649  
650 0 my @args = parse_arg_list ($elem);
651 0 my $format_arg = $args[0];
652 ### format: @$format_arg
653  
654 0 my ($str, $any_vars) = Perl::Critic::Policy::Miscellanea::TextDomainPlaceholders::_arg_string ($format_arg, $document);
655 ### $str
656 ### $any_vars
657  
658 0 ▶ if ($any_vars) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
if ($any_vars) 0 0 0
659 0 return ($str =~ $regexp);
660 0 });
661 }
662  
663 # 5.004 new __PACKAGE__
664 #
665 sub Perl::MinimumVersion::_Pulp__special_literal__PACKAGE__ {
666 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__special_literal__PACKAGE__: not called CC=1 SCAR=6.9
667 ### _Pulp__special_literal__PACKAGE__
668 $pmv->Document->find_first
669 (sub {
670 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
671 0 ▶ if ($elem->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::Word') and $elem eq '__PACKAGE__' and not Perl::Critic::Utils::is_hash_key($elem)) { } 0 0 0
Condition0%0/6
$elem->isa("PPI::Token::Word") and $elem eq "__PACKAGE__" and not Perl::Critic::Utils::is_hash_key($elem)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq "__PACKAGE__"
!ll&&!rl&&r
000
MC/DC0%0/3
$elem->isa("PPI::Token::Word") and $elem eq "__PACKAGE__" and not Perl::Critic::Utils::is_hash_key($elem)
$elem->isa("PPI::Token::Word") $elem eq "__PACKAGE__" not Perl::Critic::Utils::is_hash_key($elem)
Truth table0%0/4
A and B and not(C)
A= $elem->isa("PPI::Token::Word")B= $elem eq "__PACKAGE__"C= not Perl::Critic::Utils::is_hash_key($elem)
ABCresult
0XX0
10X0
1100
1111
672 && $elem eq '__PACKAGE__'
673 && ! Perl::Critic::Utils::is_hash_key($elem)) {
674 0 return 1;
675 } else {
676 0 return 0;
677 }
678 0 });
679 }
680  
681 # 5.004 new "use VERSION"
682 #
683 # "use MODULE VERSION" is not as easy, fairly sure it depends whether the
684 # target module uses Exporter.pm or not since the VERSION part is passed to
685 # import() and Exporter.pm checks it.
686 #
687 sub Perl::MinimumVersion::_Pulp__use_version_number {
688 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__use_version_number: not called CC=1 SCAR=6.9
689 ### _Pulp__use_version_number
690 $pmv->Document->find_first
691 (sub {
692 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
693 0 ▶ $elem->isa('PPI::Statement::Include') or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Statement::Include") or return 0 0 0 0
694 0 ▶ $elem->type eq 'use' or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->type eq "use" or return 0 0 0 0
695 0 ▶ if ($elem->version ne '') { # empty string '' for not a "use VERSION"
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->version ne '') { } 0 0 0
696 0 return 1;
697 } else {
698 0 return 0;
699 }
700 0 });
701 }
702  
703 # 5.004 new "foreach my $i" lexical loop variable
704 #
705 sub Perl::MinimumVersion::_Pulp__for_loop_variable_using_my {
706 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__for_loop_variable_using_my: not called CC=1 SCAR=6.9
707 ### _Pulp__for_loop_variable_using_my
708 $pmv->Document->find_first
709 (sub {
710 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=6 SCAR=37.4
711 0 ▶ $elem->isa('PPI::Statement::Compound') or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Statement::Compound") or return 0 0 0 0
712 0 ▶ $elem->type eq 'foreach' or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->type eq "foreach" or return 0 0 0 0
713 0 ▶ my $second = $elem->schild(1) || return 0;
Condition0%0/2
$elem->schild(1) || (return 0)
l!l
00
MC/DC0%0/1
$elem->schild(1) || (return 0)
$elem->schild(1)
Truth table0%0/2
A
A= $elem->schild(1)
Aresult
11
00
714 0 ▶ $second->isa('PPI::Token::Word') or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$second->isa("PPI::Token::Word") or return 0 0 0 0
715 0 ▶ if ($second eq 'my') {
Branch: 1 branch
BranchTrueFalseTotal
if ($second eq 'my') { } 0 0 0
716 0 return 1;
717 } else {
718 0 return 0;
719 }
720 0 });
721 }
722  
723 # 5.004 new "$foo->(PARAMS)" coderef call
724 #
725 sub Perl::MinimumVersion::_Pulp__arrow_coderef_call {
726 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__arrow_coderef_call: not called CC=1 SCAR=6.9
727 ### _Pulp__arrow_coderef_call
728 $pmv->Document->find_first
729 (sub {
730 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
731 0 ▶ $elem->isa('PPI::Token::Operator') or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Token::Operator") or return 0 0 0 0
732 ### operator: "$elem"
733 0 ▶ $elem eq '->' or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$elem eq "->" or return 0 0 0 0
734 0 ▶ $elem = $elem->snext_sibling || return 0;
Condition0%0/2
$elem->snext_sibling || (return 0)
l!l
00
MC/DC0%0/1
$elem->snext_sibling || (return 0)
$elem->snext_sibling
Truth table0%0/2
A
A= $elem->snext_sibling
Aresult
11
00
735 ### next: "$elem"
736 0 ▶ if ($elem->isa('PPI::Structure::List')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa('PPI::Structure::List')) { } 0 0 0
737 0 return 1;
738 } else {
739 0 return 0;
740 }
741 0 });
742 }
743  
744 # 5.004 new sysseek() function
745 #
746 # Crib note: the prototype() function is newly documented in 5.004 but
747 # existed earlier, or something. Might have returned a trailing "\0" in
748 # 5.003.
749 #
750 sub Perl::MinimumVersion::_Pulp__sysseek_builtin {
751 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__sysseek_builtin: not called CC=1 SCAR=6.9
752 ### _Pulp__sysseek_builtin
753 $pmv->Document->find_first
754 (sub {
755 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
756 0 ▶ if ($elem->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::Word') and $elem eq 'sysseek' || $elem eq 'CORE::sysseek' and Perl::Critic::Utils::is_function_call($elem)) { } 0 0 0
Condition0%0/9
$elem->isa("PPI::Token::Word") and $elem eq "sysseek" || $elem eq "CORE::sysseek" and Perl::Critic::Utils::is_function_call($elem)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq "sysseek" || $elem eq "CORE::sysseek"
!ll&&!rl&&r
000
$elem eq "sysseek" or $elem eq "CORE::sysseek"
l!l&&r!l&&!r
000
MC/DC0%0/4
$elem->isa("PPI::Token::Word") and $elem eq "sysseek" || $elem eq "CORE::sysseek" and Perl::Critic::Utils::is_function_call($elem)
$elem->isa("PPI::Token::Word") $elem eq "sysseek" $elem eq "CORE::sysseek" Perl::Critic::Utils::is_function_call($elem)
Truth table0%0/6
A and B or C and D
A= $elem->isa("PPI::Token::Word")B= $elem eq "sysseek"C= $elem eq "CORE::sysseek"D= Perl::Critic::Utils::is_function_call($elem)
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
757 && ($elem eq 'sysseek' || $elem eq 'CORE::sysseek')
758 && Perl::Critic::Utils::is_function_call ($elem)) {
759 0 return 1;
760 } else {
761 0 return 0;
762 }
763 0 });
764 }
765  
766  
767 #---------------------------------------------------------------------------
768 # UNIVERSAL.pm methods
769 #
770 {
771 40 my $methods = { VERSION => 1,
772 isa => 1,
773 can => 1 };
774 sub Perl::MinimumVersion::_Pulp__UNIVERSAL_methods_5004 {
775 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__UNIVERSAL_methods_5004: not called CC=1 SCAR=6.9
776 ### _Pulp__UNIVERSAL_methods_5004() ...
777 0 return _any_method($pmv,$methods);
778 }
779 }
780 {
781 40 my $methods = { DOES => 1 };
782 sub Perl::MinimumVersion::_Pulp__UNIVERSAL_methods_5010 {
783 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__UNIVERSAL_methods_5010: not called CC=1 SCAR=6.9
784 ### _Pulp__UNIVERSAL_methods_5010() ...
785 0 return _any_method($pmv,$methods);
786 }
787 }
788 40 sub _any_method {
789 0 ▶ my ($pmv, $hash) = @_;
Subroutine _any_method: not called CC=1 SCAR=6.9
790 $pmv->Document->find_first
791 (sub {
792 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
793 0 ▶ if ($elem->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::Word') and $hash->{$elem} and Perl::Critic::Utils::is_method_call($elem)) { } 0 0 0
Condition0%0/6
$elem->isa("PPI::Token::Word") and $hash->{$elem} and Perl::Critic::Utils::is_method_call($elem)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $hash->{$elem}
!ll&&!rl&&r
000
MC/DC0%0/3
$elem->isa("PPI::Token::Word") and $hash->{$elem} and Perl::Critic::Utils::is_method_call($elem)
$elem->isa("PPI::Token::Word") $hash->{$elem} Perl::Critic::Utils::is_method_call($elem)
Truth table0%0/4
A and B and C
A= $elem->isa("PPI::Token::Word")B= $hash->{$elem}C= Perl::Critic::Utils::is_method_call($elem)
ABCresult
0XX0
10X0
1100
1111
794 && $hash->{$elem}
795 && Perl::Critic::Utils::is_method_call ($elem)) {
796 0 return 1;
797 } else {
798 0 return 0;
799 }
800 0 });
801 }
802  
803  
804 #------------------------------------------------------------------------------
805 # keys @foo, values @foo, each @foo new in 5.12.0
806 #
807 sub Perl::MinimumVersion::_Pulp__keys_of_array {
808 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__keys_of_array: not called CC=1 SCAR=6.9
809 0 return _keys_etc_of_array ($pmv, 'keys');
810 }
811 sub Perl::MinimumVersion::_Pulp__values_of_array {
812 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__values_of_array: not called CC=1 SCAR=6.9
813 0 return _keys_etc_of_array ($pmv, 'values');
814 }
815 sub Perl::MinimumVersion::_Pulp__each_of_array {
816 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__each_of_array: not called CC=1 SCAR=6.9
817 0 return _keys_etc_of_array ($pmv, 'each');
818 }
819 sub _keys_etc_of_array {
820 0 ▶ my ($pmv, $which) = @_;
Subroutine _keys_etc_of_array: not called CC=1 SCAR=6.9
821 ### _keys_etc_of_array() ...
822 $pmv->Document->find_first
823 (sub {
824 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=5 SCAR=34.0
825 0 ▶ if ($elem->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::Word') and $elem eq $which and Perl::Critic::Utils::is_function_call($elem) and _arg_is_array($elem->snext_sibling)) { } 0 0 0
Condition0%0/9
$elem->isa("PPI::Token::Word") and $elem eq $which and Perl::Critic::Utils::is_function_call($elem) and _arg_is_array($elem->snext_sibling)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq $which and Perl::Critic::Utils::is_function_call($elem)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq $which
!ll&&!rl&&r
000
MC/DC0%0/4
$elem->isa("PPI::Token::Word") and $elem eq $which and Perl::Critic::Utils::is_function_call($elem) and _arg_is_array($elem->snext_sibling)
$elem->isa("PPI::Token::Word") $elem eq $which Perl::Critic::Utils::is_function_call($elem) _arg_is_array($elem->snext_sibling)
Truth table0%0/5
A and B and C and D
A= $elem->isa("PPI::Token::Word")B= $elem eq $whichC= Perl::Critic::Utils::is_function_call($elem)D= _arg_is_array($elem->snext_sibling)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
826 && $elem eq $which
827 && Perl::Critic::Utils::is_function_call($elem)
828 && _arg_is_array($elem->snext_sibling)) {
829 0 return 1;
830 } else {
831 0 return 0;
832 }
833 0 });
834 }
835 sub _arg_is_array {
836 0 ▶ my ($elem) = @_;
Subroutine _arg_is_array: not called CC=6 SCAR=37.4
837 ### _arg_is_array "$elem"
838  
839 0 ▶ $elem = _descend_through_lists($elem) || return 0;
Condition0%0/2
_descend_through_lists($elem) || (return 0)
l!l
00
MC/DC0%0/1
_descend_through_lists($elem) || (return 0)
_descend_through_lists($elem)
Truth table0%0/2
A
A= _descend_through_lists($elem)
Aresult
11
00
840  
841 0 ▶ if ($elem->isa('PPI::Token::Symbol')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Symbol") and $elem->raw_type eq "\@") 0 0 0
Condition0%0/3
$elem->isa("PPI::Token::Symbol") and $elem->raw_type eq "\@"
!ll&&!rl&&r
000
MC/DC0%0/2
$elem->isa("PPI::Token::Symbol") and $elem->raw_type eq "\@"
$elem->isa("PPI::Token::Symbol") $elem->raw_type eq "\@"
Truth table0%0/3
A and B
A= $elem->isa("PPI::Token::Symbol")B= $elem->raw_type eq "\@"
ABresult
0X0
100
111
842 && $elem->raw_type eq '@') {
843 0 return 1;
844 }
845 0 ▶ if ($elem->isa('PPI::Token::Cast') && $elem eq '@') {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Cast") and $elem eq "\@") 0 0 0
Condition0%0/3
$elem->isa("PPI::Token::Cast") and $elem eq "\@"
!ll&&!rl&&r
000
MC/DC0%0/2
$elem->isa("PPI::Token::Cast") and $elem eq "\@"
$elem->isa("PPI::Token::Cast") $elem eq "\@"
Truth table0%0/3
A and B
A= $elem->isa("PPI::Token::Cast")B= $elem eq "\@"
ABresult
0X0
100
111
846 0 return 1;
847 }
848 0 return 0;
849 }
850  
851  
852 #------------------------------------------------------------------------------
853 # eval '#line ...' with the #line the very first thing,
854 # the #line doesn't take effect until 5.008,
855 # in 5.006 need a blank line or something first
856  
857 {
858 40 my $initial_line_re = qr/^#[ \t]*line/;
859  
860 sub Perl::MinimumVersion::_Pulp__eval_line_directive_first_thing {
861 0 ▶ my ($pmv) = @_;
Subroutine _Pulp__eval_line_directive_first_thing: not called CC=1 SCAR=6.9
862 ### _Pulp__eval_line_directive_first_thing() ...
863 $pmv->Document->find_first
864 (sub {
865 0 ▶ my ($document, $elem) = @_;
Subroutine __ANON__: not called CC=10 SCAR=47.0
866 0 ▶ if ($elem->isa('PPI::Token::Word')
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Token::Word") and $elem eq "eval" and Perl::Critic::Utils::is_function_call($elem) and $elem = $elem->snext_sibling and $elem = _descend_through_lists($elem)) 0 0 0
Condition0%0/12
$elem->isa("PPI::Token::Word") and $elem eq "eval" and Perl::Critic::Utils::is_function_call($elem) and $elem = $elem->snext_sibling and $elem = _descend_through_lists($elem)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq "eval" and Perl::Critic::Utils::is_function_call($elem) and $elem = $elem->snext_sibling
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq "eval" and Perl::Critic::Utils::is_function_call($elem)
!ll&&!rl&&r
000
$elem->isa("PPI::Token::Word") and $elem eq "eval"
!ll&&!rl&&r
000
MC/DC0%0/5
$elem->isa("PPI::Token::Word") and $elem eq "eval" and Perl::Critic::Utils::is_function_call($elem) and $elem = $elem->snext_sibling and $elem = _descend_through_lists($elem)
$elem->isa("PPI::Token::Word") $elem eq "eval" Perl::Critic::Utils::is_function_call($elem) $elem = $elem->snext_sibling $elem = _descend_through_lists($elem)
Truth table0%0/6
A and B and C and D and E
A= $elem->isa("PPI::Token::Word")B= $elem eq "eval"C= Perl::Critic::Utils::is_function_call($elem)D= $elem = $elem->snext_siblingE= $elem = _descend_through_lists($elem)
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
867 && $elem eq 'eval'
868 && Perl::Critic::Utils::is_function_call($elem)
869 && ($elem = $elem->snext_sibling)
870 && ($elem = _descend_through_lists($elem))) {
871 ### eval of: "$elem"
872  
873 0 ▶ if ($elem->isa('PPI::Token::Quote')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($elem->isa('PPI::Token::Quote')) { } 0 0 0
elsif ($elem->isa('PPI::Token::HereDoc')) { } 0 0 0
874 0 ▶ if ($elem->string =~ $initial_line_re) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->string =~ /$initial_line_re/) 0 0 0
875 0 return 1;
876 }
877 } elsif ($elem->isa('PPI::Token::HereDoc')) {
878 0 my ($str) = $elem->heredoc; # first line
879 0 ▶ if ($str =~ $initial_line_re) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /$initial_line_re/) 0 0 0
880 0 return 1;
881 }
882 }
883 }
884 0 return 0;
885 0 });
886 }
887 }
888  
889  
890 #---------------------------------------------------------------------------
891 # generic
892  
893 # if $elem is a symbol or a List of a symbol then return that symbol elem,
894 # otherwise return an empty list
895 #
896 40 sub _symbol_or_list_symbol {
897 0 ▶ my ($elem) = @_;
Subroutine _symbol_or_list_symbol: not called CC=6 SCAR=37.4
898 0 ▶ if ($elem->isa('PPI::Structure::List')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("PPI::Structure::List")) 0 0 0
899 0 ▶ $elem = $elem->schild(0) || return;
Condition0%0/2
$elem->schild(0) || (return)
l!l
00
MC/DC0%0/1
$elem->schild(0) || (return)
$elem->schild(0)
Truth table0%0/2
A
A= $elem->schild(0)
Aresult
11
00
900 0 ▶ $elem->isa('PPI::Statement::Expression') || return;
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Statement::Expression") or return 0 0 0
901 0 ▶ $elem = $elem->schild(0) || return;
Condition0%0/2
$elem->schild(0) || (return)
l!l
00
MC/DC0%0/1
$elem->schild(0) || (return)
$elem->schild(0)
Truth table0%0/2
A
A= $elem->schild(0)
Aresult
11
00
902 }
903 0 ▶ $elem->isa('PPI::Token::Symbol') || return;
Branch: 1 branch
BranchTrueFalseTotal
$elem->isa("PPI::Token::Symbol") or return 0 0 0
904 0 return $elem;
905 }
906  
907  
908 #---------------------------------------------------------------------------
909  
910 40 1;
911 __END__
912  
913 =for stopwords config MinimumVersion Pragma CPAN prereq multi-constant concats pragma endianness filehandle asciz builtin Ryde no-args parens BER lexically-scoped
914  
915 =head1 NAME
916  
917 Perl::Critic::Policy::Compatibility::PerlMinimumVersionAndWhy - explicit Perl version for features used
918  
919 =head1 DESCRIPTION
920  
921 This policy is part of the L<C<Perl::Critic::Pulp>|Perl::Critic::Pulp>
922 add-on. It requires that you have an explicit C<use 5.XXX> etc for the Perl
923 syntax features you use, as determined by
924 L<C<Perl::MinimumVersion>|Perl::MinimumVersion>.
925  
926 use 5.010; # the // operator is new in perl 5.010
927 print $x // $y; # ok
928  
929 If you don't have the C<Perl::MinimumVersion> module then nothing is
930 reported. Certain nasty hacks are used to extract reasons and locations
931 from C<Perl::MinimumVersion>.
932  
933 This policy is under the "compatibility" theme (see L<Perl::Critic/POLICY
934 THEMES>). Its best use is when it picks up things like C<//> or C<qr> which
935 are only available in a newer Perl than you meant to target.
936  
937 An explicit C<use 5.xxx> can be a little tedious, but has the advantage of
938 making it clear what's needed (or supposed to be needed) and it gives a good
939 error message if run on an older Perl.
940  
941 =head2 Disabling
942
943 The config options below let you limit how far back to go. Or if you don't
944 care at all about this sort of thing you can always disable the policy
945 completely from your F<~/.perlcriticrc> file in the usual way (see
946 L<Perl::Critic/CONFIGURATION>),
947  
948 [-Compatibility::PerlMinimumVersionAndWhy]
949  
950 =head2 MinimumVersion Mangling
951  
952 Some mangling is applied to what C<Perl::MinimumVersion> normally reports
953 (as of its version 1.28).
954  
955 =over 4
956  
957 =item *
958  
959 A multi-constant hash with the L<C<constant>|constant> module is not
960 reported, since that's covered better by
961 L<Compatibility::ConstantPragmaHash|Perl::Critic::Policy::Compatibility::ConstantPragmaHash>.
962  
963 =item *
964  
965 Module requirements for things like C<use Errno> are dropped, since you
966 might get a back-port from CPAN etc and the need for a module is better
967 expressed in a distribution "prereq".
968  
969 But pragma modules like C<use warnings> are still reported. They're
970 normally an interface to a feature new in the Perl version it comes with and
971 can't be back-ported. (See L</OTHER NOTES> below too.)
972  
973 =back
974  
975 =head2 MinimumVersion Extras
976  
977 The following extra checks are added to C<Perl::MinimumVersion>.
978  
979 =over
980  
981 =item 5.12 for
982  
983 =over
984  
985 =item *
986  
987 new C<keys @array>, C<values @array> and C<each @array>
988  
989 =back
990  
991 =item 5.10 for
992  
993 =over
994  
995 =item *
996  
997 C<qr//m>, since "m" modifier doesn't propagate correctly on a C<qr> until
998 5.10
999  
1000 =item *
1001  
1002 C<-e -f -x> stacked filetest operators.
1003  
1004 =item *
1005  
1006 C<pack()> new C<E<lt>> and C<E<gt>> endianness.
1007  
1008 =item *
1009  
1010 new C<UNIVERSAL.pm> method C<DOES()>
1011  
1012 =back
1013  
1014 =item 5.8 for
1015  
1016 =over
1017  
1018 =item *
1019  
1020 new C<word [newline] =E<gt>> fat comma quoting across a newline
1021  
1022 For earlier Perl C<word> ended up a function call. It's presumed such code
1023 is meant to quote in the 5.8 style, and thus requires 5.8 or higher.
1024  
1025 =item *
1026  
1027 C<eval '#line ...'> with C<#line> the very first thing
1028  
1029 In earlier Perl a C<#line> as the very first thing in an C<eval> doesn't
1030 take effect. Adding a blank line so it's not first is enough.
1031  
1032 =item *
1033  
1034 C<pack()> new C<F> native NV, C<D> long double, C<i> IV, C<j> UV, C<()>
1035 group, C<[]> repeat count
1036  
1037 =back
1038  
1039 =item 5.6 for
1040  
1041 =over
1042  
1043 =item *
1044  
1045 new C<exists &subr>, C<exists $array[0]> and C<delete $array[0]>
1046  
1047 =item *
1048  
1049 new C<0b110011> binary number literals
1050  
1051 =item *
1052  
1053 new C<open(my $fh,...)> etc auto-creation of filehandle
1054  
1055 =item *
1056  
1057 C<syswrite()> length parameter optional
1058  
1059 =item *
1060  
1061 C<Foo-E<gt>$method> no-args call without parens
1062  
1063 For earlier Perl a no-args call to a method named in a variable must be
1064 C<Foo-E<gt>$method()>. The parens are optional in 5.6 up.
1065  
1066 =item *
1067  
1068 C<pack()> new C<Z> asciz, C<q>,C<Q> quads, C<!> native size, C</> counted
1069 string, C<#> comment
1070  
1071 =back
1072  
1073 =item 5.005 for
1074  
1075 =over
1076  
1077 =item *
1078  
1079 new C<Foo::Bar::> double-colon package name quoting
1080  
1081 =item *
1082  
1083 new C<my ($x, undef, $y) = @values>, using C<undef> as a dummy in a C<my>
1084 list
1085  
1086 =back
1087  
1088 =item 5.004 for
1089  
1090 =over
1091  
1092 =item *
1093  
1094 new C<use 5.xxx> Perl version check through C<use>. For earlier Perl it can
1095 be C<BEGIN { require 5.000 }> etc
1096  
1097 =item *
1098  
1099 new C<__PACKAGE__> special literal
1100  
1101 =item *
1102  
1103 new C<foreach my $foo> lexical loop variable
1104  
1105 =item *
1106  
1107 new C<$coderef-E<gt>()> call with C<-E<gt>>
1108  
1109 =item *
1110  
1111 new C<sysseek()> builtin function
1112  
1113 =item *
1114  
1115 C<pack()> new C<w> BER integer
1116  
1117 =item *
1118  
1119 new C<UNIVERSAL.pm> with C<VERSION()>, C<isa()> and C<can()> methods
1120  
1121 =back
1122  
1123 =back
1124  
1125 C<pack()> and C<unpack()> format strings are only checked if they're literal
1126 strings or here-documents without interpolations, or C<.> operator concats
1127 of those.
1128  
1129 The C<qr//m> report concerns a misfeature fixed in perl 5.10.0 (see
1130 L<perl5101delta>). In earlier versions a regexp like C<$re = qr/^x/m>
1131 within another regexp like C</zz|$re/> loses the C</m> attribute from
1132 C<$re>, changing the interpretation of the C<^> (and C<$> similarly). Forms
1133 like C<(\A|\n)> are a possible workaround, though are uncommon so may be a
1134 little obscure. C<RegularExpressions::RequireLineBoundaryMatching> asks for
1135 C</m> in all cases so if think you want that then you probably want Perl
1136 5.10 or up for the fix too.
1137  
1138 =head2 C<Modern::Perl>
1139  
1140 C<use Modern::Perl> is taken to mean Perl 5.10. This is slightly
1141 experimental and in principle the actual minimum it implies is forever
1142 rising, and even now could be more, or depends on it date argument scheme.
1143 Maybe if could say its actual current desire then an installed version could
1144 be queried.
1145  
1146 =head1 CONFIGURATION
1147  
1148 =over 4
1149  
1150 =item C<above_version> (version string, default none)
1151  
1152 Set a minimum version of Perl you always use, so that reports are only about
1153 things higher than this and higher than what the document declares. The
1154 value is anything the L<C<version.pm>|version> module can parse.
1155  
1156 [Compatibility::PerlMinimumVersionAndWhy]
1157 above_version = 5.006
1158  
1159 For example if you always use Perl 5.6 and set 5.006 like this then you can
1160 have C<our> package variables without an explicit C<use 5.006>.
1161  
1162 =item C<skip_checks> (list of check names, default none)
1163  
1164 Skip the given MinimumVersion checks (a space separated list). The check
1165 names are shown in the violation message and come from
1166 C<Perl::MinimumVersion::CHECKS>. For example,
1167  
1168 [Compatibility::PerlMinimumVersionAndWhy]
1169 skip_checks = _some_thing _another_thing
1170  
1171 This can be used for checks you believe are wrong, or where the
1172 compatibility matter only affects limited circumstances which you
1173 understand.
1174  
1175 The check names are likely to be a moving target, especially the Pulp
1176 additions. Unknown checks in the list are quietly ignored.
1177  
1178 =back
1179  
1180 =head1 OTHER NOTES
1181  
1182 C<use warnings> is reported as a Perl 5.6 feature since the lexically-scoped
1183 fine grain warnings control it gives is new in that version. If targeting
1184 earlier versions then it's often enough to drop C<use warnings>, ensure your
1185 code runs cleanly under S<< C<perl -w> >>, and leave it to applications to
1186 use C<-w> (or set C<$^W>) if they desire.
1187  
1188 C<warnings::compat> offers a C<use warnings> for earlier Perl, but it's not
1189 lexical, instead setting C<$^W> globally. In a script this might be an
1190 alternative to S<C<#!/usr/bin/perl -w>> (per L<perlrun>), but in a module
1191 it's probably not a good idea to change global settings.
1192  
1193 The C<UNIVERSAL.pm> methods C<VERSION()>, C<isa()>, C<can()> or C<DOES()>
1194 might in principle be implemented explicitly by a particular class, but it's
1195 assumed that's not so and that any call to those requires the respective
1196 minimum Perl version.
1197  
1198 =head1 SEE ALSO
1199  
1200 L<Perl::Critic::Pulp>,
1201 L<Perl::Critic>
1202  
1203 L<Perl::Critic::Policy::Modules::PerlMinimumVersion>, which is similar, but
1204 compares against a Perl version configured in your F<~/.perlcriticrc> rather
1205 than a version in the document.
1206  
1207 L<Perl::Critic::Policy::Modules::RequirePerlVersion>
1208  
1209 =head1 HOME PAGE
1210  
1211 L<http://user42.tuxfamily.org/perl-critic-pulp/index.html>
1212  
1213 =head1 COPYRIGHT
1214  
1215 Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 Kevin Ryde
1216  
1217 Perl-Critic-Pulp is free software; you can redistribute it and/or modify it
1218 under the terms of the GNU General Public License as published by the Free
1219 Software Foundation; either version 3, or (at your option) any later
1220 version.
1221  
1222 Perl-Critic-Pulp is distributed in the hope that it will be useful, but
1223 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1224 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1225 more details.
1226  
1227 You should have received a copy of the GNU General Public License along with
1228 Perl-Critic-Pulp. If not, see <http://www.gnu.org/licenses/>.
1229  
1230 =cut
↑ Summary Policy/CodeLayout/RequireFinalSemicolon.pm »