lib/Perl/Critic/Policy/ValuesAndExpressions/RequireConstantVersion.pm

filter: Statementstmt 55.3% 57 / 103 Branchbran 18.7% 15 / 80 Conditioncond 1.6% 1 / 60 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 83.3% 15 / 18 Podpod 80.0% 4 / 5 totaltotal 31.5% 92 / 292 CC 61 SCAR 50.4
CC
61
Cov
30%
_validate_operator_bind_regex
365.5
_validate_word_version
240.0
_validate_word_qv
90.0
CRAP 154.5
« lib/Perl/Critic/Policy/RegularExpressions/ProhibitCaptureWithoutTest.pm ↑ Summary lib/Perl/Critic/Policy/Subroutines/ProhibitAmpersandSigils.pm »
1 package Perl::Critic::Policy::ValuesAndExpressions::RequireConstantVersion;
2  
3 40 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 40 ▶use Perl::Critic::Utils qw<
Subroutine BEGIN: called CC=1 SCAR=0.0
8 :booleans :characters :classification :data_conversion :language
9 :severities
10 40 >;
11 40 ▶use Perl::Critic::Utils::PPI qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
12 is_ppi_constant_element
13 get_next_element_in_same_simple_statement
14 get_previous_module_used_on_same_line
15 40 };
16 40 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 40 ▶use parent 'Perl::Critic::Policy';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 40 our $VERSION = '1.156';
21  
22 #-----------------------------------------------------------------------------
23  
24 40 Readonly::Scalar my $BIND_REGEX => q<=~>;
25 40 Readonly::Scalar my $DOLLAR => q<$>;
26 # All uses of the $DOLLAR variable below are to prevent false failures in
27 # xt/93_version.t.
28 40 Readonly::Scalar my $QV => q<qv>;
29 40 Readonly::Scalar my $VERSION_MODULE => q<version>;
30 40 Readonly::Scalar my $VERSION_VARIABLE => $DOLLAR . q<VERSION>;
31  
32 # Operators which would make a new value our of our $VERSION, and therefore
33 # not modify it. I'm sure this list is not exhaustive. The logical operators
34 # generally do not qualify for this list. At least, I think not.
35 40 Readonly::Hash my %OPERATOR_WHICH_MAKES_NEW_VALUE => hashify( qw{
36 = . + - * ** / % ^ ~ & | > < == != >= <= eq ne gt lt ge le
37 } );
38  
39 40 Readonly::Scalar my $DESC => $DOLLAR . q<VERSION value must be a constant>;
40 40 Readonly::Scalar my $EXPL => qq<Computed ${DOLLAR}VERSION may tie the code to a single repository, or cause spooky action from a distance>;
41  
42 #-----------------------------------------------------------------------------
43  
44 91 ▶sub supported_parameters { return (
Subroutine supported_parameters: called CC=1 SCAR=0.0
Pod undocumented
45 {
46 91 name => 'allow_version_without_use_on_same_line',
47 description =>
48 q{Allow qv() and version->new() without a 'use version' on the same line.},
49 default_string => $FALSE,
50 behavior => 'boolean',
51 }
52 );
53 }
54 74 ▶sub default_severity { return $SEVERITY_LOW }
Subroutine default_severity: called CC=1 SCAR=0.0
Pod documented
55 73 ▶sub default_themes { return qw( core maintenance ) }
Subroutine default_themes: called CC=1 SCAR=0.0
Pod documented
56 31 ▶sub applies_to { return 'PPI::Token::Symbol' }
Subroutine applies_to: called CC=1 SCAR=0.0
Pod documented
57  
58 #-----------------------------------------------------------------------------
59  
60 173 ▶sub violates {
Subroutine violates: called CC=12 SCAR=27.8
Pod documented
61 173 my ( $self, $elem, undef ) = @_;
62  
63 # Any variable other than $VERSION is ignored.
64 173 ▶ return if $VERSION_VARIABLE ne $elem->content();
Branch: 1 branch
BranchTrueFalseTotal
if $VERSION_VARIABLE ne $elem->content 146 27 173
65  
66 # Get the next thing (presumably an operator) after $VERSION. The $VERSION
67 # might be in a list, so if we get nothing we move upwards until we hit a
68 # simple statement. If we have nothing at this point, we do not understand
69 # the code, and so we return.
70 27 my $operator;
71 return if
72 27 ▶ not $operator = get_next_element_in_same_simple_statement( $elem );
Branch: 1 branch
BranchTrueFalseTotal
unless $operator = get_next_element_in_same_simple_statement($elem) 0 27 27
73  
74 # If the next operator is a regex binding, and its other operand is a
75 # substitution operator, it is an attempt to modify $VERSION, so we
76 # return an error to that effect.
77 27 ▶ return $self->violation( $DESC, $EXPL, $elem )
Branch: 1 branch
BranchTrueFalseTotal
if _validate_operator_bind_regex($operator, $elem) 0 27 27
78 if _validate_operator_bind_regex( $operator, $elem );
79  
80 # If the presumptive operator is not an assignment operator of some sort,
81 # we are not modifying $VERSION at all, and so we just return.
82 27 ▶ return if not $operator = _check_for_assignment_operator( $operator );
Branch: 1 branch
BranchTrueFalseTotal
unless $operator = _check_for_assignment_operator($operator) 0 27 27
83  
84 # If there is no operand to the right of the assignment, we do not
85 # understand the code; simply return.
86 27 my $value;
87 27 ▶ return if not $value = $operator->snext_sibling();
Branch: 1 branch
BranchTrueFalseTotal
unless $value = $operator->snext_sibling 0 27 27
88  
89 # If the value is symbol '$VERSION', just return as we will see it again
90 # later.
91 return if
92 27 ▶ $value->isa( 'PPI::Token::Symbol' )
Branch: 1 branch
BranchTrueFalseTotal
if $value->isa("PPI::Token::Symbol") and $value->content eq $VERSION_VARIABLE 0 27 27
Condition33%1/3
$value->isa("PPI::Token::Symbol") and $value->content eq $VERSION_VARIABLE
!ll&&!rl&&r
2700
MC/DC0%0/2
$value->isa("PPI::Token::Symbol") and $value->content eq $VERSION_VARIABLE
$value->isa("PPI::Token::Symbol") $value->content eq $VERSION_VARIABLE
Truth table33%1/3
A and B
A= $value->isa("PPI::Token::Symbol")B= $value->content eq $VERSION_VARIABLE
ABresult
0X0
100
111
93 and $value->content() eq $VERSION_VARIABLE;
94  
95 # If the value is a word, there are a number of acceptable things it could
96 # be. Check for these. If there was a problem, return it.
97 27 $value = $self->_validate_word_token( $elem, $value );
98 27 ▶ return $value if $value->isa( 'Perl::Critic::Exception' );
Branch: 1 branch
BranchTrueFalseTotal
if $value->isa("Perl::Critic::Exception") 0 27 27
99  
100 # If the value is anything but a constant, we cry foul.
101 27 ▶ return $self->violation( $DESC, $EXPL, $elem )
Branch: 1 branch
BranchTrueFalseTotal
unless is_ppi_constant_element($value) 0 27 27
102 if not is_ppi_constant_element( $value );
103  
104 # If we have nothing after the value, it is OK.
105 27 my $structure;
106 return if
107 27 ▶ not $structure = get_next_element_in_same_simple_statement( $value );
Branch: 1 branch
BranchTrueFalseTotal
unless $structure = get_next_element_in_same_simple_statement($value) 0 27 27
108  
109 # If we have a semicolon after the value, it is OK.
110 27 ▶ return if $SCOLON eq $structure->content();
Branch: 1 branch
BranchTrueFalseTotal
if $Perl::Critic::Policy::ValuesAndExpressions::RequireConstantVersion::SCOLON eq $structure->content 27 0 27
111  
112 # If there is anything else after the value, we cry foul.
113 0 return $self->violation( $DESC, $EXPL, $elem );
114 }
115  
116 #-----------------------------------------------------------------------------
117  
118 # Check if the element is an assignment operator.
119  
120 27 ▶sub _check_for_assignment_operator {
Subroutine _check_for_assignment_operator: called CC=3 SCAR=12.5
121 27 my ( $operator ) = @_;
122  
123 27 ▶ return if not $operator->isa( 'PPI::Token::Operator' );
Branch: 1 branch
BranchTrueFalseTotal
unless $operator->isa("PPI::Token::Operator") 0 27 27
124 27 ▶ return $operator if is_assignment_operator($operator->content());
Branch: 1 branch
BranchTrueFalseTotal
if is_assignment_operator($operator->content) 27 0 27
125 0 return;
126 }
127  
128 #-----------------------------------------------------------------------------
129  
130 # Validate a bind_regex ('=~') operator appearing after $VERSION. We return
131 # true if the operator is in fact '=~', and its next sibling isa
132 # PPI::Token::Regexp::Substitute. Otherwise we return false.
133  
134 27 ▶sub _validate_operator_bind_regex {
Subroutine _validate_operator_bind_regex: called CC=20 SCAR=59.0
135 27 my ( $operator, $elem ) = @_;
136  
137 # We are not interested in anything but '=~ s/../../'.
138 27 ▶ return if $BIND_REGEX ne $operator->content();
Branch: 1 branch
BranchTrueFalseTotal
if $BIND_REGEX ne $operator->content 27 0 27
139 0 my $operand;
140 0 ▶ return if not $operand = $operator->snext_sibling();
Branch: 1 branch
BranchTrueFalseTotal
unless $operand = $operator->snext_sibling 0 0 0
141 0 ▶ return if not $operand->isa( 'PPI::Token::Regexp::Substitute' );
Branch: 1 branch
BranchTrueFalseTotal
unless $operand->isa("PPI::Token::Regexp::Substitute") 0 0 0
142  
143 # The substitution is OK if it is of the form
144 # '($var = $VERSION) =~ s/../../'.
145  
146 # We can't look like the desired form if we have a next sig. sib.
147 0 ▶ return $TRUE if $elem->snext_sibling();
Branch: 1 branch
BranchTrueFalseTotal
if $elem->snext_sibling 0 0 0
148  
149 # We can't look like the desired form if we are not in a list.
150 0 my $containing_list;
151 0 ▶ $containing_list = $elem->parent()
Branch: 1 branch
BranchTrueFalseTotal
$containing_list = $elem->parent and $containing_list->isa("PPI::Statement") and $containing_list = $containing_list->parent and $containing_list->isa("PPI::Structure::List") or return $Perl::Critic::Policy::ValuesAndExpressions::RequireConstantVersion::TRUE 0 0 0
Condition0%0/9
$containing_list = $elem->parent and $containing_list->isa("PPI::Statement") and $containing_list = $containing_list->parent and $containing_list->isa("PPI::Structure::List")
!ll&&!rl&&r
000
$containing_list = $elem->parent and $containing_list->isa("PPI::Statement") and $containing_list = $containing_list->parent
!ll&&!rl&&r
000
$containing_list = $elem->parent and $containing_list->isa("PPI::Statement")
!ll&&!rl&&r
000
MC/DC0%0/4
$containing_list = $elem->parent and $containing_list->isa("PPI::Statement") and $containing_list = $containing_list->parent and $containing_list->isa("PPI::Structure::List")
$containing_list = $elem->parent $containing_list->isa("PPI::Statement") $containing_list = $containing_list->parent $containing_list->isa("PPI::Structure::List")
Truth table0%0/5
A and B and C and D
A= $containing_list = $elem->parentB= $containing_list->isa("PPI::Statement")C= $containing_list = $containing_list->parentD= $containing_list->isa("PPI::Structure::List")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
152 and $containing_list->isa( 'PPI::Statement' )
153 and $containing_list = $containing_list->parent()
154 and $containing_list->isa( 'PPI::Structure::List' )
155 or return $TRUE;
156  
157 # If we have no prior element, we're ( $VERSION ) =~ s/../../,
158 # which flunks.
159 0 ▶ my $prior = $elem->sprevious_sibling() or return $TRUE;
Branch: 1 branch
BranchTrueFalseTotal
my $prior = $elem->sprevious_sibling or return $Perl::Critic::Policy::ValuesAndExpressions::RequireConstantVersion::TRUE 0 0 0
160  
161 # If the prior element is an operator which makes a new value, we pass.
162 return if $prior->isa( 'PPI::Token::Operator' )
163 0 ▶ && $OPERATOR_WHICH_MAKES_NEW_VALUE{ $prior->content() };
Branch: 1 branch
BranchTrueFalseTotal
if $prior->isa("PPI::Token::Operator") and $OPERATOR_WHICH_MAKES_NEW_VALUE{$prior->content} 0 0 0
Condition0%0/3
$prior->isa("PPI::Token::Operator") and $OPERATOR_WHICH_MAKES_NEW_VALUE{$prior->content}
!ll&&!rl&&r
000
MC/DC0%0/2
$prior->isa("PPI::Token::Operator") and $OPERATOR_WHICH_MAKES_NEW_VALUE{$prior->content}
$prior->isa("PPI::Token::Operator") $OPERATOR_WHICH_MAKES_NEW_VALUE{$prior->content}
Truth table0%0/3
A and B
A= $prior->isa("PPI::Token::Operator")B= $OPERATOR_WHICH_MAKES_NEW_VALUE{$prior->content}
ABresult
0X0
100
111
164  
165 # Now things get complicated, as RT #55600 shows. We need to grub through
166 # the entire list, looking for something that looks like a subroutine
167 # call, but without parens around the argument list. This catches the
168 # ticket's case, which was
169 # ( $foo = sprintf '%s/%s', __PACKAGE__, $VERSION ) =~ s/../../.
170 0 my $current = $prior;
171 0 ▶ while( $prior = $current->sprevious_sibling() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prior = $current->sprevious_sibling) 0 0 0
172 0 ▶ $prior->isa( 'PPI::Token::Word' ) or next;
Branch: 1 branch
BranchTrueFalseTotal
$prior->isa("PPI::Token::Word") or next 0 0 0
173 0 ▶ is_function_call( $prior) or next;
Branch: 1 branch
BranchTrueFalseTotal
is_function_call($prior) or next 0 0 0
174 # If this function has its own argument list, we need to keep looking;
175 # otherwise we have found a function with no parens, and we can
176 # return.
177 0 ▶ $current->isa( 'PPI::Structure::List' )
Branch: 1 branch
BranchTrueFalseTotal
$current->isa("PPI::Structure::List") or return 0 0 0
178 or return;
179 } continue {
180 0 $current = $prior;
181 }
182  
183 # Maybe the whole list was arguments for a subroutine or method call.
184 0 ▶ $prior = $containing_list->sprevious_sibling()
Branch: 1 branch
BranchTrueFalseTotal
$prior = $containing_list->sprevious_sibling or return $Perl::Critic::Policy::ValuesAndExpressions::RequireConstantVersion::TRUE 0 0 0
185 or return $TRUE;
186 0 ▶ if ( $prior->isa( 'PPI::Token::Word' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prior->isa("PPI::Token::Word")) 0 0 0
187 0 ▶ return if is_method_call( $prior );
Branch: 1 branch
BranchTrueFalseTotal
if is_method_call($prior) 0 0 0
188 0 ▶ return if is_function_call( $prior );
Branch: 1 branch
BranchTrueFalseTotal
if is_function_call($prior) 0 0 0
189 }
190  
191 # Anything left is presumed a violation.
192 0 return $TRUE;
193 }
194  
195 #-----------------------------------------------------------------------------
196  
197 # Validating a PPI::Token::Word is a complicated business, so we split it out
198 # into its own subroutine. The $elem is to be used in forming the error
199 # message, and the $value is the PPI::Token::Word we just encountered. The
200 # return is either a PPI::Element for further analysis, or a
201 # Perl::Critic::Exception to be returned.
202  
203 27 ▶sub _validate_word_token {
Subroutine _validate_word_token: called CC=5 SCAR=27.4
204 27 my ( $self, $elem, $value ) = @_;
205  
206 27 ▶ if ( $value->isa( 'PPI::Token::Word' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->isa("PPI::Token::Word")) 0 27 27
207 0 my $content = $value->content();
208  
209 # If the word is of the form 'v\d+' it may be the first portion of a
210 # misparsed (by PPI) v-string. It is really a v-string if the next
211 # element is a number. Unless v-strings are allowed, we return an
212 # error.
213 0 ▶ if ( $content =~ m/ \A v \d+ \z /smx ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($content =~ / \A v \d+ \z /msx) { } 0 0 0
elsif ($QV eq $content) { } 0 0 0
elsif ($VERSION_MODULE eq $content) { } 0 0 0
214 0 $value = $self->_validate_word_vstring( $elem, $value );
215 }
216 elsif ( $QV eq $content ) {
217 # If the word is 'qv' we suspect use of the version module. If
218 # 'use version' appears on the same line, _and_ the remainder of
219 # the expression is of the form '(value)', we extract the value
220 # for further analysis.
221  
222 0 $value = $self->_validate_word_qv( $elem, $value );
223 }
224 elsif ( $VERSION_MODULE eq $content ) {
225 # If the word is 'version' we suspect use of the version module.
226 # Check to see if it is properly used.
227 0 $value = $self->_validate_word_version( $elem, $value );
228 }
229 }
230  
231 27 return $value;
232 }
233  
234 #-----------------------------------------------------------------------------
235  
236 # Validate $VERSION = v1.2.3;
237 # Note that this is needed because PPI mis-parses the 'v1.2.3' construct into
238 # a word ('v1') and a number of some sort ('.2.3'). This method should only be
239 # called if it is already known that the $value is a PPI::Token::Word matching
240 # m/ \A v \d+ \z /smx;
241  
242 0 ▶sub _validate_word_vstring {
Subroutine _validate_word_vstring: not called CC=3 SCAR=24.8
243 0 my ( $self, $elem, $value ) = @_;
244  
245 # Check for the second part of the mis-parsed v-string, flunking if it is
246 # not found.
247 0 my $next;
248 0 ▶ return $self->violation( $DESC, $EXPL, $elem )
Branch: 1 branch
BranchTrueFalseTotal
unless $next = $value->snext_sibling and $next->isa("PPI::Token::Number") 0 0 0
Condition0%0/3
$next = $value->snext_sibling and $next->isa("PPI::Token::Number")
!ll&&!rl&&r
000
MC/DC0%0/2
$next = $value->snext_sibling and $next->isa("PPI::Token::Number")
$next = $value->snext_sibling $next->isa("PPI::Token::Number")
Truth table0%0/3
A and B
A= $next = $value->snext_siblingB= $next->isa("PPI::Token::Number")
ABresult
0X0
100
111
249 if
250 not $next = $value->snext_sibling()
251 or not $next->isa( 'PPI::Token::Number' );
252  
253 # Return the second part of the v-string for further analysis.
254 0 return $next;
255 }
256  
257 #-----------------------------------------------------------------------------
258  
259 # Validate $VERSION = qv();
260  
261 0 ▶sub _validate_word_qv {
Subroutine _validate_word_qv: not called CC=9 SCAR=45.0
262 0 my ( $self, $elem, $value ) = @_;
263  
264 # Unless we are specifically allowing this construction without the
265 # 'use version;' on the same line, check for it and flunk if we do not
266 # find it.
267 $self->{_allow_version_without_use_on_same_line}
268 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_allow_version_without_use_on_same_line"} or do { my $module; return $self->violation($DESC, $EXPL, $elem) unless $module = get_previous_module_used_on_same_line($value); return $self->violation($DESC, $EXPL, $elem) if $VERSION_MODULE ne $module->content } 0 0 0
269 0 my $module;
270 0 ▶ return $self->violation( $DESC, $EXPL, $elem )
Branch: 1 branch
BranchTrueFalseTotal
unless $module = get_previous_module_used_on_same_line($value) 0 0 0
271 if not
272 $module = get_previous_module_used_on_same_line($value);
273 0 ▶ return $self->violation( $DESC, $EXPL, $elem )
Branch: 1 branch
BranchTrueFalseTotal
if $VERSION_MODULE ne $module->content 0 0 0
274 if $VERSION_MODULE ne $module->content();
275 };
276  
277 # Dig out the first argument of 'qv()', flunking if we can not find it.
278 0 my $next;
279 0 ▶ return $self->violation( $DESC, $EXPL, $elem )
Branch: 1 branch
BranchTrueFalseTotal
unless $next = $value->snext_sibling and $next->isa("PPI::Structure::List") and $next = $next->schild(0) and $next->isa("PPI::Statement::Expression") and $next = $next->schild(0) 0 0 0
Condition0%0/12
$next = $value->snext_sibling and $next->isa("PPI::Structure::List") and $next = $next->schild(0) and $next->isa("PPI::Statement::Expression") and $next = $next->schild(0)
!ll&&!rl&&r
000
$next = $value->snext_sibling and $next->isa("PPI::Structure::List") and $next = $next->schild(0) and $next->isa("PPI::Statement::Expression")
!ll&&!rl&&r
000
$next = $value->snext_sibling and $next->isa("PPI::Structure::List") and $next = $next->schild(0)
!ll&&!rl&&r
000
$next = $value->snext_sibling and $next->isa("PPI::Structure::List")
!ll&&!rl&&r
000
MC/DC0%0/5
$next = $value->snext_sibling and $next->isa("PPI::Structure::List") and $next = $next->schild(0) and $next->isa("PPI::Statement::Expression") and $next = $next->schild(0)
$next = $value->snext_sibling $next->isa("PPI::Structure::List") $next = $next->schild(0) $next->isa("PPI::Statement::Expression") $next = $next->schild(0)
Truth table0%0/6
A and B and C and D and E
A= $next = $value->snext_siblingB= $next->isa("PPI::Structure::List")C= $next = $next->schild(0)D= $next->isa("PPI::Statement::Expression")E= $next = $next->schild(0)
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
280 if not (
281 $next = $value->snext_sibling()
282 and $next->isa( 'PPI::Structure::List' )
283 and $next = $next->schild( 0 )
284 and $next->isa( 'PPI::Statement::Expression' )
285 and $next = $next->schild( 0 )
286 );
287  
288 # Return the qv() argument for further analysis.
289 0 return $next;
290 }
291  
292 #-----------------------------------------------------------------------------
293  
294 # Validate $VERSION = version->new();
295  
296 # TODO: Fix this EVIL dual-purpose return value. This is ugggggleeeee.
297 0 ▶sub _validate_word_version {
Subroutine _validate_word_version: not called CC=15 SCAR=54.8
298 0 my ( $self, $elem, $value ) = @_;
299  
300 # Unless we are specifically allowing this construction without the
301 # 'use version;' on the same line, check for it and flunk if we do not
302 # find it.
303 $self->{_allow_version_without_use_on_same_line}
304 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_allow_version_without_use_on_same_line"} or do { my $module; return $self->violation($DESC, $EXPL, $elem) unless $module = get_previous_module_used_on_same_line($value); return $self->violation($DESC, $EXPL, $elem) if $VERSION_MODULE ne $module->content } 0 0 0
305 0 my $module;
306 0 ▶ return $self->violation( $DESC, $EXPL, $elem )
Branch: 1 branch
BranchTrueFalseTotal
unless $module = get_previous_module_used_on_same_line($value) 0 0 0
307 if not
308 $module = get_previous_module_used_on_same_line($value);
309 0 ▶ return $self->violation( $DESC, $EXPL, $elem )
Branch: 1 branch
BranchTrueFalseTotal
if $VERSION_MODULE ne $module->content 0 0 0
310 if $VERSION_MODULE ne $module->content();
311 };
312  
313 # Dig out the first argument of '->new()', flunking if we can not find it.
314 0 my $next;
315 0 ▶ return $next if
Branch: 1 branch
BranchTrueFalseTotal
if $next = $value->snext_sibling and $next->isa("PPI::Token::Operator") and "->" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Token::Word") and "new" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Structure::List") and $next = $next->schild(0) and $next->isa("PPI::Statement::Expression") and $next = $next->schild(0) 0 0 0
Condition0%0/30
$next = $value->snext_sibling and $next->isa("PPI::Token::Operator") and "->" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Token::Word") and "new" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Structure::List") and $next = $next->schild(0) and $next->isa("PPI::Statement::Expression") and $next = $next->schild(0)
!ll&&!rl&&r
000
$next = $value->snext_sibling and $next->isa("PPI::Token::Operator") and "->" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Token::Word") and "new" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Structure::List") and $next = $next->schild(0) and $next->isa("PPI::Statement::Expression")
!ll&&!rl&&r
000
$next = $value->snext_sibling and $next->isa("PPI::Token::Operator") and "->" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Token::Word") and "new" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Structure::List") and $next = $next->schild(0)
!ll&&!rl&&r
000
$next = $value->snext_sibling and $next->isa("PPI::Token::Operator") and "->" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Token::Word") and "new" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Structure::List")
!ll&&!rl&&r
000
$next = $value->snext_sibling and $next->isa("PPI::Token::Operator") and "->" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Token::Word") and "new" eq $next->content and $next = $next->snext_sibling
!ll&&!rl&&r
000
$next = $value->snext_sibling and $next->isa("PPI::Token::Operator") and "->" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Token::Word") and "new" eq $next->content
!ll&&!rl&&r
000
$next = $value->snext_sibling and $next->isa("PPI::Token::Operator") and "->" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Token::Word")
!ll&&!rl&&r
000
$next = $value->snext_sibling and $next->isa("PPI::Token::Operator") and "->" eq $next->content and $next = $next->snext_sibling
!ll&&!rl&&r
000
$next = $value->snext_sibling and $next->isa("PPI::Token::Operator") and "->" eq $next->content
!ll&&!rl&&r
000
$next = $value->snext_sibling and $next->isa("PPI::Token::Operator")
!ll&&!rl&&r
000
MC/DC0%0/11
$next = $value->snext_sibling and $next->isa("PPI::Token::Operator") and "->" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Token::Word") and "new" eq $next->content and $next = $next->snext_sibling and $next->isa("PPI::Structure::List") and $next = $next->schild(0) and $next->isa("PPI::Statement::Expression") and $next = $next->schild(0)
$next = $value->snext_sibling $next->isa("PPI::Token::Operator") "->" eq $next->content $next = $next->snext_sibling $next->isa("PPI::Token::Word") "new" eq $next->content $next = $next->snext_sibling $next->isa("PPI::Structure::List") $next = $next->schild(0) $next->isa("PPI::Statement::Expression") $next = $next->schild(0)
Truth table0%0/12
A and B and C and D and E and F and G and H and I and J and K
A= $next = $value->snext_siblingB= $next->isa("PPI::Token::Operator")C= "->" eq $next->contentD= $next = $next->snext_siblingE= $next->isa("PPI::Token::Word")F= "new" eq $next->contentG= $next = $next->snext_siblingH= $next->isa("PPI::Structure::List")I= $next = $next->schild(0)J= $next->isa("PPI::Statement::Expression")K= $next = $next->schild(0)
ABCDEFGHIJKresult
0XXXXXXXXXX0
10XXXXXXXXX0
110XXXXXXXX0
1110XXXXXXX0
11110XXXXXX0
111110XXXXX0
1111110XXXX0
11111110XXX0
111111110XX0
1111111110X0
111111111100
111111111111
316 $next = $value->snext_sibling()
317 and $next->isa( 'PPI::Token::Operator' )
318 and q{->} eq $next->content()
319 and $next = $next->snext_sibling()
320 and $next->isa( 'PPI::Token::Word' )
321 and q{new} eq $next->content()
322 and $next = $next->snext_sibling()
323 and $next->isa( 'PPI::Structure::List' )
324 and $next = $next->schild( 0 )
325 and $next->isa( 'PPI::Statement::Expression' )
326 and $next = $next->schild( 0 );
327  
328 0 return $self->violation( $DESC, $EXPL, $elem );
329 }
330  
331 40 1;
332  
333 __END__
« lib/Perl/Critic/Policy/RegularExpressions/ProhibitCaptureWithoutTest.pm ↑ Summary lib/Perl/Critic/Policy/Subroutines/ProhibitAmpersandSigils.pm »