line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# NOTE: This module is way too large. Please think about adding new |
2
|
|
|
|
|
|
|
# functionality into a P::C::Utils::* module instead. |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Perl::Critic::Utils; |
5
|
|
|
|
|
|
|
|
6
|
40
|
|
|
40
|
|
129209
|
use 5.010001; |
|
40
|
|
|
|
|
159
|
|
7
|
40
|
|
|
40
|
|
221
|
use strict; |
|
40
|
|
|
|
|
84
|
|
|
40
|
|
|
|
|
797
|
|
8
|
40
|
|
|
40
|
|
200
|
use warnings; |
|
40
|
|
|
|
|
90
|
|
|
40
|
|
|
|
|
1018
|
|
9
|
40
|
|
|
40
|
|
4443
|
use Readonly; |
|
40
|
|
|
|
|
32374
|
|
|
40
|
|
|
|
|
2268
|
|
10
|
|
|
|
|
|
|
|
11
|
40
|
|
|
40
|
|
339
|
use Carp qw( confess ); |
|
40
|
|
|
|
|
122
|
|
|
40
|
|
|
|
|
2012
|
|
12
|
40
|
|
|
40
|
|
732
|
use English qw(-no_match_vars); |
|
40
|
|
|
|
|
3742
|
|
|
40
|
|
|
|
|
282
|
|
13
|
40
|
|
|
40
|
|
14100
|
use File::Find qw(); |
|
40
|
|
|
|
|
101
|
|
|
40
|
|
|
|
|
835
|
|
14
|
40
|
|
|
40
|
|
248
|
use File::Spec qw(); |
|
40
|
|
|
|
|
111
|
|
|
40
|
|
|
|
|
918
|
|
15
|
40
|
|
|
40
|
|
242
|
use Scalar::Util qw( blessed ); |
|
40
|
|
|
|
|
96
|
|
|
40
|
|
|
|
|
2989
|
|
16
|
40
|
|
|
40
|
|
20718
|
use B::Keywords qw(); |
|
40
|
|
|
|
|
71781
|
|
|
40
|
|
|
|
|
1112
|
|
17
|
40
|
|
|
40
|
|
16374
|
use PPI::Token::Quote::Single; |
|
40
|
|
|
|
|
2471269
|
|
|
40
|
|
|
|
|
1913
|
|
18
|
40
|
|
|
40
|
|
9873
|
use List::SomeUtils qw(any); |
|
40
|
|
|
|
|
224800
|
|
|
40
|
|
|
|
|
2829
|
|
19
|
|
|
|
|
|
|
|
20
|
40
|
|
|
40
|
|
19837
|
use Perl::Critic::Exception::Fatal::Generic qw{ throw_generic }; |
|
40
|
|
|
|
|
168
|
|
|
40
|
|
|
|
|
1137
|
|
21
|
40
|
|
|
40
|
|
19143
|
use Perl::Critic::Utils::PPI qw< is_ppi_expression_or_generic_statement >; |
|
40
|
|
|
|
|
124
|
|
|
40
|
|
|
|
|
2587
|
|
22
|
|
|
|
|
|
|
|
23
|
40
|
|
|
40
|
|
361
|
use Exporter 'import'; |
|
40
|
|
|
|
|
90
|
|
|
40
|
|
|
|
|
247983
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = '1.146'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
28
|
|
|
|
|
|
|
# Exportable symbols here. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw( |
31
|
|
|
|
|
|
|
$TRUE |
32
|
|
|
|
|
|
|
$FALSE |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$POLICY_NAMESPACE |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$SEVERITY_HIGHEST |
37
|
|
|
|
|
|
|
$SEVERITY_HIGH |
38
|
|
|
|
|
|
|
$SEVERITY_MEDIUM |
39
|
|
|
|
|
|
|
$SEVERITY_LOW |
40
|
|
|
|
|
|
|
$SEVERITY_LOWEST |
41
|
|
|
|
|
|
|
@SEVERITY_NAMES |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$DEFAULT_VERBOSITY |
44
|
|
|
|
|
|
|
$DEFAULT_VERBOSITY_WITH_FILE_NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$COLON |
47
|
|
|
|
|
|
|
$COMMA |
48
|
|
|
|
|
|
|
$DQUOTE |
49
|
|
|
|
|
|
|
$EMPTY |
50
|
|
|
|
|
|
|
$EQUAL |
51
|
|
|
|
|
|
|
$FATCOMMA |
52
|
|
|
|
|
|
|
$PERIOD |
53
|
|
|
|
|
|
|
$PIPE |
54
|
|
|
|
|
|
|
$QUOTE |
55
|
|
|
|
|
|
|
$BACKTICK |
56
|
|
|
|
|
|
|
$SCOLON |
57
|
|
|
|
|
|
|
$SPACE |
58
|
|
|
|
|
|
|
$SLASH |
59
|
|
|
|
|
|
|
$BSLASH |
60
|
|
|
|
|
|
|
$LEFT_PAREN |
61
|
|
|
|
|
|
|
$RIGHT_PAREN |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
all_perl_files |
64
|
|
|
|
|
|
|
find_keywords |
65
|
|
|
|
|
|
|
first_arg |
66
|
|
|
|
|
|
|
hashify |
67
|
|
|
|
|
|
|
interpolate |
68
|
|
|
|
|
|
|
is_assignment_operator |
69
|
|
|
|
|
|
|
is_class_name |
70
|
|
|
|
|
|
|
is_function_call |
71
|
|
|
|
|
|
|
is_hash_key |
72
|
|
|
|
|
|
|
is_in_void_context |
73
|
|
|
|
|
|
|
is_included_module_name |
74
|
|
|
|
|
|
|
is_integer |
75
|
|
|
|
|
|
|
is_label_pointer |
76
|
|
|
|
|
|
|
is_method_call |
77
|
|
|
|
|
|
|
is_package_declaration |
78
|
|
|
|
|
|
|
is_perl_bareword |
79
|
|
|
|
|
|
|
is_perl_builtin |
80
|
|
|
|
|
|
|
is_perl_builtin_with_list_context |
81
|
|
|
|
|
|
|
is_perl_builtin_with_multiple_arguments |
82
|
|
|
|
|
|
|
is_perl_builtin_with_no_arguments |
83
|
|
|
|
|
|
|
is_perl_builtin_with_one_argument |
84
|
|
|
|
|
|
|
is_perl_builtin_with_optional_argument |
85
|
|
|
|
|
|
|
is_perl_builtin_with_zero_and_or_one_arguments |
86
|
|
|
|
|
|
|
is_perl_filehandle |
87
|
|
|
|
|
|
|
is_perl_global |
88
|
|
|
|
|
|
|
is_qualified_name |
89
|
|
|
|
|
|
|
is_script |
90
|
|
|
|
|
|
|
is_subroutine_name |
91
|
|
|
|
|
|
|
is_unchecked_call |
92
|
|
|
|
|
|
|
is_valid_numeric_verbosity |
93
|
|
|
|
|
|
|
parse_arg_list |
94
|
|
|
|
|
|
|
policy_long_name |
95
|
|
|
|
|
|
|
policy_short_name |
96
|
|
|
|
|
|
|
precedence_of |
97
|
|
|
|
|
|
|
severity_to_number |
98
|
|
|
|
|
|
|
shebang_line |
99
|
|
|
|
|
|
|
split_nodes_on_comma |
100
|
|
|
|
|
|
|
verbosity_to_format |
101
|
|
|
|
|
|
|
words_from_string |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# Note: this is deprecated. This should also violate ProhibitAutomaticExportation, |
106
|
|
|
|
|
|
|
# but at the moment, we aren't smart enough to deal with Readonly variables. |
107
|
|
|
|
|
|
|
Readonly::Array our @EXPORT => @EXPORT_OK; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Readonly::Hash our %EXPORT_TAGS => ( |
111
|
|
|
|
|
|
|
all => [ @EXPORT_OK ], |
112
|
|
|
|
|
|
|
booleans => [ qw{ $TRUE $FALSE } ], |
113
|
|
|
|
|
|
|
severities => [ |
114
|
|
|
|
|
|
|
qw{ |
115
|
|
|
|
|
|
|
$SEVERITY_HIGHEST |
116
|
|
|
|
|
|
|
$SEVERITY_HIGH |
117
|
|
|
|
|
|
|
$SEVERITY_MEDIUM |
118
|
|
|
|
|
|
|
$SEVERITY_LOW |
119
|
|
|
|
|
|
|
$SEVERITY_LOWEST |
120
|
|
|
|
|
|
|
@SEVERITY_NAMES |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
], |
123
|
|
|
|
|
|
|
characters => [ |
124
|
|
|
|
|
|
|
qw{ |
125
|
|
|
|
|
|
|
$COLON |
126
|
|
|
|
|
|
|
$COMMA |
127
|
|
|
|
|
|
|
$DQUOTE |
128
|
|
|
|
|
|
|
$EMPTY |
129
|
|
|
|
|
|
|
$EQUAL |
130
|
|
|
|
|
|
|
$FATCOMMA |
131
|
|
|
|
|
|
|
$PERIOD |
132
|
|
|
|
|
|
|
$PIPE |
133
|
|
|
|
|
|
|
$QUOTE |
134
|
|
|
|
|
|
|
$BACKTICK |
135
|
|
|
|
|
|
|
$SCOLON |
136
|
|
|
|
|
|
|
$SPACE |
137
|
|
|
|
|
|
|
$SLASH |
138
|
|
|
|
|
|
|
$BSLASH |
139
|
|
|
|
|
|
|
$LEFT_PAREN |
140
|
|
|
|
|
|
|
$RIGHT_PAREN |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
], |
143
|
|
|
|
|
|
|
classification => [ |
144
|
|
|
|
|
|
|
qw{ |
145
|
|
|
|
|
|
|
is_assignment_operator |
146
|
|
|
|
|
|
|
is_class_name |
147
|
|
|
|
|
|
|
is_function_call |
148
|
|
|
|
|
|
|
is_hash_key |
149
|
|
|
|
|
|
|
is_included_module_name |
150
|
|
|
|
|
|
|
is_integer |
151
|
|
|
|
|
|
|
is_label_pointer |
152
|
|
|
|
|
|
|
is_method_call |
153
|
|
|
|
|
|
|
is_package_declaration |
154
|
|
|
|
|
|
|
is_perl_bareword |
155
|
|
|
|
|
|
|
is_perl_builtin |
156
|
|
|
|
|
|
|
is_perl_filehandle |
157
|
|
|
|
|
|
|
is_perl_global |
158
|
|
|
|
|
|
|
is_perl_builtin_with_list_context |
159
|
|
|
|
|
|
|
is_perl_builtin_with_multiple_arguments |
160
|
|
|
|
|
|
|
is_perl_builtin_with_no_arguments |
161
|
|
|
|
|
|
|
is_perl_builtin_with_one_argument |
162
|
|
|
|
|
|
|
is_perl_builtin_with_optional_argument |
163
|
|
|
|
|
|
|
is_perl_builtin_with_zero_and_or_one_arguments |
164
|
|
|
|
|
|
|
is_qualified_name |
165
|
|
|
|
|
|
|
is_script |
166
|
|
|
|
|
|
|
is_subroutine_name |
167
|
|
|
|
|
|
|
is_unchecked_call |
168
|
|
|
|
|
|
|
is_valid_numeric_verbosity |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
], |
171
|
|
|
|
|
|
|
data_conversion => [ qw{ hashify words_from_string interpolate } ], |
172
|
|
|
|
|
|
|
ppi => [ qw{ first_arg parse_arg_list } ], |
173
|
|
|
|
|
|
|
internal_lookup => [ qw{ severity_to_number verbosity_to_format } ], |
174
|
|
|
|
|
|
|
language => [ qw{ precedence_of } ], |
175
|
|
|
|
|
|
|
deprecated => [ qw{ find_keywords } ], |
176
|
|
|
|
|
|
|
); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Readonly::Scalar our $POLICY_NAMESPACE => 'Perl::Critic::Policy'; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Readonly::Scalar our $SEVERITY_HIGHEST => 5; |
185
|
|
|
|
|
|
|
Readonly::Scalar our $SEVERITY_HIGH => 4; |
186
|
|
|
|
|
|
|
Readonly::Scalar our $SEVERITY_MEDIUM => 3; |
187
|
|
|
|
|
|
|
Readonly::Scalar our $SEVERITY_LOW => 2; |
188
|
|
|
|
|
|
|
Readonly::Scalar our $SEVERITY_LOWEST => 1; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Readonly::Scalar our $COMMA => q{,}; |
193
|
|
|
|
|
|
|
Readonly::Scalar our $EQUAL => q{=}; |
194
|
|
|
|
|
|
|
Readonly::Scalar our $FATCOMMA => q{=>}; |
195
|
|
|
|
|
|
|
Readonly::Scalar our $COLON => q{:}; |
196
|
|
|
|
|
|
|
Readonly::Scalar our $SCOLON => q{;}; |
197
|
|
|
|
|
|
|
Readonly::Scalar our $QUOTE => q{'}; |
198
|
|
|
|
|
|
|
Readonly::Scalar our $DQUOTE => q{"}; |
199
|
|
|
|
|
|
|
Readonly::Scalar our $BACKTICK => q{`}; |
200
|
|
|
|
|
|
|
Readonly::Scalar our $PERIOD => q{.}; |
201
|
|
|
|
|
|
|
Readonly::Scalar our $PIPE => q{|}; |
202
|
|
|
|
|
|
|
Readonly::Scalar our $SPACE => q{ }; |
203
|
|
|
|
|
|
|
Readonly::Scalar our $SLASH => q{/}; |
204
|
|
|
|
|
|
|
Readonly::Scalar our $BSLASH => q{\\}; |
205
|
|
|
|
|
|
|
Readonly::Scalar our $LEFT_PAREN => q{(}; |
206
|
|
|
|
|
|
|
Readonly::Scalar our $RIGHT_PAREN => q{)}; |
207
|
|
|
|
|
|
|
Readonly::Scalar our $EMPTY => q{}; |
208
|
|
|
|
|
|
|
Readonly::Scalar our $TRUE => 1; |
209
|
|
|
|
|
|
|
Readonly::Scalar our $FALSE => 0; |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
#TODO: Should this include punctuations vars? |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
218
|
|
|
|
|
|
|
## no critic (ProhibitNoisyQuotes); |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Readonly::Hash my %PRECEDENCE_OF => ( |
221
|
|
|
|
|
|
|
'->' => 1, |
222
|
|
|
|
|
|
|
'++' => 2, |
223
|
|
|
|
|
|
|
'--' => 2, |
224
|
|
|
|
|
|
|
'**' => 3, |
225
|
|
|
|
|
|
|
'!' => 4, |
226
|
|
|
|
|
|
|
'~' => 4, |
227
|
|
|
|
|
|
|
'\\' => 4, |
228
|
|
|
|
|
|
|
'=~' => 5, |
229
|
|
|
|
|
|
|
'!~' => 5, |
230
|
|
|
|
|
|
|
'*' => 6, |
231
|
|
|
|
|
|
|
'/' => 6, |
232
|
|
|
|
|
|
|
'%' => 6, |
233
|
|
|
|
|
|
|
'x' => 6, |
234
|
|
|
|
|
|
|
'+' => 7, |
235
|
|
|
|
|
|
|
'-' => 7, |
236
|
|
|
|
|
|
|
'.' => 7, |
237
|
|
|
|
|
|
|
'<<' => 8, |
238
|
|
|
|
|
|
|
'>>' => 8, |
239
|
|
|
|
|
|
|
'-R' => 9, |
240
|
|
|
|
|
|
|
'-W' => 9, |
241
|
|
|
|
|
|
|
'-X' => 9, |
242
|
|
|
|
|
|
|
'-r' => 9, |
243
|
|
|
|
|
|
|
'-w' => 9, |
244
|
|
|
|
|
|
|
'-x' => 9, |
245
|
|
|
|
|
|
|
'-e' => 9, |
246
|
|
|
|
|
|
|
'-O' => 9, |
247
|
|
|
|
|
|
|
'-o' => 9, |
248
|
|
|
|
|
|
|
'-z' => 9, |
249
|
|
|
|
|
|
|
'-s' => 9, |
250
|
|
|
|
|
|
|
'-M' => 9, |
251
|
|
|
|
|
|
|
'-A' => 9, |
252
|
|
|
|
|
|
|
'-C' => 9, |
253
|
|
|
|
|
|
|
'-S' => 9, |
254
|
|
|
|
|
|
|
'-c' => 9, |
255
|
|
|
|
|
|
|
'-b' => 9, |
256
|
|
|
|
|
|
|
'-f' => 9, |
257
|
|
|
|
|
|
|
'-d' => 9, |
258
|
|
|
|
|
|
|
'-p' => 9, |
259
|
|
|
|
|
|
|
'-l' => 9, |
260
|
|
|
|
|
|
|
'-u' => 9, |
261
|
|
|
|
|
|
|
'-g' => 9, |
262
|
|
|
|
|
|
|
'-k' => 9, |
263
|
|
|
|
|
|
|
'-t' => 9, |
264
|
|
|
|
|
|
|
'-T' => 9, |
265
|
|
|
|
|
|
|
'-B' => 9, |
266
|
|
|
|
|
|
|
'<' => 10, |
267
|
|
|
|
|
|
|
'>' => 10, |
268
|
|
|
|
|
|
|
'<=' => 10, |
269
|
|
|
|
|
|
|
'>=' => 10, |
270
|
|
|
|
|
|
|
'lt' => 10, |
271
|
|
|
|
|
|
|
'gt' => 10, |
272
|
|
|
|
|
|
|
'le' => 10, |
273
|
|
|
|
|
|
|
'ge' => 10, |
274
|
|
|
|
|
|
|
'==' => 11, |
275
|
|
|
|
|
|
|
'!=' => 11, |
276
|
|
|
|
|
|
|
'<=>' => 11, |
277
|
|
|
|
|
|
|
'eq' => 11, |
278
|
|
|
|
|
|
|
'ne' => 11, |
279
|
|
|
|
|
|
|
'cmp' => 11, |
280
|
|
|
|
|
|
|
'~~' => 11, |
281
|
|
|
|
|
|
|
'&' => 12, |
282
|
|
|
|
|
|
|
'|' => 13, |
283
|
|
|
|
|
|
|
'^' => 13, |
284
|
|
|
|
|
|
|
'&&' => 14, |
285
|
|
|
|
|
|
|
'//' => 15, |
286
|
|
|
|
|
|
|
'||' => 15, |
287
|
|
|
|
|
|
|
'..' => 16, |
288
|
|
|
|
|
|
|
'...' => 17, |
289
|
|
|
|
|
|
|
'?' => 18, |
290
|
|
|
|
|
|
|
':' => 18, |
291
|
|
|
|
|
|
|
'=' => 19, |
292
|
|
|
|
|
|
|
'+=' => 19, |
293
|
|
|
|
|
|
|
'-=' => 19, |
294
|
|
|
|
|
|
|
'*=' => 19, |
295
|
|
|
|
|
|
|
'/=' => 19, |
296
|
|
|
|
|
|
|
'%=' => 19, |
297
|
|
|
|
|
|
|
'||=' => 19, |
298
|
|
|
|
|
|
|
'&&=' => 19, |
299
|
|
|
|
|
|
|
'|=' => 19, |
300
|
|
|
|
|
|
|
'&=' => 19, |
301
|
|
|
|
|
|
|
'**=' => 19, |
302
|
|
|
|
|
|
|
'x=' => 19, |
303
|
|
|
|
|
|
|
'.=' => 19, |
304
|
|
|
|
|
|
|
'^=' => 19, |
305
|
|
|
|
|
|
|
'<<=' => 19, |
306
|
|
|
|
|
|
|
'>>=' => 19, |
307
|
|
|
|
|
|
|
'//=' => 19, |
308
|
|
|
|
|
|
|
',' => 20, |
309
|
|
|
|
|
|
|
'=>' => 20, |
310
|
|
|
|
|
|
|
'not' => 22, |
311
|
|
|
|
|
|
|
'and' => 23, |
312
|
|
|
|
|
|
|
'or' => 24, |
313
|
|
|
|
|
|
|
'xor' => 24, |
314
|
|
|
|
|
|
|
); |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
## use critic |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
Readonly::Scalar my $MIN_PRECEDENCE_TO_TERMINATE_PARENLESS_ARG_LIST => |
319
|
|
|
|
|
|
|
precedence_of( 'not' ); |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
sub hashify { ## no critic (ArgUnpacking) |
324
|
39532
|
|
|
39532
|
1
|
99711
|
return map { $_ => 1 } @_; |
|
616191
|
|
|
|
|
1132019
|
|
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
sub interpolate { |
330
|
959
|
|
|
959
|
1
|
1701
|
my ( $literal ) = @_; |
331
|
959
|
|
33
|
|
|
52417
|
return eval "\"$literal\"" || confess $EVAL_ERROR; ## no critic (StringyEval); |
332
|
|
|
|
|
|
|
} |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
sub find_keywords { |
337
|
5
|
|
|
5
|
1
|
8905
|
my ( $doc, $keyword ) = @_; |
338
|
5
|
|
|
|
|
24
|
my $nodes_ref = $doc->find('PPI::Token::Word'); |
339
|
5
|
100
|
|
|
|
213
|
return if !$nodes_ref; |
340
|
4
|
|
|
|
|
9
|
my @matches = grep { $_ eq $keyword } @{$nodes_ref}; |
|
11
|
|
|
|
|
104
|
|
|
4
|
|
|
|
|
9
|
|
341
|
4
|
100
|
|
|
|
73
|
return @matches ? \@matches : undef; |
342
|
|
|
|
|
|
|
} |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
sub _name_for_sub_or_stringified_element { |
347
|
3765
|
|
|
3765
|
|
5194
|
my $elem = shift; |
348
|
|
|
|
|
|
|
|
349
|
3765
|
100
|
100
|
|
|
21089
|
if ( blessed $elem and $elem->isa('PPI::Statement::Sub') ) { |
350
|
62
|
|
|
|
|
176
|
return $elem->name(); |
351
|
|
|
|
|
|
|
} |
352
|
|
|
|
|
|
|
|
353
|
3703
|
|
|
|
|
8500
|
return "$elem"; |
354
|
|
|
|
|
|
|
} |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
357
|
|
|
|
|
|
|
## no critic (ProhibitPackageVars) |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
Readonly::Hash my %BUILTINS => hashify( @B::Keywords::Functions ); |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
sub is_perl_builtin { |
362
|
415
|
|
|
415
|
1
|
2399
|
my $elem = shift; |
363
|
415
|
50
|
|
|
|
1175
|
return if !$elem; |
364
|
|
|
|
|
|
|
|
365
|
415
|
|
|
|
|
899
|
return exists $BUILTINS{ _name_for_sub_or_stringified_element($elem) }; |
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
Readonly::Hash my %BAREWORDS => hashify( |
371
|
|
|
|
|
|
|
@B::Keywords::Barewords, |
372
|
|
|
|
|
|
|
@B::Keywords::BarewordsExtra, |
373
|
|
|
|
|
|
|
); |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
sub is_perl_bareword { |
376
|
1691
|
|
|
1691
|
1
|
5513
|
my $elem = shift; |
377
|
1691
|
50
|
|
|
|
3756
|
return if !$elem; |
378
|
|
|
|
|
|
|
|
379
|
1691
|
|
|
|
|
3546
|
return exists $BAREWORDS{ _name_for_sub_or_stringified_element($elem) }; |
380
|
|
|
|
|
|
|
} |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
sub _build_globals_without_sigils { |
385
|
|
|
|
|
|
|
# B::Keywords as of 1.08 forgot $\ |
386
|
|
|
|
|
|
|
my @globals = |
387
|
40
|
|
|
40
|
|
223
|
map { substr $_, 1 } |
|
5960
|
|
|
|
|
10623
|
|
388
|
|
|
|
|
|
|
@B::Keywords::Arrays, |
389
|
|
|
|
|
|
|
@B::Keywords::Hashes, |
390
|
|
|
|
|
|
|
@B::Keywords::Scalars, |
391
|
|
|
|
|
|
|
'$\\'; ## no critic (RequireInterpolationOfMetachars) |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
# Not all of these have sigils |
394
|
40
|
|
|
|
|
203
|
foreach my $filehandle (@B::Keywords::Filehandles) { |
395
|
360
|
|
|
|
|
903
|
(my $stripped = $filehandle) =~ s< \A [*] ><>xms; |
396
|
360
|
|
|
|
|
859
|
push @globals, $stripped; |
397
|
|
|
|
|
|
|
} |
398
|
|
|
|
|
|
|
|
399
|
40
|
|
|
|
|
1609
|
return @globals; |
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
Readonly::Array my @GLOBALS_WITHOUT_SIGILS => _build_globals_without_sigils(); |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
Readonly::Hash my %GLOBALS => hashify( @GLOBALS_WITHOUT_SIGILS ); |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
sub is_perl_global { |
407
|
853
|
|
|
853
|
1
|
3556
|
my $elem = shift; |
408
|
853
|
50
|
|
|
|
2753
|
return if !$elem; |
409
|
853
|
|
|
|
|
2017
|
my $var_name = "$elem"; #Convert Token::Symbol to string |
410
|
853
|
|
|
|
|
5056
|
$var_name =~ s{\A [\$@%*] }{}xms; #Chop off the sigil |
411
|
853
|
|
|
|
|
4259
|
return exists $GLOBALS{ $var_name }; |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
Readonly::Hash my %FILEHANDLES => hashify( @B::Keywords::Filehandles ); |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
sub is_perl_filehandle { |
419
|
1580
|
|
|
1580
|
1
|
2787
|
my $elem = shift; |
420
|
1580
|
50
|
|
|
|
4585
|
return if !$elem; |
421
|
|
|
|
|
|
|
|
422
|
1580
|
|
|
|
|
3168
|
return exists $FILEHANDLES{ _name_for_sub_or_stringified_element($elem) }; |
423
|
|
|
|
|
|
|
} |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
## use critic |
426
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
# egrep '=item.*LIST' perlfunc.pod |
429
|
|
|
|
|
|
|
Readonly::Hash my %BUILTINS_WHICH_PROVIDE_LIST_CONTEXT => |
430
|
|
|
|
|
|
|
hashify( |
431
|
|
|
|
|
|
|
qw{ |
432
|
|
|
|
|
|
|
chmod |
433
|
|
|
|
|
|
|
chown |
434
|
|
|
|
|
|
|
die |
435
|
|
|
|
|
|
|
exec |
436
|
|
|
|
|
|
|
formline |
437
|
|
|
|
|
|
|
grep |
438
|
|
|
|
|
|
|
import |
439
|
|
|
|
|
|
|
join |
440
|
|
|
|
|
|
|
kill |
441
|
|
|
|
|
|
|
map |
442
|
|
|
|
|
|
|
no |
443
|
|
|
|
|
|
|
open |
444
|
|
|
|
|
|
|
pack |
445
|
|
|
|
|
|
|
print |
446
|
|
|
|
|
|
|
printf |
447
|
|
|
|
|
|
|
push |
448
|
|
|
|
|
|
|
reverse |
449
|
|
|
|
|
|
|
say |
450
|
|
|
|
|
|
|
sort |
451
|
|
|
|
|
|
|
splice |
452
|
|
|
|
|
|
|
sprintf |
453
|
|
|
|
|
|
|
syscall |
454
|
|
|
|
|
|
|
system |
455
|
|
|
|
|
|
|
tie |
456
|
|
|
|
|
|
|
unlink |
457
|
|
|
|
|
|
|
unshift |
458
|
|
|
|
|
|
|
use |
459
|
|
|
|
|
|
|
utime |
460
|
|
|
|
|
|
|
warn |
461
|
|
|
|
|
|
|
}, |
462
|
|
|
|
|
|
|
); |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
sub is_perl_builtin_with_list_context { |
465
|
0
|
|
|
0
|
1
|
0
|
my $elem = shift; |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
return |
468
|
|
|
|
|
|
|
exists |
469
|
|
|
|
|
|
|
$BUILTINS_WHICH_PROVIDE_LIST_CONTEXT{ |
470
|
0
|
|
|
|
|
0
|
_name_for_sub_or_stringified_element($elem) |
471
|
|
|
|
|
|
|
}; |
472
|
|
|
|
|
|
|
} |
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
# egrep '=item.*[A-Z],' perlfunc.pod |
477
|
|
|
|
|
|
|
Readonly::Hash my %BUILTINS_WHICH_TAKE_MULTIPLE_ARGUMENTS => |
478
|
|
|
|
|
|
|
hashify( |
479
|
|
|
|
|
|
|
qw{ |
480
|
|
|
|
|
|
|
accept |
481
|
|
|
|
|
|
|
atan2 |
482
|
|
|
|
|
|
|
bind |
483
|
|
|
|
|
|
|
binmode |
484
|
|
|
|
|
|
|
bless |
485
|
|
|
|
|
|
|
connect |
486
|
|
|
|
|
|
|
crypt |
487
|
|
|
|
|
|
|
dbmopen |
488
|
|
|
|
|
|
|
fcntl |
489
|
|
|
|
|
|
|
flock |
490
|
|
|
|
|
|
|
gethostbyaddr |
491
|
|
|
|
|
|
|
getnetbyaddr |
492
|
|
|
|
|
|
|
getpriority |
493
|
|
|
|
|
|
|
getservbyname |
494
|
|
|
|
|
|
|
getservbyport |
495
|
|
|
|
|
|
|
getsockopt |
496
|
|
|
|
|
|
|
index |
497
|
|
|
|
|
|
|
ioctl |
498
|
|
|
|
|
|
|
link |
499
|
|
|
|
|
|
|
listen |
500
|
|
|
|
|
|
|
mkdir |
501
|
|
|
|
|
|
|
msgctl |
502
|
|
|
|
|
|
|
msgget |
503
|
|
|
|
|
|
|
msgrcv |
504
|
|
|
|
|
|
|
msgsnd |
505
|
|
|
|
|
|
|
open |
506
|
|
|
|
|
|
|
opendir |
507
|
|
|
|
|
|
|
pipe |
508
|
|
|
|
|
|
|
read |
509
|
|
|
|
|
|
|
recv |
510
|
|
|
|
|
|
|
rename |
511
|
|
|
|
|
|
|
rindex |
512
|
|
|
|
|
|
|
seek |
513
|
|
|
|
|
|
|
seekdir |
514
|
|
|
|
|
|
|
select |
515
|
|
|
|
|
|
|
semctl |
516
|
|
|
|
|
|
|
semget |
517
|
|
|
|
|
|
|
semop |
518
|
|
|
|
|
|
|
send |
519
|
|
|
|
|
|
|
setpgrp |
520
|
|
|
|
|
|
|
setpriority |
521
|
|
|
|
|
|
|
setsockopt |
522
|
|
|
|
|
|
|
shmctl |
523
|
|
|
|
|
|
|
shmget |
524
|
|
|
|
|
|
|
shmread |
525
|
|
|
|
|
|
|
shmwrite |
526
|
|
|
|
|
|
|
shutdown |
527
|
|
|
|
|
|
|
socket |
528
|
|
|
|
|
|
|
socketpair |
529
|
|
|
|
|
|
|
splice |
530
|
|
|
|
|
|
|
split |
531
|
|
|
|
|
|
|
substr |
532
|
|
|
|
|
|
|
symlink |
533
|
|
|
|
|
|
|
sysopen |
534
|
|
|
|
|
|
|
sysread |
535
|
|
|
|
|
|
|
sysseek |
536
|
|
|
|
|
|
|
syswrite |
537
|
|
|
|
|
|
|
truncate |
538
|
|
|
|
|
|
|
unpack |
539
|
|
|
|
|
|
|
vec |
540
|
|
|
|
|
|
|
waitpid |
541
|
|
|
|
|
|
|
}, |
542
|
|
|
|
|
|
|
keys %BUILTINS_WHICH_PROVIDE_LIST_CONTEXT |
543
|
|
|
|
|
|
|
); |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
sub is_perl_builtin_with_multiple_arguments { |
546
|
17
|
|
|
17
|
1
|
497
|
my $elem = shift; |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
return |
549
|
|
|
|
|
|
|
exists |
550
|
|
|
|
|
|
|
$BUILTINS_WHICH_TAKE_MULTIPLE_ARGUMENTS{ |
551
|
17
|
|
|
|
|
45
|
_name_for_sub_or_stringified_element($elem) |
552
|
|
|
|
|
|
|
}; |
553
|
|
|
|
|
|
|
} |
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
556
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
Readonly::Hash my %BUILTINS_WHICH_TAKE_NO_ARGUMENTS => |
558
|
|
|
|
|
|
|
hashify( |
559
|
|
|
|
|
|
|
qw{ |
560
|
|
|
|
|
|
|
endgrent |
561
|
|
|
|
|
|
|
endhostent |
562
|
|
|
|
|
|
|
endnetent |
563
|
|
|
|
|
|
|
endprotoent |
564
|
|
|
|
|
|
|
endpwent |
565
|
|
|
|
|
|
|
endservent |
566
|
|
|
|
|
|
|
fork |
567
|
|
|
|
|
|
|
format |
568
|
|
|
|
|
|
|
getgrent |
569
|
|
|
|
|
|
|
gethostent |
570
|
|
|
|
|
|
|
getlogin |
571
|
|
|
|
|
|
|
getnetent |
572
|
|
|
|
|
|
|
getppid |
573
|
|
|
|
|
|
|
getprotoent |
574
|
|
|
|
|
|
|
getpwent |
575
|
|
|
|
|
|
|
getservent |
576
|
|
|
|
|
|
|
setgrent |
577
|
|
|
|
|
|
|
setpwent |
578
|
|
|
|
|
|
|
split |
579
|
|
|
|
|
|
|
time |
580
|
|
|
|
|
|
|
times |
581
|
|
|
|
|
|
|
wait |
582
|
|
|
|
|
|
|
wantarray |
583
|
|
|
|
|
|
|
} |
584
|
|
|
|
|
|
|
); |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
sub is_perl_builtin_with_no_arguments { |
587
|
0
|
|
|
0
|
1
|
0
|
my $elem = shift; |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
return |
590
|
|
|
|
|
|
|
exists |
591
|
|
|
|
|
|
|
$BUILTINS_WHICH_TAKE_NO_ARGUMENTS{ |
592
|
0
|
|
|
|
|
0
|
_name_for_sub_or_stringified_element($elem) |
593
|
|
|
|
|
|
|
}; |
594
|
|
|
|
|
|
|
} |
595
|
|
|
|
|
|
|
|
596
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
Readonly::Hash my %BUILTINS_WHICH_TAKE_ONE_ARGUMENT => |
599
|
|
|
|
|
|
|
hashify( |
600
|
|
|
|
|
|
|
qw{ |
601
|
|
|
|
|
|
|
closedir |
602
|
|
|
|
|
|
|
dbmclose |
603
|
|
|
|
|
|
|
delete |
604
|
|
|
|
|
|
|
each |
605
|
|
|
|
|
|
|
exists |
606
|
|
|
|
|
|
|
fileno |
607
|
|
|
|
|
|
|
getgrgid |
608
|
|
|
|
|
|
|
getgrnam |
609
|
|
|
|
|
|
|
gethostbyname |
610
|
|
|
|
|
|
|
getnetbyname |
611
|
|
|
|
|
|
|
getpeername |
612
|
|
|
|
|
|
|
getpgrp |
613
|
|
|
|
|
|
|
getprotobyname |
614
|
|
|
|
|
|
|
getprotobynumber |
615
|
|
|
|
|
|
|
getpwnam |
616
|
|
|
|
|
|
|
getpwuid |
617
|
|
|
|
|
|
|
getsockname |
618
|
|
|
|
|
|
|
goto |
619
|
|
|
|
|
|
|
keys |
620
|
|
|
|
|
|
|
local |
621
|
|
|
|
|
|
|
prototype |
622
|
|
|
|
|
|
|
readdir |
623
|
|
|
|
|
|
|
readline |
624
|
|
|
|
|
|
|
readpipe |
625
|
|
|
|
|
|
|
rewinddir |
626
|
|
|
|
|
|
|
scalar |
627
|
|
|
|
|
|
|
sethostent |
628
|
|
|
|
|
|
|
setnetent |
629
|
|
|
|
|
|
|
setprotoent |
630
|
|
|
|
|
|
|
setservent |
631
|
|
|
|
|
|
|
telldir |
632
|
|
|
|
|
|
|
tied |
633
|
|
|
|
|
|
|
untie |
634
|
|
|
|
|
|
|
values |
635
|
|
|
|
|
|
|
} |
636
|
|
|
|
|
|
|
); |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
sub is_perl_builtin_with_one_argument { |
639
|
0
|
|
|
0
|
1
|
0
|
my $elem = shift; |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
return |
642
|
|
|
|
|
|
|
exists |
643
|
|
|
|
|
|
|
$BUILTINS_WHICH_TAKE_ONE_ARGUMENT{ |
644
|
0
|
|
|
|
|
0
|
_name_for_sub_or_stringified_element($elem) |
645
|
|
|
|
|
|
|
}; |
646
|
|
|
|
|
|
|
} |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
## no critic (ProhibitPackageVars) |
651
|
|
|
|
|
|
|
Readonly::Hash my %BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT => |
652
|
|
|
|
|
|
|
hashify( |
653
|
|
|
|
|
|
|
grep { not exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{ $_ } } |
654
|
|
|
|
|
|
|
grep { not exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{ $_ } } |
655
|
|
|
|
|
|
|
grep { not exists $BUILTINS_WHICH_TAKE_MULTIPLE_ARGUMENTS{ $_ } } |
656
|
|
|
|
|
|
|
@B::Keywords::Functions |
657
|
|
|
|
|
|
|
); |
658
|
|
|
|
|
|
|
## use critic |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
sub is_perl_builtin_with_optional_argument { |
661
|
0
|
|
|
0
|
1
|
0
|
my $elem = shift; |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
return |
664
|
|
|
|
|
|
|
exists |
665
|
|
|
|
|
|
|
$BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT{ |
666
|
0
|
|
|
|
|
0
|
_name_for_sub_or_stringified_element($elem) |
667
|
|
|
|
|
|
|
}; |
668
|
|
|
|
|
|
|
} |
669
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
sub is_perl_builtin_with_zero_and_or_one_arguments { |
673
|
62
|
|
|
62
|
1
|
118
|
my $elem = shift; |
674
|
|
|
|
|
|
|
|
675
|
62
|
50
|
|
|
|
180
|
return if not $elem; |
676
|
|
|
|
|
|
|
|
677
|
62
|
|
|
|
|
175
|
my $name = _name_for_sub_or_stringified_element($elem); |
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
return ( |
680
|
|
|
|
|
|
|
exists $BUILTINS_WHICH_TAKE_ONE_ARGUMENT{ $name } |
681
|
|
|
|
|
|
|
or exists $BUILTINS_WHICH_TAKE_NO_ARGUMENTS{ $name } |
682
|
62
|
|
66
|
|
|
515
|
or exists $BUILTINS_WHICH_TAKE_OPTIONAL_ARGUMENT{ $name } |
683
|
|
|
|
|
|
|
); |
684
|
|
|
|
|
|
|
} |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
687
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
sub is_qualified_name { |
689
|
0
|
|
|
0
|
1
|
0
|
my $name = shift; |
690
|
|
|
|
|
|
|
|
691
|
0
|
0
|
|
|
|
0
|
return if not $name; |
692
|
|
|
|
|
|
|
|
693
|
0
|
|
|
|
|
0
|
return index ( $name, q{::} ) >= 0; |
694
|
|
|
|
|
|
|
} |
695
|
|
|
|
|
|
|
|
696
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
sub precedence_of { |
699
|
612
|
|
|
612
|
1
|
1583
|
my $elem = shift; |
700
|
612
|
50
|
|
|
|
1852
|
return if !$elem; |
701
|
612
|
100
|
|
|
|
2713
|
return $PRECEDENCE_OF{ ref $elem ? "$elem" : $elem }; |
702
|
|
|
|
|
|
|
} |
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
sub is_hash_key { |
707
|
4499
|
|
|
4499
|
1
|
20223
|
my $elem = shift; |
708
|
4499
|
50
|
|
|
|
11479
|
return if !$elem; |
709
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
#If followed by an argument list, then it's a function call, not a literal. |
711
|
4499
|
|
|
|
|
11618
|
my $sib = $elem->snext_sibling(); |
712
|
4499
|
100
|
100
|
|
|
112056
|
return if $sib && $sib->isa('PPI::Structure::List'); |
713
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
#Check curly-brace style: $hash{foo} = bar; |
715
|
3913
|
|
|
|
|
10157
|
my $parent = $elem->parent(); |
716
|
3913
|
50
|
|
|
|
20638
|
return if !$parent; |
717
|
3913
|
|
|
|
|
8373
|
my $grandparent = $parent->parent(); |
718
|
3913
|
50
|
|
|
|
17602
|
return if !$grandparent; |
719
|
3913
|
100
|
|
|
|
13968
|
return 1 if $grandparent->isa('PPI::Structure::Subscript'); |
720
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
#Check declarative style: %hash = (foo => bar); |
723
|
3863
|
100
|
100
|
|
|
18311
|
return 1 if $sib && $sib->isa('PPI::Token::Operator') && $sib eq '=>'; |
|
|
|
100
|
|
|
|
|
724
|
|
|
|
|
|
|
|
725
|
3841
|
|
|
|
|
12277
|
return; |
726
|
|
|
|
|
|
|
} |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
729
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
sub is_included_module_name { |
731
|
1788
|
|
|
1788
|
1
|
2631
|
my $elem = shift; |
732
|
1788
|
50
|
|
|
|
4034
|
return if !$elem; |
733
|
1788
|
|
|
|
|
3475
|
my $stmnt = $elem->statement(); |
734
|
1788
|
50
|
|
|
|
22610
|
return if !$stmnt; |
735
|
1788
|
100
|
|
|
|
7117
|
return if !$stmnt->isa('PPI::Statement::Include'); |
736
|
126
|
|
|
|
|
424
|
return $stmnt->schild(1) == $elem; |
737
|
|
|
|
|
|
|
} |
738
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
740
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
sub is_integer { |
742
|
9659
|
|
|
9659
|
1
|
17278
|
my ($value) = @_; |
743
|
9659
|
50
|
|
|
|
23114
|
return 0 if not defined $value; |
744
|
|
|
|
|
|
|
|
745
|
9659
|
|
|
|
|
61153
|
return $value =~ m{ \A [+-]? \d+ \z }xms; |
746
|
|
|
|
|
|
|
} |
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
sub is_label_pointer { |
751
|
1493
|
|
|
1493
|
1
|
2191
|
my $elem = shift; |
752
|
1493
|
50
|
|
|
|
3799
|
return if !$elem; |
753
|
|
|
|
|
|
|
|
754
|
1493
|
|
|
|
|
3227
|
my $statement = $elem->statement(); |
755
|
1493
|
50
|
|
|
|
20800
|
return if !$statement; |
756
|
|
|
|
|
|
|
|
757
|
1493
|
|
|
|
|
3097
|
my $psib = $elem->sprevious_sibling(); |
758
|
1493
|
100
|
|
|
|
27138
|
return if !$psib; |
759
|
|
|
|
|
|
|
|
760
|
258
|
|
100
|
|
|
1384
|
return $statement->isa('PPI::Statement::Break') |
761
|
|
|
|
|
|
|
&& $psib =~ m/(?:redo|goto|next|last)/xmso; |
762
|
|
|
|
|
|
|
} |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
sub is_method_call { |
767
|
2142
|
|
|
2142
|
1
|
3694
|
my $elem = shift; |
768
|
2142
|
50
|
|
|
|
5177
|
return if !$elem; |
769
|
|
|
|
|
|
|
|
770
|
2142
|
|
|
|
|
4825
|
return _is_dereference_operator( $elem->sprevious_sibling() ); |
771
|
|
|
|
|
|
|
} |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
774
|
|
|
|
|
|
|
|
775
|
|
|
|
|
|
|
sub is_class_name { |
776
|
1551
|
|
|
1551
|
1
|
2270
|
my $elem = shift; |
777
|
1551
|
50
|
|
|
|
4085
|
return if !$elem; |
778
|
|
|
|
|
|
|
|
779
|
1551
|
|
66
|
|
|
3747
|
return _is_dereference_operator( $elem->snext_sibling() ) |
780
|
|
|
|
|
|
|
&& !_is_dereference_operator( $elem->sprevious_sibling() ); |
781
|
|
|
|
|
|
|
} |
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
784
|
|
|
|
|
|
|
|
785
|
|
|
|
|
|
|
sub _is_dereference_operator { |
786
|
3706
|
|
|
3706
|
|
76670
|
my $elem = shift; |
787
|
3706
|
100
|
|
|
|
10930
|
return if !$elem; |
788
|
|
|
|
|
|
|
|
789
|
2073
|
|
100
|
|
|
9977
|
return $elem->isa('PPI::Token::Operator') && $elem eq q{->}; |
790
|
|
|
|
|
|
|
} |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
sub is_package_declaration { |
795
|
1686
|
|
|
1686
|
1
|
2695
|
my $elem = shift; |
796
|
1686
|
50
|
|
|
|
4590
|
return if !$elem; |
797
|
1686
|
|
|
|
|
4369
|
my $stmnt = $elem->statement(); |
798
|
1686
|
50
|
|
|
|
26602
|
return if !$stmnt; |
799
|
1686
|
50
|
|
|
|
7194
|
return if !$stmnt->isa('PPI::Statement::Package'); |
800
|
0
|
|
|
|
|
0
|
return $stmnt->schild(1) == $elem; |
801
|
|
|
|
|
|
|
} |
802
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
804
|
|
|
|
|
|
|
|
805
|
|
|
|
|
|
|
sub is_subroutine_name { |
806
|
1724
|
|
|
1724
|
1
|
2869
|
my $elem = shift; |
807
|
1724
|
50
|
|
|
|
4263
|
return if !$elem; |
808
|
1724
|
|
|
|
|
3954
|
my $sib = $elem->sprevious_sibling(); |
809
|
1724
|
100
|
|
|
|
33207
|
return if !$sib; |
810
|
435
|
|
|
|
|
1051
|
my $stmnt = $elem->statement(); |
811
|
435
|
50
|
|
|
|
6683
|
return if !$stmnt; |
812
|
435
|
|
66
|
|
|
2200
|
return $stmnt->isa('PPI::Statement::Sub') && $sib eq 'sub'; |
813
|
|
|
|
|
|
|
} |
814
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
816
|
|
|
|
|
|
|
|
817
|
|
|
|
|
|
|
sub is_function_call { |
818
|
1653
|
50
|
|
1653
|
1
|
7796
|
my $elem = shift or return; |
819
|
|
|
|
|
|
|
|
820
|
1653
|
100
|
|
|
|
3411
|
return if is_perl_bareword($elem); |
821
|
1580
|
50
|
|
|
|
21328
|
return if is_perl_filehandle($elem); |
822
|
1580
|
50
|
|
|
|
17624
|
return if is_package_declaration($elem); |
823
|
1580
|
100
|
|
|
|
3565
|
return if is_included_module_name($elem); |
824
|
1576
|
100
|
|
|
|
5641
|
return if is_method_call($elem); |
825
|
1551
|
100
|
|
|
|
6191
|
return if is_class_name($elem); |
826
|
1538
|
100
|
|
|
|
7138
|
return if is_subroutine_name($elem); |
827
|
1493
|
100
|
|
|
|
3144
|
return if is_label_pointer($elem); |
828
|
1492
|
100
|
|
|
|
3405
|
return if is_hash_key($elem); |
829
|
|
|
|
|
|
|
|
830
|
1462
|
|
|
|
|
7655
|
return 1; |
831
|
|
|
|
|
|
|
} |
832
|
|
|
|
|
|
|
|
833
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
834
|
|
|
|
|
|
|
|
835
|
|
|
|
|
|
|
sub is_script { |
836
|
8
|
|
|
8
|
1
|
9268
|
my $doc = shift; |
837
|
|
|
|
|
|
|
|
838
|
8
|
|
|
|
|
469
|
warnings::warnif( |
839
|
|
|
|
|
|
|
'deprecated', |
840
|
|
|
|
|
|
|
'Perl::Critic::Utils::is_script($doc) deprecated, use $doc->is_program() instead.', ## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars) |
841
|
|
|
|
|
|
|
); |
842
|
|
|
|
|
|
|
|
843
|
8
|
50
|
33
|
|
|
87
|
return $doc->is_program() |
844
|
|
|
|
|
|
|
if blessed($doc) && $doc->isa('Perl::Critic::Document'); |
845
|
|
|
|
|
|
|
|
846
|
8
|
100
|
|
|
|
25
|
return 1 if shebang_line($doc); |
847
|
3
|
100
|
|
|
|
10
|
return 1 if _is_PL_file($doc); |
848
|
2
|
|
|
|
|
14
|
return 0; |
849
|
|
|
|
|
|
|
} |
850
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
852
|
|
|
|
|
|
|
|
853
|
|
|
|
|
|
|
sub _is_PL_file { ## no critic (NamingConventions::Capitalization) |
854
|
3
|
|
|
3
|
|
7
|
my ($doc) = @_; |
855
|
3
|
50
|
|
|
|
16
|
return if not $doc->can('filename'); |
856
|
3
|
|
100
|
|
|
10
|
my $filename = $doc->filename() || return; |
857
|
1
|
50
|
|
|
|
17
|
return 1 if $filename =~ m/[.] PL \z/xms; |
858
|
0
|
|
|
|
|
0
|
return 0; |
859
|
|
|
|
|
|
|
} |
860
|
|
|
|
|
|
|
|
861
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
sub is_in_void_context { |
864
|
65
|
|
|
65
|
1
|
126
|
my ($token) = @_; |
865
|
|
|
|
|
|
|
|
866
|
|
|
|
|
|
|
# If part of a collective, can't be void. |
867
|
65
|
100
|
|
|
|
160
|
return if $token->sprevious_sibling(); |
868
|
|
|
|
|
|
|
|
869
|
46
|
|
|
|
|
835
|
my $parent = $token->statement()->parent(); |
870
|
46
|
50
|
|
|
|
767
|
if ($parent) { |
871
|
46
|
100
|
|
|
|
155
|
return if $parent->isa('PPI::Structure::List'); |
872
|
34
|
50
|
|
|
|
120
|
return if $parent->isa('PPI::Structure::For'); |
873
|
34
|
100
|
|
|
|
126
|
return if $parent->isa('PPI::Structure::Condition'); |
874
|
30
|
100
|
|
|
|
107
|
return if $parent->isa('PPI::Structure::Constructor'); |
875
|
26
|
100
|
|
|
|
90
|
return if $parent->isa('PPI::Structure::Subscript'); |
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
# If it's in a block and not the last statement then it's in void. |
878
|
24
|
100
|
100
|
|
|
100
|
return 1 if |
879
|
|
|
|
|
|
|
$parent->isa('PPI::Structure::Block') |
880
|
|
|
|
|
|
|
and $token->statement()->snext_sibling(); |
881
|
|
|
|
|
|
|
|
882
|
22
|
|
|
|
|
379
|
my $grand_parent = $parent->parent(); |
883
|
22
|
100
|
|
|
|
107
|
if ($grand_parent) { |
884
|
|
|
|
|
|
|
return if |
885
|
10
|
100
|
66
|
|
|
80
|
$parent->isa('PPI::Structure::Block') |
886
|
|
|
|
|
|
|
and not $grand_parent->isa('PPI::Statement::Compound'); |
887
|
|
|
|
|
|
|
} |
888
|
|
|
|
|
|
|
} |
889
|
|
|
|
|
|
|
|
890
|
20
|
|
|
|
|
67
|
return $TRUE; |
891
|
|
|
|
|
|
|
} |
892
|
|
|
|
|
|
|
|
893
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
894
|
|
|
|
|
|
|
|
895
|
|
|
|
|
|
|
sub policy_long_name { |
896
|
29505
|
|
|
29505
|
1
|
51403
|
my ( $policy_name ) = @_; |
897
|
29505
|
100
|
|
|
|
136505
|
if ( $policy_name !~ m{ \A $POLICY_NAMESPACE }xms ) { |
898
|
3102
|
|
|
|
|
9091
|
$policy_name = $POLICY_NAMESPACE . q{::} . $policy_name; |
899
|
|
|
|
|
|
|
} |
900
|
29505
|
|
|
|
|
89369
|
return $policy_name; |
901
|
|
|
|
|
|
|
} |
902
|
|
|
|
|
|
|
|
903
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
904
|
|
|
|
|
|
|
|
905
|
|
|
|
|
|
|
sub policy_short_name { |
906
|
176150
|
|
|
176150
|
1
|
294328
|
my ( $policy_name ) = @_; |
907
|
176150
|
|
|
|
|
743592
|
$policy_name =~ s{\A $POLICY_NAMESPACE ::}{}xms; |
908
|
176150
|
|
|
|
|
520786
|
return $policy_name; |
909
|
|
|
|
|
|
|
} |
910
|
|
|
|
|
|
|
|
911
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
912
|
|
|
|
|
|
|
|
913
|
|
|
|
|
|
|
sub first_arg { |
914
|
231
|
|
|
231
|
1
|
6719
|
my $elem = shift; |
915
|
231
|
|
|
|
|
524
|
my $sib = $elem->snext_sibling(); |
916
|
231
|
100
|
|
|
|
5013
|
return if !$sib; |
917
|
|
|
|
|
|
|
|
918
|
225
|
100
|
|
|
|
790
|
if ( $sib->isa('PPI::Structure::List') ) { |
919
|
|
|
|
|
|
|
|
920
|
15
|
|
|
|
|
131
|
my $expr = $sib->schild(0); |
921
|
15
|
100
|
|
|
|
211
|
return if !$expr; |
922
|
9
|
50
|
|
|
|
40
|
return $expr->isa('PPI::Statement') ? $expr->schild(0) : $expr; |
923
|
|
|
|
|
|
|
} |
924
|
|
|
|
|
|
|
|
925
|
210
|
|
|
|
|
598
|
return $sib; |
926
|
|
|
|
|
|
|
} |
927
|
|
|
|
|
|
|
|
928
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
929
|
|
|
|
|
|
|
|
930
|
|
|
|
|
|
|
sub parse_arg_list { |
931
|
445
|
|
|
445
|
1
|
14375
|
my $elem = shift; |
932
|
445
|
|
|
|
|
1138
|
my $sib = $elem->snext_sibling(); |
933
|
445
|
100
|
|
|
|
9791
|
return if !$sib; |
934
|
|
|
|
|
|
|
|
935
|
441
|
100
|
|
|
|
1536
|
if ( $sib->isa('PPI::Structure::List') ) { |
936
|
|
|
|
|
|
|
|
937
|
|
|
|
|
|
|
#Pull siblings from list |
938
|
191
|
|
|
|
|
1635
|
my @list_contents = $sib->schildren(); |
939
|
191
|
100
|
|
|
|
1899
|
return if not @list_contents; |
940
|
|
|
|
|
|
|
|
941
|
189
|
|
|
|
|
286
|
my @list_expressions; |
942
|
189
|
|
|
|
|
380
|
foreach my $item (@list_contents) { |
943
|
189
|
50
|
|
|
|
578
|
if ( |
944
|
|
|
|
|
|
|
is_ppi_expression_or_generic_statement($item) |
945
|
|
|
|
|
|
|
) { |
946
|
189
|
|
|
|
|
479
|
push |
947
|
|
|
|
|
|
|
@list_expressions, |
948
|
|
|
|
|
|
|
split_nodes_on_comma( $item->schildren() ); |
949
|
|
|
|
|
|
|
} |
950
|
|
|
|
|
|
|
else { |
951
|
0
|
|
|
|
|
0
|
push @list_expressions, $item; |
952
|
|
|
|
|
|
|
} |
953
|
|
|
|
|
|
|
} |
954
|
|
|
|
|
|
|
|
955
|
189
|
|
|
|
|
645
|
return @list_expressions; |
956
|
|
|
|
|
|
|
} |
957
|
|
|
|
|
|
|
else { |
958
|
|
|
|
|
|
|
|
959
|
|
|
|
|
|
|
#Gather up remaining nodes in the statement |
960
|
250
|
|
|
|
|
480
|
my $iter = $elem; |
961
|
250
|
|
|
|
|
530
|
my @arg_list = (); |
962
|
|
|
|
|
|
|
|
963
|
250
|
|
|
|
|
634
|
while ($iter = $iter->snext_sibling() ) { |
964
|
1071
|
100
|
66
|
|
|
26499
|
last if $iter->isa('PPI::Token::Structure') and $iter eq $SCOLON; |
965
|
894
|
100
|
100
|
|
|
2879
|
last if $iter->isa('PPI::Token::Operator') |
966
|
|
|
|
|
|
|
and $MIN_PRECEDENCE_TO_TERMINATE_PARENLESS_ARG_LIST <= |
967
|
|
|
|
|
|
|
precedence_of( $iter ); |
968
|
829
|
|
|
|
|
5390
|
push @arg_list, $iter; |
969
|
|
|
|
|
|
|
} |
970
|
250
|
|
|
|
|
4235
|
return split_nodes_on_comma( @arg_list ); |
971
|
|
|
|
|
|
|
} |
972
|
|
|
|
|
|
|
} |
973
|
|
|
|
|
|
|
|
974
|
|
|
|
|
|
|
#--------------------------------- |
975
|
|
|
|
|
|
|
|
976
|
|
|
|
|
|
|
sub split_nodes_on_comma { |
977
|
475
|
|
|
475
|
1
|
3086
|
my @nodes = @_; |
978
|
|
|
|
|
|
|
|
979
|
475
|
|
|
|
|
801
|
my $i = 0; |
980
|
475
|
|
|
|
|
704
|
my @node_stacks; |
981
|
475
|
|
|
|
|
941
|
for my $node (@nodes) { |
982
|
1680
|
100
|
100
|
|
|
7961
|
if ( |
|
|
100
|
100
|
|
|
|
|
983
|
|
|
|
|
|
|
$node->isa('PPI::Token::Operator') |
984
|
|
|
|
|
|
|
and ($node eq $COMMA or $node eq $FATCOMMA) |
985
|
|
|
|
|
|
|
) { |
986
|
547
|
100
|
|
|
|
8599
|
if (@node_stacks) { |
987
|
546
|
|
|
|
|
804
|
$i++; #Move forward to next 'node stack' |
988
|
|
|
|
|
|
|
} |
989
|
547
|
|
|
|
|
1112
|
next; |
990
|
|
|
|
|
|
|
} elsif ( $node->isa('PPI::Token::QuoteLike::Words' )) { |
991
|
25
|
|
|
|
|
57
|
my $section = $node->{sections}->[0]; |
992
|
25
|
|
|
|
|
68
|
my @words = words_from_string(substr $node->content, $section->{position}, $section->{size}); |
993
|
25
|
|
|
|
|
105
|
my $loc = $node->location; |
994
|
25
|
|
|
|
|
343
|
for my $word (@words) { |
995
|
28
|
|
|
|
|
132
|
my $token = PPI::Token::Quote::Single->new(q{'} . $word . q{'}); |
996
|
28
|
|
|
|
|
450
|
$token->{_location} = $loc; |
997
|
28
|
|
|
|
|
50
|
push @{ $node_stacks[$i++] }, $token; |
|
28
|
|
|
|
|
87
|
|
998
|
|
|
|
|
|
|
} |
999
|
25
|
|
|
|
|
65
|
next; |
1000
|
|
|
|
|
|
|
} |
1001
|
1108
|
|
|
|
|
1801
|
push @{ $node_stacks[$i] }, $node; |
|
1108
|
|
|
|
|
2748
|
|
1002
|
|
|
|
|
|
|
} |
1003
|
475
|
|
|
|
|
1710
|
return @node_stacks; |
1004
|
|
|
|
|
|
|
} |
1005
|
|
|
|
|
|
|
|
1006
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
1007
|
|
|
|
|
|
|
|
1008
|
|
|
|
|
|
|
# XXX: You must keep the regular expressions in extras/perlcritic.el in sync |
1009
|
|
|
|
|
|
|
# if you change these. |
1010
|
|
|
|
|
|
|
Readonly::Hash my %FORMAT_OF => ( |
1011
|
|
|
|
|
|
|
1 => "%f:%l:%c:%m\n", |
1012
|
|
|
|
|
|
|
2 => "%f: (%l:%c) %m\n", |
1013
|
|
|
|
|
|
|
3 => "%m at %f line %l\n", |
1014
|
|
|
|
|
|
|
4 => "%m at line %l, column %c. %e. (Severity: %s)\n", |
1015
|
|
|
|
|
|
|
5 => "%f: %m at line %l, column %c. %e. (Severity: %s)\n", |
1016
|
|
|
|
|
|
|
6 => "%m at line %l, near '%r'. (Severity: %s)\n", |
1017
|
|
|
|
|
|
|
7 => "%f: %m at line %l near '%r'. (Severity: %s)\n", |
1018
|
|
|
|
|
|
|
8 => "[%p] %m at line %l, column %c. (Severity: %s)\n", |
1019
|
|
|
|
|
|
|
9 => "[%p] %m at line %l, near '%r'. (Severity: %s)\n", |
1020
|
|
|
|
|
|
|
10 => "%m at line %l, column %c.\n %p (Severity: %s)\n%d\n", |
1021
|
|
|
|
|
|
|
11 => "%m at line %l, near '%r'.\n %p (Severity: %s)\n%d\n", |
1022
|
|
|
|
|
|
|
); |
1023
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
Readonly::Scalar our $DEFAULT_VERBOSITY => 4; |
1025
|
|
|
|
|
|
|
Readonly::Scalar our $DEFAULT_VERBOSITY_WITH_FILE_NAME => 5; |
1026
|
|
|
|
|
|
|
Readonly::Scalar my $DEFAULT_FORMAT => $FORMAT_OF{$DEFAULT_VERBOSITY}; |
1027
|
|
|
|
|
|
|
|
1028
|
|
|
|
|
|
|
sub is_valid_numeric_verbosity { |
1029
|
2921
|
|
|
2921
|
1
|
8668
|
my ($verbosity) = @_; |
1030
|
|
|
|
|
|
|
|
1031
|
2921
|
|
|
|
|
15268
|
return exists $FORMAT_OF{$verbosity}; |
1032
|
|
|
|
|
|
|
} |
1033
|
|
|
|
|
|
|
|
1034
|
|
|
|
|
|
|
sub verbosity_to_format { |
1035
|
20
|
|
|
20
|
1
|
45
|
my ($verbosity) = @_; |
1036
|
20
|
100
|
|
|
|
68
|
return $DEFAULT_FORMAT if not defined $verbosity; |
1037
|
19
|
100
|
66
|
|
|
52
|
return $FORMAT_OF{abs int $verbosity} || $DEFAULT_FORMAT if is_integer($verbosity); |
1038
|
17
|
|
|
|
|
51
|
return interpolate( $verbosity ); #Otherwise, treat as a format spec |
1039
|
|
|
|
|
|
|
} |
1040
|
|
|
|
|
|
|
|
1041
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
1042
|
|
|
|
|
|
|
|
1043
|
|
|
|
|
|
|
Readonly::Hash my %SEVERITY_NUMBER_OF => ( |
1044
|
|
|
|
|
|
|
gentle => 5, |
1045
|
|
|
|
|
|
|
stern => 4, |
1046
|
|
|
|
|
|
|
harsh => 3, |
1047
|
|
|
|
|
|
|
cruel => 2, |
1048
|
|
|
|
|
|
|
brutal => 1, |
1049
|
|
|
|
|
|
|
); |
1050
|
|
|
|
|
|
|
|
1051
|
|
|
|
|
|
|
Readonly::Array our @SEVERITY_NAMES => #This is exported! |
1052
|
|
|
|
|
|
|
sort |
1053
|
|
|
|
|
|
|
{ $SEVERITY_NUMBER_OF{$a} <=> $SEVERITY_NUMBER_OF{$b} } |
1054
|
|
|
|
|
|
|
keys %SEVERITY_NUMBER_OF; |
1055
|
|
|
|
|
|
|
|
1056
|
|
|
|
|
|
|
sub severity_to_number { |
1057
|
871
|
|
|
871
|
1
|
1668
|
my ($severity) = @_; |
1058
|
871
|
100
|
|
|
|
1986
|
return _normalize_severity( $severity ) if is_integer( $severity ); |
1059
|
6
|
|
|
|
|
48
|
my $severity_number = $SEVERITY_NUMBER_OF{lc $severity}; |
1060
|
|
|
|
|
|
|
|
1061
|
6
|
100
|
|
|
|
80
|
if ( not defined $severity_number ) { |
1062
|
1
|
|
|
|
|
9
|
throw_generic qq{Invalid severity: "$severity"}; |
1063
|
|
|
|
|
|
|
} |
1064
|
|
|
|
|
|
|
|
1065
|
5
|
|
|
|
|
21
|
return $severity_number; |
1066
|
|
|
|
|
|
|
} |
1067
|
|
|
|
|
|
|
|
1068
|
|
|
|
|
|
|
sub _normalize_severity { |
1069
|
865
|
|
50
|
865
|
|
2281
|
my $s = shift || return $SEVERITY_HIGHEST; |
1070
|
865
|
50
|
|
|
|
2167
|
$s = $s > $SEVERITY_HIGHEST ? $SEVERITY_HIGHEST : $s; |
1071
|
865
|
50
|
|
|
|
1879
|
$s = $s < $SEVERITY_LOWEST ? $SEVERITY_LOWEST : $s; |
1072
|
865
|
|
|
|
|
2292
|
return $s; |
1073
|
|
|
|
|
|
|
} |
1074
|
|
|
|
|
|
|
|
1075
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
1076
|
|
|
|
|
|
|
|
1077
|
|
|
|
|
|
|
Readonly::Array my @SKIP_DIR => qw( CVS RCS .svn _darcs {arch} .bzr .cdv .git .hg .pc _build blib ); |
1078
|
|
|
|
|
|
|
Readonly::Hash my %SKIP_DIR => hashify( @SKIP_DIR ); |
1079
|
|
|
|
|
|
|
|
1080
|
|
|
|
|
|
|
sub all_perl_files { |
1081
|
1
|
|
|
1
|
1
|
30
|
my @arg = @_; |
1082
|
1
|
|
|
|
|
3
|
my @code_files; |
1083
|
|
|
|
|
|
|
|
1084
|
|
|
|
|
|
|
# The old code did a breadth-first search (documentation to the |
1085
|
|
|
|
|
|
|
# contrary notwithstanding,) whereas File::Find does depth-first. So |
1086
|
|
|
|
|
|
|
# there appears to be no way to use File::Find without changing the |
1087
|
|
|
|
|
|
|
# order in which the files are returned. |
1088
|
|
|
|
|
|
|
File::Find::find( { |
1089
|
|
|
|
|
|
|
wanted => sub { |
1090
|
163
|
50
|
66
|
163
|
|
3376
|
if ( -d && $SKIP_DIR{$_} ) { |
|
|
100
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
1091
|
0
|
|
|
|
|
0
|
$File::Find::prune = 1; |
1092
|
|
|
|
|
|
|
} elsif ( -f && ! _is_backup( $_ ) && _is_perl( $_ ) ) { |
1093
|
145
|
|
|
|
|
309
|
push @code_files, $File::Find::name; |
1094
|
|
|
|
|
|
|
} |
1095
|
163
|
|
|
|
|
2921
|
return; |
1096
|
|
|
|
|
|
|
}, |
1097
|
1
|
|
|
|
|
148
|
untaint => 1, |
1098
|
|
|
|
|
|
|
}, |
1099
|
|
|
|
|
|
|
@arg, |
1100
|
|
|
|
|
|
|
); |
1101
|
|
|
|
|
|
|
|
1102
|
|
|
|
|
|
|
# Use File::Spec->abs2rel() to get rid of leading './' or other OS |
1103
|
|
|
|
|
|
|
# equivalent on relative filenames. |
1104
|
|
|
|
|
|
|
# Use map {} to get rid of leading './', or other OS equivalent |
1105
|
1
|
50
|
|
|
|
10
|
return ( map { File::Spec->file_name_is_absolute( $_ ) ? |
|
145
|
|
|
|
|
9026
|
|
1106
|
|
|
|
|
|
|
$_ : File::Spec->abs2rel( $_ ) } @code_files ); |
1107
|
|
|
|
|
|
|
} |
1108
|
|
|
|
|
|
|
|
1109
|
|
|
|
|
|
|
|
1110
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
1111
|
|
|
|
|
|
|
# Decide if it's some sort of backup file |
1112
|
|
|
|
|
|
|
|
1113
|
|
|
|
|
|
|
sub _is_backup { |
1114
|
152
|
|
|
152
|
|
2289
|
my ($file) = @_; |
1115
|
152
|
100
|
|
|
|
674
|
return 1 if $file =~ m{ (?: [.] swp | [.] bak | ~ ) \z}xms; |
1116
|
149
|
100
|
|
|
|
349
|
return 1 if $file =~ m{ \A [#] .+ [#] \z}xms; |
1117
|
148
|
|
|
|
|
516
|
return; |
1118
|
|
|
|
|
|
|
} |
1119
|
|
|
|
|
|
|
|
1120
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
1121
|
|
|
|
|
|
|
# Returns true if the argument ends with a perl-ish file |
1122
|
|
|
|
|
|
|
# extension, or if it has a shebang-line containing 'perl' This |
1123
|
|
|
|
|
|
|
# subroutine was also poached from Test::Perl::Critic |
1124
|
|
|
|
|
|
|
|
1125
|
|
|
|
|
|
|
sub _is_perl { |
1126
|
165
|
|
|
165
|
|
13084
|
my ($file) = @_; |
1127
|
|
|
|
|
|
|
|
1128
|
|
|
|
|
|
|
#Check filename extensions |
1129
|
165
|
100
|
|
|
|
807
|
return 1 if $file =~ m{ [.] (?: PL | p[lm] | psgi | t ) \z}xms; |
1130
|
|
|
|
|
|
|
|
1131
|
|
|
|
|
|
|
#Check for shebang |
1132
|
15
|
100
|
|
|
|
575
|
open my $fh, '<', $file or return; |
1133
|
9
|
|
|
|
|
124
|
my $first = <$fh>; |
1134
|
9
|
50
|
|
|
|
100
|
close $fh or throw_generic "unable to close $file: $OS_ERROR"; |
1135
|
|
|
|
|
|
|
|
1136
|
9
|
100
|
66
|
|
|
124
|
return 1 if defined $first && ( $first =~ m{ \A [#]!.*perl }xms ); |
1137
|
3
|
|
|
|
|
29
|
return; |
1138
|
|
|
|
|
|
|
} |
1139
|
|
|
|
|
|
|
|
1140
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
1141
|
|
|
|
|
|
|
|
1142
|
|
|
|
|
|
|
sub shebang_line { |
1143
|
2797
|
|
|
2797
|
1
|
9055
|
my $doc = shift; |
1144
|
2797
|
|
|
|
|
13018
|
my $first_element = $doc->first_element(); |
1145
|
2797
|
50
|
|
|
|
17098
|
return if not $first_element; |
1146
|
2797
|
100
|
|
|
|
16761
|
return if not $first_element->isa('PPI::Token::Comment'); |
1147
|
47
|
|
|
|
|
248
|
my $location = $first_element->location(); |
1148
|
47
|
50
|
|
|
|
1813
|
return if !$location; |
1149
|
|
|
|
|
|
|
# The shebang must be the first two characters in the file, according to |
1150
|
|
|
|
|
|
|
# http://en.wikipedia.org/wiki/Shebang_(Unix) |
1151
|
47
|
50
|
|
|
|
182
|
return if $location->[0] != 1; # line number |
1152
|
47
|
50
|
|
|
|
148
|
return if $location->[1] != 1; # column number |
1153
|
47
|
|
|
|
|
144
|
my $shebang = $first_element->content; |
1154
|
47
|
100
|
|
|
|
350
|
return if $shebang !~ m{ \A [#]! }xms; |
1155
|
27
|
|
|
|
|
153
|
return $shebang; |
1156
|
|
|
|
|
|
|
} |
1157
|
|
|
|
|
|
|
|
1158
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
1159
|
|
|
|
|
|
|
|
1160
|
|
|
|
|
|
|
sub words_from_string { |
1161
|
37172
|
|
|
37172
|
1
|
59781
|
my $str = shift; |
1162
|
|
|
|
|
|
|
|
1163
|
37172
|
|
|
|
|
131313
|
return split q{ }, $str; # This must be a literal space, not $SPACE |
1164
|
|
|
|
|
|
|
} |
1165
|
|
|
|
|
|
|
|
1166
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
1167
|
|
|
|
|
|
|
|
1168
|
|
|
|
|
|
|
Readonly::Hash my %ASSIGNMENT_OPERATORS => hashify( qw( = **= += -= .= *= /= %= x= &= |= ^= <<= >>= &&= ||= //= ) ); |
1169
|
|
|
|
|
|
|
|
1170
|
|
|
|
|
|
|
sub is_assignment_operator { |
1171
|
257
|
|
|
257
|
1
|
16603
|
my $elem = shift; |
1172
|
|
|
|
|
|
|
|
1173
|
257
|
|
|
|
|
981
|
return $ASSIGNMENT_OPERATORS{ $elem }; |
1174
|
|
|
|
|
|
|
} |
1175
|
|
|
|
|
|
|
|
1176
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
1177
|
|
|
|
|
|
|
|
1178
|
|
|
|
|
|
|
sub is_unchecked_call { |
1179
|
167
|
|
|
167
|
1
|
5468
|
my ( $elem, $autodie_modules ) = @_; |
1180
|
|
|
|
|
|
|
|
1181
|
167
|
100
|
|
|
|
360
|
return if not is_function_call( $elem ); |
1182
|
|
|
|
|
|
|
|
1183
|
|
|
|
|
|
|
# check to see if there's an '=' or 'unless' or something before this. |
1184
|
165
|
100
|
|
|
|
434
|
if( my $sib = $elem->sprevious_sibling() ){ |
1185
|
68
|
50
|
|
|
|
2043
|
return if $sib; |
1186
|
|
|
|
|
|
|
} |
1187
|
|
|
|
|
|
|
|
1188
|
|
|
|
|
|
|
|
1189
|
97
|
50
|
|
|
|
1821
|
if( my $statement = $elem->statement() ){ |
1190
|
|
|
|
|
|
|
|
1191
|
|
|
|
|
|
|
# "open or die" is OK. |
1192
|
|
|
|
|
|
|
# We can't check snext_sibling for 'or' since the next siblings are an |
1193
|
|
|
|
|
|
|
# unknown number of arguments to the system call. Instead, check all of |
1194
|
|
|
|
|
|
|
# the elements to this statement to see if we find 'or' or '||'. |
1195
|
|
|
|
|
|
|
|
1196
|
|
|
|
|
|
|
my $or_operators = sub { |
1197
|
657
|
|
|
657
|
|
6877
|
my (undef, $elem) = @_; ## no critic(Variables::ProhibitReusedNames) |
1198
|
657
|
100
|
|
|
|
2087
|
return if not $elem->isa('PPI::Token::Operator'); |
1199
|
68
|
100
|
100
|
|
|
196
|
return if $elem ne q{or} && $elem ne q{||}; |
1200
|
27
|
|
|
|
|
575
|
return 1; |
1201
|
97
|
|
|
|
|
1650
|
}; |
1202
|
|
|
|
|
|
|
|
1203
|
97
|
100
|
|
|
|
317
|
return if $statement->find( $or_operators ); |
1204
|
|
|
|
|
|
|
|
1205
|
|
|
|
|
|
|
|
1206
|
70
|
50
|
|
|
|
801
|
if( my $parent = $elem->statement()->parent() ){ |
1207
|
|
|
|
|
|
|
|
1208
|
|
|
|
|
|
|
# Check if we're in an if( open ) {good} else {bad} condition |
1209
|
70
|
100
|
|
|
|
1394
|
return if $parent->isa('PPI::Structure::Condition'); |
1210
|
|
|
|
|
|
|
|
1211
|
|
|
|
|
|
|
# Return val could be captured in data structure and checked later |
1212
|
66
|
50
|
|
|
|
278
|
return if $parent->isa('PPI::Structure::Constructor'); |
1213
|
|
|
|
|
|
|
|
1214
|
|
|
|
|
|
|
# "die if not ( open() )" - It's in list context. |
1215
|
66
|
100
|
|
|
|
376
|
if ( $parent->isa('PPI::Structure::List') ) { |
1216
|
6
|
100
|
|
|
|
44
|
if( my $uncle = $parent->sprevious_sibling() ){ |
1217
|
1
|
50
|
|
|
|
41
|
return if $uncle; |
1218
|
|
|
|
|
|
|
} |
1219
|
|
|
|
|
|
|
} |
1220
|
|
|
|
|
|
|
} |
1221
|
|
|
|
|
|
|
} |
1222
|
|
|
|
|
|
|
|
1223
|
65
|
100
|
|
|
|
299
|
return if _is_fatal($elem, $autodie_modules); |
1224
|
|
|
|
|
|
|
|
1225
|
|
|
|
|
|
|
# Otherwise, return. this system call is unchecked. |
1226
|
30
|
|
|
|
|
161
|
return 1; |
1227
|
|
|
|
|
|
|
} |
1228
|
|
|
|
|
|
|
|
1229
|
|
|
|
|
|
|
# Based upon autodie 2.10. |
1230
|
|
|
|
|
|
|
Readonly::Hash my %AUTODIE_PARAMETER_TO_AFFECTED_BUILTINS_MAP => ( |
1231
|
|
|
|
|
|
|
# Map builtins to themselves. |
1232
|
|
|
|
|
|
|
( |
1233
|
|
|
|
|
|
|
map { $_ => { hashify( $_ ) } } |
1234
|
|
|
|
|
|
|
qw< |
1235
|
|
|
|
|
|
|
accept bind binmode chdir chmod close closedir connect |
1236
|
|
|
|
|
|
|
dbmclose dbmopen exec fcntl fileno flock fork getsockopt ioctl |
1237
|
|
|
|
|
|
|
link listen mkdir msgctl msgget msgrcv msgsnd open opendir |
1238
|
|
|
|
|
|
|
pipe read readlink recv rename rmdir seek semctl semget semop |
1239
|
|
|
|
|
|
|
send setsockopt shmctl shmget shmread shutdown socketpair |
1240
|
|
|
|
|
|
|
symlink sysopen sysread sysseek system syswrite truncate umask |
1241
|
|
|
|
|
|
|
unlink |
1242
|
|
|
|
|
|
|
> |
1243
|
|
|
|
|
|
|
), |
1244
|
|
|
|
|
|
|
|
1245
|
|
|
|
|
|
|
# Generate these using tools/dump-autodie-tag-contents |
1246
|
|
|
|
|
|
|
':threads' => { hashify( qw< fork > ) }, |
1247
|
|
|
|
|
|
|
':system' => { hashify( qw< exec system > ) }, |
1248
|
|
|
|
|
|
|
':dbm' => { hashify( qw< dbmclose dbmopen > ) }, |
1249
|
|
|
|
|
|
|
':semaphore' => { hashify( qw< semctl semget semop > ) }, |
1250
|
|
|
|
|
|
|
':shm' => { hashify( qw< shmctl shmget shmread > ) }, |
1251
|
|
|
|
|
|
|
':msg' => { hashify( qw< msgctl msgget msgrcv msgsnd > ) }, |
1252
|
|
|
|
|
|
|
':file' => { |
1253
|
|
|
|
|
|
|
hashify( |
1254
|
|
|
|
|
|
|
qw< |
1255
|
|
|
|
|
|
|
binmode chmod close fcntl fileno flock ioctl open sysopen |
1256
|
|
|
|
|
|
|
truncate |
1257
|
|
|
|
|
|
|
> |
1258
|
|
|
|
|
|
|
) |
1259
|
|
|
|
|
|
|
}, |
1260
|
|
|
|
|
|
|
':filesys' => { |
1261
|
|
|
|
|
|
|
hashify( |
1262
|
|
|
|
|
|
|
qw< |
1263
|
|
|
|
|
|
|
chdir closedir link mkdir opendir readlink rename rmdir |
1264
|
|
|
|
|
|
|
symlink umask unlink |
1265
|
|
|
|
|
|
|
> |
1266
|
|
|
|
|
|
|
) |
1267
|
|
|
|
|
|
|
}, |
1268
|
|
|
|
|
|
|
':ipc' => { |
1269
|
|
|
|
|
|
|
hashify( |
1270
|
|
|
|
|
|
|
qw< |
1271
|
|
|
|
|
|
|
msgctl msgget msgrcv msgsnd pipe semctl semget semop shmctl |
1272
|
|
|
|
|
|
|
shmget shmread |
1273
|
|
|
|
|
|
|
> |
1274
|
|
|
|
|
|
|
) |
1275
|
|
|
|
|
|
|
}, |
1276
|
|
|
|
|
|
|
':socket' => { |
1277
|
|
|
|
|
|
|
hashify( |
1278
|
|
|
|
|
|
|
qw< |
1279
|
|
|
|
|
|
|
accept bind connect getsockopt listen recv send setsockopt |
1280
|
|
|
|
|
|
|
shutdown socketpair |
1281
|
|
|
|
|
|
|
> |
1282
|
|
|
|
|
|
|
) |
1283
|
|
|
|
|
|
|
}, |
1284
|
|
|
|
|
|
|
':io' => { |
1285
|
|
|
|
|
|
|
hashify( |
1286
|
|
|
|
|
|
|
qw< |
1287
|
|
|
|
|
|
|
accept bind binmode chdir chmod close closedir connect |
1288
|
|
|
|
|
|
|
dbmclose dbmopen fcntl fileno flock getsockopt ioctl link |
1289
|
|
|
|
|
|
|
listen mkdir msgctl msgget msgrcv msgsnd open opendir pipe |
1290
|
|
|
|
|
|
|
read readlink recv rename rmdir seek semctl semget semop send |
1291
|
|
|
|
|
|
|
setsockopt shmctl shmget shmread shutdown socketpair symlink |
1292
|
|
|
|
|
|
|
sysopen sysread sysseek syswrite truncate umask unlink |
1293
|
|
|
|
|
|
|
> |
1294
|
|
|
|
|
|
|
) |
1295
|
|
|
|
|
|
|
}, |
1296
|
|
|
|
|
|
|
':default' => { |
1297
|
|
|
|
|
|
|
hashify( |
1298
|
|
|
|
|
|
|
qw< |
1299
|
|
|
|
|
|
|
accept bind binmode chdir chmod close closedir connect |
1300
|
|
|
|
|
|
|
dbmclose dbmopen fcntl fileno flock fork getsockopt ioctl link |
1301
|
|
|
|
|
|
|
listen mkdir msgctl msgget msgrcv msgsnd open opendir pipe |
1302
|
|
|
|
|
|
|
read readlink recv rename rmdir seek semctl semget semop send |
1303
|
|
|
|
|
|
|
setsockopt shmctl shmget shmread shutdown socketpair symlink |
1304
|
|
|
|
|
|
|
sysopen sysread sysseek syswrite truncate umask unlink |
1305
|
|
|
|
|
|
|
> |
1306
|
|
|
|
|
|
|
) |
1307
|
|
|
|
|
|
|
}, |
1308
|
|
|
|
|
|
|
':all' => { |
1309
|
|
|
|
|
|
|
hashify( |
1310
|
|
|
|
|
|
|
qw< |
1311
|
|
|
|
|
|
|
accept bind binmode chdir chmod close closedir connect |
1312
|
|
|
|
|
|
|
dbmclose dbmopen exec fcntl fileno flock fork getsockopt ioctl |
1313
|
|
|
|
|
|
|
link listen mkdir msgctl msgget msgrcv msgsnd open opendir |
1314
|
|
|
|
|
|
|
pipe read readlink recv rename rmdir seek semctl semget semop |
1315
|
|
|
|
|
|
|
send setsockopt shmctl shmget shmread shutdown socketpair |
1316
|
|
|
|
|
|
|
symlink sysopen sysread sysseek system syswrite truncate umask |
1317
|
|
|
|
|
|
|
unlink |
1318
|
|
|
|
|
|
|
> |
1319
|
|
|
|
|
|
|
) |
1320
|
|
|
|
|
|
|
}, |
1321
|
|
|
|
|
|
|
); |
1322
|
|
|
|
|
|
|
|
1323
|
|
|
|
|
|
|
sub _is_fatal { |
1324
|
65
|
|
|
65
|
|
133
|
my ( $elem, $autodie_modules ) = @_; |
1325
|
|
|
|
|
|
|
|
1326
|
65
|
|
|
|
|
224
|
my $top = $elem->top(); |
1327
|
65
|
50
|
|
|
|
911
|
return if not $top->isa('PPI::Document'); |
1328
|
|
|
|
|
|
|
|
1329
|
65
|
|
|
|
|
157
|
my $includes = $top->find('PPI::Statement::Include'); |
1330
|
65
|
100
|
|
|
|
47370
|
return if not $includes; |
1331
|
|
|
|
|
|
|
|
1332
|
45
|
|
|
|
|
81
|
for my $include (@{$includes}) { |
|
45
|
|
|
|
|
118
|
|
1333
|
49
|
100
|
|
|
|
280
|
next if 'use' ne $include->type(); |
1334
|
|
|
|
|
|
|
|
1335
|
47
|
100
|
100
|
|
|
1254
|
if ('Fatal' eq $include->module()) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
1336
|
18
|
|
|
|
|
447
|
my @args = parse_arg_list($include->schild(1)); |
1337
|
18
|
|
|
|
|
46
|
foreach my $arg (@args) { |
1338
|
18
|
100
|
66
|
|
|
134
|
return $TRUE if $arg->[0]->isa('PPI::Token::Quote') && $elem eq $arg->[0]->string(); |
1339
|
|
|
|
|
|
|
} |
1340
|
|
|
|
|
|
|
} |
1341
|
|
|
|
|
|
|
elsif ('Fatal::Exception' eq $include->module()) { |
1342
|
6
|
|
|
|
|
304
|
my @args = parse_arg_list($include->schild(1)); |
1343
|
6
|
|
|
|
|
16
|
shift @args; # skip exception class name |
1344
|
6
|
|
|
|
|
29
|
foreach my $arg (@args) { |
1345
|
6
|
50
|
33
|
|
|
57
|
return $TRUE if $arg->[0]->isa('PPI::Token::Quote') && $elem eq $arg->[0]->string(); |
1346
|
|
|
|
|
|
|
} |
1347
|
|
|
|
|
|
|
} |
1348
|
5
|
50
|
|
5
|
|
15
|
elsif ($include->pragma eq 'autodie' || any {$_ eq $include->module()} @{$autodie_modules || []}) { |
|
5
|
|
|
|
|
410
|
|
1349
|
19
|
|
|
|
|
1394
|
return _is_covered_by_autodie($elem, $include); |
1350
|
|
|
|
|
|
|
} |
1351
|
|
|
|
|
|
|
} |
1352
|
|
|
|
|
|
|
|
1353
|
6
|
|
|
|
|
169
|
return; |
1354
|
|
|
|
|
|
|
} |
1355
|
|
|
|
|
|
|
|
1356
|
|
|
|
|
|
|
sub _is_covered_by_autodie { |
1357
|
19
|
|
|
19
|
|
48
|
my ($elem, $include) = @_; |
1358
|
|
|
|
|
|
|
|
1359
|
19
|
|
|
|
|
50
|
my $autodie = $include->schild(1); |
1360
|
19
|
|
|
|
|
292
|
my @args = parse_arg_list($autodie); |
1361
|
19
|
|
|
|
|
62
|
my $first_arg = first_arg($autodie); |
1362
|
|
|
|
|
|
|
|
1363
|
|
|
|
|
|
|
# The first argument to any `use` pragma could be a version number. |
1364
|
|
|
|
|
|
|
# If so, then we just discard it. We only want the arguments after it. |
1365
|
19
|
100
|
66
|
|
|
133
|
if ($first_arg and $first_arg->isa('PPI::Token::Number')){ shift @args }; |
|
2
|
|
|
|
|
4
|
|
1366
|
|
|
|
|
|
|
|
1367
|
19
|
100
|
|
|
|
60
|
if (@args) { |
1368
|
9
|
|
|
|
|
27
|
foreach my $arg (@args) { |
1369
|
|
|
|
|
|
|
my $builtins = |
1370
|
|
|
|
|
|
|
$AUTODIE_PARAMETER_TO_AFFECTED_BUILTINS_MAP{ |
1371
|
10
|
|
|
|
|
49
|
$arg->[0]->string |
1372
|
|
|
|
|
|
|
}; |
1373
|
|
|
|
|
|
|
|
1374
|
10
|
100
|
66
|
|
|
191
|
return $TRUE if $builtins and $builtins->{$elem->content()}; |
1375
|
|
|
|
|
|
|
} |
1376
|
|
|
|
|
|
|
} |
1377
|
|
|
|
|
|
|
else { |
1378
|
|
|
|
|
|
|
my $builtins = |
1379
|
10
|
|
|
|
|
61
|
$AUTODIE_PARAMETER_TO_AFFECTED_BUILTINS_MAP{':default'}; |
1380
|
|
|
|
|
|
|
|
1381
|
10
|
50
|
33
|
|
|
110
|
return $TRUE if $builtins and $builtins->{$elem->content()}; |
1382
|
|
|
|
|
|
|
} |
1383
|
|
|
|
|
|
|
|
1384
|
4
|
|
|
|
|
65
|
return; |
1385
|
|
|
|
|
|
|
} |
1386
|
|
|
|
|
|
|
|
1387
|
|
|
|
|
|
|
1; |
1388
|
|
|
|
|
|
|
|
1389
|
|
|
|
|
|
|
__END__ |
1390
|
|
|
|
|
|
|
|
1391
|
|
|
|
|
|
|
=pod |
1392
|
|
|
|
|
|
|
|
1393
|
|
|
|
|
|
|
=head1 NAME |
1394
|
|
|
|
|
|
|
|
1395
|
|
|
|
|
|
|
Perl::Critic::Utils - General utility subroutines and constants for Perl::Critic and derivative distributions. |
1396
|
|
|
|
|
|
|
|
1397
|
|
|
|
|
|
|
|
1398
|
|
|
|
|
|
|
=head1 DESCRIPTION |
1399
|
|
|
|
|
|
|
|
1400
|
|
|
|
|
|
|
This module provides several static subs and variables that are useful |
1401
|
|
|
|
|
|
|
for developing L<Perl::Critic::Policy|Perl::Critic::Policy> |
1402
|
|
|
|
|
|
|
subclasses. Unless you are writing Policy modules, you probably don't |
1403
|
|
|
|
|
|
|
care about this package. |
1404
|
|
|
|
|
|
|
|
1405
|
|
|
|
|
|
|
|
1406
|
|
|
|
|
|
|
=head1 INTERFACE SUPPORT |
1407
|
|
|
|
|
|
|
|
1408
|
|
|
|
|
|
|
This is considered to be a public module. Any changes to its |
1409
|
|
|
|
|
|
|
interface will go through a deprecation cycle. |
1410
|
|
|
|
|
|
|
|
1411
|
|
|
|
|
|
|
|
1412
|
|
|
|
|
|
|
=head1 IMPORTABLE SUBS |
1413
|
|
|
|
|
|
|
|
1414
|
|
|
|
|
|
|
=over |
1415
|
|
|
|
|
|
|
|
1416
|
|
|
|
|
|
|
=item C<find_keywords( $doc, $keyword )> |
1417
|
|
|
|
|
|
|
|
1418
|
|
|
|
|
|
|
B<DEPRECATED:> Since version 0.11, every Policy is evaluated at each |
1419
|
|
|
|
|
|
|
element of the document. So you shouldn't need to go looking for a |
1420
|
|
|
|
|
|
|
particular keyword. If you I<do> want to use this, please import it |
1421
|
|
|
|
|
|
|
via the C<:deprecated> tag, rather than directly, to mark the module |
1422
|
|
|
|
|
|
|
as needing updating. |
1423
|
|
|
|
|
|
|
|
1424
|
|
|
|
|
|
|
Given a L<PPI::Document|PPI::Document> as C<$doc>, returns a reference |
1425
|
|
|
|
|
|
|
to an array containing all the L<PPI::Token::Word|PPI::Token::Word> |
1426
|
|
|
|
|
|
|
elements that match C<$keyword>. This can be used to find any |
1427
|
|
|
|
|
|
|
built-in function, method call, bareword, or reserved keyword. It |
1428
|
|
|
|
|
|
|
will not match variables, subroutine names, literal strings, numbers, |
1429
|
|
|
|
|
|
|
or symbols. If the document doesn't contain any matches, returns |
1430
|
|
|
|
|
|
|
undef. |
1431
|
|
|
|
|
|
|
|
1432
|
|
|
|
|
|
|
=item C<is_assignment_operator( $element )> |
1433
|
|
|
|
|
|
|
|
1434
|
|
|
|
|
|
|
Given a L<PPI::Token::Operator|PPI::Token::Operator> or a string, |
1435
|
|
|
|
|
|
|
returns true if that token represents one of the assignment operators |
1436
|
|
|
|
|
|
|
(e.g. C<= &&= ||= //= += -=> etc.). |
1437
|
|
|
|
|
|
|
|
1438
|
|
|
|
|
|
|
=item C<is_perl_global( $element )> |
1439
|
|
|
|
|
|
|
|
1440
|
|
|
|
|
|
|
Given a L<PPI::Token::Symbol|PPI::Token::Symbol> or a string, returns |
1441
|
|
|
|
|
|
|
true if that token represents one of the global variables provided by |
1442
|
|
|
|
|
|
|
the L<English|English> module, or one of the builtin global variables |
1443
|
|
|
|
|
|
|
like C<%SIG>, C<%ENV>, or C<@ARGV>. The sigil on the symbol is |
1444
|
|
|
|
|
|
|
ignored, so things like C<$ARGV> or C<$ENV> will still return true. |
1445
|
|
|
|
|
|
|
|
1446
|
|
|
|
|
|
|
|
1447
|
|
|
|
|
|
|
=item C<is_perl_builtin( $element )> |
1448
|
|
|
|
|
|
|
|
1449
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, |
1450
|
|
|
|
|
|
|
L<PPI::Statement::Sub|PPI::Statement::Sub>, or string, returns true if |
1451
|
|
|
|
|
|
|
that token represents a call to any of the builtin functions. |
1452
|
|
|
|
|
|
|
|
1453
|
|
|
|
|
|
|
|
1454
|
|
|
|
|
|
|
=item C<is_perl_bareword( $element )> |
1455
|
|
|
|
|
|
|
|
1456
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, |
1457
|
|
|
|
|
|
|
L<PPI::Statement::Sub|PPI::Statement::Sub>, or string, returns true if |
1458
|
|
|
|
|
|
|
that token represents a bareword (e.g. "if", "else", "sub", "package"). |
1459
|
|
|
|
|
|
|
|
1460
|
|
|
|
|
|
|
|
1461
|
|
|
|
|
|
|
=item C<is_perl_filehandle( $element )> |
1462
|
|
|
|
|
|
|
|
1463
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, or string, returns true |
1464
|
|
|
|
|
|
|
if that token represents one of the global filehandles (e.g. C<STDIN>, |
1465
|
|
|
|
|
|
|
C<STDERR>, C<STDOUT>, C<ARGV>). Note |
1466
|
|
|
|
|
|
|
that this function will return false if given a filehandle that is |
1467
|
|
|
|
|
|
|
represented as a typeglob (e.g. C<*STDIN>) |
1468
|
|
|
|
|
|
|
|
1469
|
|
|
|
|
|
|
|
1470
|
|
|
|
|
|
|
=item C<is_perl_builtin_with_list_context( $element )> |
1471
|
|
|
|
|
|
|
|
1472
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, |
1473
|
|
|
|
|
|
|
L<PPI::Statement::Sub|PPI::Statement::Sub>, or string, returns true if |
1474
|
|
|
|
|
|
|
that token represents a call to any of the builtin functions |
1475
|
|
|
|
|
|
|
that provide a list context to the following tokens. |
1476
|
|
|
|
|
|
|
|
1477
|
|
|
|
|
|
|
|
1478
|
|
|
|
|
|
|
=item C<is_perl_builtin_with_multiple_arguments( $element )> |
1479
|
|
|
|
|
|
|
|
1480
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, |
1481
|
|
|
|
|
|
|
L<PPI::Statement::Sub|PPI::Statement::Sub>, or string, returns true if |
1482
|
|
|
|
|
|
|
that token represents a call to any of the builtin functions that B<can> |
1483
|
|
|
|
|
|
|
take multiple arguments. |
1484
|
|
|
|
|
|
|
|
1485
|
|
|
|
|
|
|
|
1486
|
|
|
|
|
|
|
=item C<is_perl_builtin_with_no_arguments( $element )> |
1487
|
|
|
|
|
|
|
|
1488
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, |
1489
|
|
|
|
|
|
|
L<PPI::Statement::Sub|PPI::Statement::Sub>, or string, returns true if |
1490
|
|
|
|
|
|
|
that token represents a call to any of the builtin functions that |
1491
|
|
|
|
|
|
|
B<cannot> take any arguments. |
1492
|
|
|
|
|
|
|
|
1493
|
|
|
|
|
|
|
|
1494
|
|
|
|
|
|
|
=item C<is_perl_builtin_with_one_argument( $element )> |
1495
|
|
|
|
|
|
|
|
1496
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, |
1497
|
|
|
|
|
|
|
L<PPI::Statement::Sub|PPI::Statement::Sub>, or string, returns true if |
1498
|
|
|
|
|
|
|
that token represents a call to any of the builtin functions that takes |
1499
|
|
|
|
|
|
|
B<one and only one> argument. |
1500
|
|
|
|
|
|
|
|
1501
|
|
|
|
|
|
|
|
1502
|
|
|
|
|
|
|
=item C<is_perl_builtin_with_optional_argument( $element )> |
1503
|
|
|
|
|
|
|
|
1504
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, |
1505
|
|
|
|
|
|
|
L<PPI::Statement::Sub|PPI::Statement::Sub>, or string, returns true if |
1506
|
|
|
|
|
|
|
that token represents a call to any of the builtin functions that takes |
1507
|
|
|
|
|
|
|
B<no more than one> argument. |
1508
|
|
|
|
|
|
|
|
1509
|
|
|
|
|
|
|
The sets of values for which |
1510
|
|
|
|
|
|
|
C<is_perl_builtin_with_multiple_arguments()>, |
1511
|
|
|
|
|
|
|
C<is_perl_builtin_with_no_arguments()>, |
1512
|
|
|
|
|
|
|
C<is_perl_builtin_with_one_argument()>, and |
1513
|
|
|
|
|
|
|
C<is_perl_builtin_with_optional_argument()> return true are disjoint |
1514
|
|
|
|
|
|
|
and their union is precisely the set of values that |
1515
|
|
|
|
|
|
|
C<is_perl_builtin()> will return true for. |
1516
|
|
|
|
|
|
|
|
1517
|
|
|
|
|
|
|
|
1518
|
|
|
|
|
|
|
=item C<is_perl_builtin_with_zero_and_or_one_arguments( $element )> |
1519
|
|
|
|
|
|
|
|
1520
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, |
1521
|
|
|
|
|
|
|
L<PPI::Statement::Sub|PPI::Statement::Sub>, or string, returns true if |
1522
|
|
|
|
|
|
|
that token represents a call to any of the builtin functions that takes |
1523
|
|
|
|
|
|
|
no and/or one argument. |
1524
|
|
|
|
|
|
|
|
1525
|
|
|
|
|
|
|
Returns true if any of C<is_perl_builtin_with_no_arguments()>, |
1526
|
|
|
|
|
|
|
C<is_perl_builtin_with_one_argument()>, and |
1527
|
|
|
|
|
|
|
C<is_perl_builtin_with_optional_argument()> returns true. |
1528
|
|
|
|
|
|
|
|
1529
|
|
|
|
|
|
|
|
1530
|
|
|
|
|
|
|
=item C<is_qualified_name( $name )> |
1531
|
|
|
|
|
|
|
|
1532
|
|
|
|
|
|
|
Given a string, L<PPI::Token::Word|PPI::Token::Word>, or |
1533
|
|
|
|
|
|
|
L<PPI::Token::Symbol|PPI::Token::Symbol>, answers whether it has a |
1534
|
|
|
|
|
|
|
module component, i.e. contains "::". |
1535
|
|
|
|
|
|
|
|
1536
|
|
|
|
|
|
|
|
1537
|
|
|
|
|
|
|
=item C<precedence_of( $element )> |
1538
|
|
|
|
|
|
|
|
1539
|
|
|
|
|
|
|
Given a L<PPI::Token::Operator|PPI::Token::Operator> or a string, |
1540
|
|
|
|
|
|
|
returns the precedence of the operator, where 1 is the highest |
1541
|
|
|
|
|
|
|
precedence. Returns undef if the precedence can't be determined |
1542
|
|
|
|
|
|
|
(which is usually because it is not an operator). |
1543
|
|
|
|
|
|
|
|
1544
|
|
|
|
|
|
|
|
1545
|
|
|
|
|
|
|
=item C<is_hash_key( $element )> |
1546
|
|
|
|
|
|
|
|
1547
|
|
|
|
|
|
|
Given a L<PPI::Element|PPI::Element>, returns true if the element is a |
1548
|
|
|
|
|
|
|
literal hash key. PPI doesn't distinguish between regular barewords |
1549
|
|
|
|
|
|
|
(like keywords or subroutine calls) and barewords in hash subscripts |
1550
|
|
|
|
|
|
|
(which are considered literal). So this subroutine is useful if your |
1551
|
|
|
|
|
|
|
Policy is searching for L<PPI::Token::Word|PPI::Token::Word> elements |
1552
|
|
|
|
|
|
|
and you want to filter out the hash subscript variety. In both of the |
1553
|
|
|
|
|
|
|
following examples, "foo" is considered a hash key: |
1554
|
|
|
|
|
|
|
|
1555
|
|
|
|
|
|
|
$hash1{foo} = 1; |
1556
|
|
|
|
|
|
|
%hash2 = (foo => 1); |
1557
|
|
|
|
|
|
|
|
1558
|
|
|
|
|
|
|
But if the bareword is followed by an argument list, then perl treats |
1559
|
|
|
|
|
|
|
it as a function call. So in these examples, "foo" is B<not> |
1560
|
|
|
|
|
|
|
considered a hash key: |
1561
|
|
|
|
|
|
|
|
1562
|
|
|
|
|
|
|
$hash1{ foo() } = 1; |
1563
|
|
|
|
|
|
|
&hash2 = (foo() => 1); |
1564
|
|
|
|
|
|
|
|
1565
|
|
|
|
|
|
|
|
1566
|
|
|
|
|
|
|
=item C<is_included_module_name( $element )> |
1567
|
|
|
|
|
|
|
|
1568
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, returns true if the |
1569
|
|
|
|
|
|
|
element is the name of a module that is being included via C<use>, |
1570
|
|
|
|
|
|
|
C<require>, or C<no>. |
1571
|
|
|
|
|
|
|
|
1572
|
|
|
|
|
|
|
|
1573
|
|
|
|
|
|
|
=item C<is_integer( $value )> |
1574
|
|
|
|
|
|
|
|
1575
|
|
|
|
|
|
|
Answers whether the parameter, as a string, looks like an integral |
1576
|
|
|
|
|
|
|
value. |
1577
|
|
|
|
|
|
|
|
1578
|
|
|
|
|
|
|
|
1579
|
|
|
|
|
|
|
=item C<is_class_name( $element )> |
1580
|
|
|
|
|
|
|
|
1581
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, returns true if the |
1582
|
|
|
|
|
|
|
element that immediately follows this element is the dereference |
1583
|
|
|
|
|
|
|
operator "->". When a bareword has a "->" on the B<right> side, it |
1584
|
|
|
|
|
|
|
usually means that it is the name of the class (from which a method is |
1585
|
|
|
|
|
|
|
being called). |
1586
|
|
|
|
|
|
|
|
1587
|
|
|
|
|
|
|
|
1588
|
|
|
|
|
|
|
=item C<is_label_pointer( $element )> |
1589
|
|
|
|
|
|
|
|
1590
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, returns true if the |
1591
|
|
|
|
|
|
|
element is the label in a C<next>, C<last>, C<redo>, or C<goto> |
1592
|
|
|
|
|
|
|
statement. Note this is not the same thing as the label declaration. |
1593
|
|
|
|
|
|
|
|
1594
|
|
|
|
|
|
|
|
1595
|
|
|
|
|
|
|
=item C<is_method_call( $element )> |
1596
|
|
|
|
|
|
|
|
1597
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, returns true if the |
1598
|
|
|
|
|
|
|
element that immediately precedes this element is the dereference |
1599
|
|
|
|
|
|
|
operator "->". When a bareword has a "->" on the B<left> side, it |
1600
|
|
|
|
|
|
|
usually means that it is the name of a method (that is being called |
1601
|
|
|
|
|
|
|
from a class). |
1602
|
|
|
|
|
|
|
|
1603
|
|
|
|
|
|
|
|
1604
|
|
|
|
|
|
|
=item C<is_package_declaration( $element )> |
1605
|
|
|
|
|
|
|
|
1606
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, returns true if the |
1607
|
|
|
|
|
|
|
element is the name of a package that is being declared. |
1608
|
|
|
|
|
|
|
|
1609
|
|
|
|
|
|
|
|
1610
|
|
|
|
|
|
|
=item C<is_subroutine_name( $element )> |
1611
|
|
|
|
|
|
|
|
1612
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word>, returns true if the |
1613
|
|
|
|
|
|
|
element is the name of a subroutine declaration. This is useful for |
1614
|
|
|
|
|
|
|
distinguishing barewords and from function calls from subroutine |
1615
|
|
|
|
|
|
|
declarations. |
1616
|
|
|
|
|
|
|
|
1617
|
|
|
|
|
|
|
|
1618
|
|
|
|
|
|
|
=item C<is_function_call( $element )> |
1619
|
|
|
|
|
|
|
|
1620
|
|
|
|
|
|
|
Given a L<PPI::Token::Word|PPI::Token::Word> returns true if the |
1621
|
|
|
|
|
|
|
element appears to be call to a static function. Specifically, this |
1622
|
|
|
|
|
|
|
function returns true if C<is_hash_key>, C<is_method_call>, |
1623
|
|
|
|
|
|
|
C<is_subroutine_name>, C<is_included_module_name>, |
1624
|
|
|
|
|
|
|
C<is_package_declaration>, C<is_perl_bareword>, C<is_perl_filehandle>, |
1625
|
|
|
|
|
|
|
C<is_label_pointer> and C<is_subroutine_name> all return false for the |
1626
|
|
|
|
|
|
|
given element. |
1627
|
|
|
|
|
|
|
|
1628
|
|
|
|
|
|
|
|
1629
|
|
|
|
|
|
|
=item C<first_arg( $element )> |
1630
|
|
|
|
|
|
|
|
1631
|
|
|
|
|
|
|
Given a L<PPI::Element|PPI::Element> that is presumed to be a function |
1632
|
|
|
|
|
|
|
call (which is usually a L<PPI::Token::Word|PPI::Token::Word>), return |
1633
|
|
|
|
|
|
|
the first argument. This is similar of C<parse_arg_list()> and |
1634
|
|
|
|
|
|
|
follows the same logic. Note that for the code: |
1635
|
|
|
|
|
|
|
|
1636
|
|
|
|
|
|
|
int($x + 0.5) |
1637
|
|
|
|
|
|
|
|
1638
|
|
|
|
|
|
|
this function will return just the C<$x>, not the whole expression. |
1639
|
|
|
|
|
|
|
This is different from the behavior of C<parse_arg_list()>. Another |
1640
|
|
|
|
|
|
|
caveat is: |
1641
|
|
|
|
|
|
|
|
1642
|
|
|
|
|
|
|
int(($x + $y) + 0.5) |
1643
|
|
|
|
|
|
|
|
1644
|
|
|
|
|
|
|
which returns C<($x + $y)> as a |
1645
|
|
|
|
|
|
|
L<PPI::Structure::List|PPI::Structure::List> instance. |
1646
|
|
|
|
|
|
|
|
1647
|
|
|
|
|
|
|
|
1648
|
|
|
|
|
|
|
=item C<parse_arg_list( $element )> |
1649
|
|
|
|
|
|
|
|
1650
|
|
|
|
|
|
|
Given a L<PPI::Element|PPI::Element> that is presumed to be a function |
1651
|
|
|
|
|
|
|
call (which is usually a L<PPI::Token::Word|PPI::Token::Word>), splits |
1652
|
|
|
|
|
|
|
the argument expressions into arrays of tokens. Returns a list |
1653
|
|
|
|
|
|
|
containing references to each of those arrays. This is useful because |
1654
|
|
|
|
|
|
|
parentheses are optional when calling a function, and PPI parses them |
1655
|
|
|
|
|
|
|
very differently. So this method is a poor-man's parse tree of PPI |
1656
|
|
|
|
|
|
|
nodes. It's not bullet-proof because it doesn't respect precedence. |
1657
|
|
|
|
|
|
|
In general, I don't like the way this function works, so don't count |
1658
|
|
|
|
|
|
|
on it to be stable (or even present). |
1659
|
|
|
|
|
|
|
|
1660
|
|
|
|
|
|
|
|
1661
|
|
|
|
|
|
|
=item C<split_nodes_on_comma( @nodes )> |
1662
|
|
|
|
|
|
|
|
1663
|
|
|
|
|
|
|
This has the same return type as C<parse_arg_list()> but expects to be |
1664
|
|
|
|
|
|
|
passed the nodes that represent the interior of a list, like: |
1665
|
|
|
|
|
|
|
|
1666
|
|
|
|
|
|
|
'foo', 1, 2, 'bar' |
1667
|
|
|
|
|
|
|
|
1668
|
|
|
|
|
|
|
|
1669
|
|
|
|
|
|
|
=item C<is_script( $document )> |
1670
|
|
|
|
|
|
|
|
1671
|
|
|
|
|
|
|
B<This subroutine is deprecated and will be removed in a future release.> You |
1672
|
|
|
|
|
|
|
should use the L<Perl::Critic::Document/"is_program()"> method instead. |
1673
|
|
|
|
|
|
|
|
1674
|
|
|
|
|
|
|
|
1675
|
|
|
|
|
|
|
=item C<is_in_void_context( $token )> |
1676
|
|
|
|
|
|
|
|
1677
|
|
|
|
|
|
|
Given a L<PPI::Token|PPI::Token>, answer whether it appears to be in a |
1678
|
|
|
|
|
|
|
void context. |
1679
|
|
|
|
|
|
|
|
1680
|
|
|
|
|
|
|
|
1681
|
|
|
|
|
|
|
=item C<policy_long_name( $policy_name )> |
1682
|
|
|
|
|
|
|
|
1683
|
|
|
|
|
|
|
Given a policy class name in long or short form, return the long form. |
1684
|
|
|
|
|
|
|
|
1685
|
|
|
|
|
|
|
|
1686
|
|
|
|
|
|
|
=item C<policy_short_name( $policy_name )> |
1687
|
|
|
|
|
|
|
|
1688
|
|
|
|
|
|
|
Given a policy class name in long or short form, return the short |
1689
|
|
|
|
|
|
|
form. |
1690
|
|
|
|
|
|
|
|
1691
|
|
|
|
|
|
|
|
1692
|
|
|
|
|
|
|
=item C<all_perl_files( @directories )> |
1693
|
|
|
|
|
|
|
|
1694
|
|
|
|
|
|
|
Given a list of directories, recursively searches through all the |
1695
|
|
|
|
|
|
|
directories (depth first) and returns a list of paths for all the |
1696
|
|
|
|
|
|
|
files that are Perl code files. Any administrative files for CVS or |
1697
|
|
|
|
|
|
|
Subversion are skipped, as are things that look like temporary or |
1698
|
|
|
|
|
|
|
backup files. |
1699
|
|
|
|
|
|
|
|
1700
|
|
|
|
|
|
|
A Perl code file is: |
1701
|
|
|
|
|
|
|
|
1702
|
|
|
|
|
|
|
=over |
1703
|
|
|
|
|
|
|
|
1704
|
|
|
|
|
|
|
=item * Any file that ends in F<.PL>, F<.pl>, F<.pm>, F<.psgi>, or F<.t> |
1705
|
|
|
|
|
|
|
|
1706
|
|
|
|
|
|
|
=item * Any file that has a first line with a shebang containing 'perl' |
1707
|
|
|
|
|
|
|
|
1708
|
|
|
|
|
|
|
=back |
1709
|
|
|
|
|
|
|
|
1710
|
|
|
|
|
|
|
|
1711
|
|
|
|
|
|
|
=item C<severity_to_number( $severity )> |
1712
|
|
|
|
|
|
|
|
1713
|
|
|
|
|
|
|
If C<$severity> is given as an integer, this function returns |
1714
|
|
|
|
|
|
|
C<$severity> but normalized to lie between C<$SEVERITY_LOWEST> and |
1715
|
|
|
|
|
|
|
C<$SEVERITY_HIGHEST>. If C<$severity> is given as a string, this |
1716
|
|
|
|
|
|
|
function returns the corresponding severity number. If the string |
1717
|
|
|
|
|
|
|
doesn't have a corresponding number, this function will throw an |
1718
|
|
|
|
|
|
|
exception. |
1719
|
|
|
|
|
|
|
|
1720
|
|
|
|
|
|
|
|
1721
|
|
|
|
|
|
|
=item C<is_valid_numeric_verbosity( $severity )> |
1722
|
|
|
|
|
|
|
|
1723
|
|
|
|
|
|
|
Answers whether the argument has a translation to a Violation format. |
1724
|
|
|
|
|
|
|
|
1725
|
|
|
|
|
|
|
|
1726
|
|
|
|
|
|
|
=item C<verbosity_to_format( $verbosity_level )> |
1727
|
|
|
|
|
|
|
|
1728
|
|
|
|
|
|
|
Given a verbosity level between 1 and 10, returns the corresponding |
1729
|
|
|
|
|
|
|
predefined format string. These formats are suitable for passing to |
1730
|
|
|
|
|
|
|
the C<set_format> method in |
1731
|
|
|
|
|
|
|
L<Perl::Critic::Violation|Perl::Critic::Violation>. See the |
1732
|
|
|
|
|
|
|
L<perlcritic|perlcritic> documentation for a listing of the predefined |
1733
|
|
|
|
|
|
|
formats. |
1734
|
|
|
|
|
|
|
|
1735
|
|
|
|
|
|
|
|
1736
|
|
|
|
|
|
|
=item C<hashify( @list )> |
1737
|
|
|
|
|
|
|
|
1738
|
|
|
|
|
|
|
Given C<@list>, return a hash where C<@list> is in the keys and each |
1739
|
|
|
|
|
|
|
value is 1. Duplicate values in C<@list> are silently squished. |
1740
|
|
|
|
|
|
|
|
1741
|
|
|
|
|
|
|
|
1742
|
|
|
|
|
|
|
=item C<interpolate( $literal )> |
1743
|
|
|
|
|
|
|
|
1744
|
|
|
|
|
|
|
Given a C<$literal> string that may contain control characters (e.g.. |
1745
|
|
|
|
|
|
|
'\t' '\n'), this function does a double interpolation on the string |
1746
|
|
|
|
|
|
|
and returns it as if it had been declared in double quotes. For |
1747
|
|
|
|
|
|
|
example: |
1748
|
|
|
|
|
|
|
|
1749
|
|
|
|
|
|
|
'foo \t bar \n' ...becomes... "foo \t bar \n" |
1750
|
|
|
|
|
|
|
|
1751
|
|
|
|
|
|
|
|
1752
|
|
|
|
|
|
|
=item C<shebang_line( $document )> |
1753
|
|
|
|
|
|
|
|
1754
|
|
|
|
|
|
|
Given a L<PPI::Document|PPI::Document>, test if it starts with C<#!>. |
1755
|
|
|
|
|
|
|
If so, return that line. Otherwise return undef. |
1756
|
|
|
|
|
|
|
|
1757
|
|
|
|
|
|
|
|
1758
|
|
|
|
|
|
|
=item C<words_from_string( $str )> |
1759
|
|
|
|
|
|
|
|
1760
|
|
|
|
|
|
|
Given config string I<$str>, return all the words from the string. |
1761
|
|
|
|
|
|
|
This is safer than splitting on whitespace. |
1762
|
|
|
|
|
|
|
|
1763
|
|
|
|
|
|
|
|
1764
|
|
|
|
|
|
|
=item C<is_unchecked_call( $element, $autodie_modules )> |
1765
|
|
|
|
|
|
|
|
1766
|
|
|
|
|
|
|
Given a L<PPI::Element|PPI::Element>, test to see if it contains a |
1767
|
|
|
|
|
|
|
function call whose return value is not checked. The second argument |
1768
|
|
|
|
|
|
|
is an array reference of module names which export C<autodie>. The |
1769
|
|
|
|
|
|
|
C<autodie> module is always included in this list by default. |
1770
|
|
|
|
|
|
|
|
1771
|
|
|
|
|
|
|
|
1772
|
|
|
|
|
|
|
=back |
1773
|
|
|
|
|
|
|
|
1774
|
|
|
|
|
|
|
|
1775
|
|
|
|
|
|
|
=head1 IMPORTABLE VARIABLES |
1776
|
|
|
|
|
|
|
|
1777
|
|
|
|
|
|
|
=over |
1778
|
|
|
|
|
|
|
|
1779
|
|
|
|
|
|
|
=item C<$COMMA> |
1780
|
|
|
|
|
|
|
|
1781
|
|
|
|
|
|
|
=item C<$FATCOMMA> |
1782
|
|
|
|
|
|
|
|
1783
|
|
|
|
|
|
|
=item C<$COLON> |
1784
|
|
|
|
|
|
|
|
1785
|
|
|
|
|
|
|
=item C<$SCOLON> |
1786
|
|
|
|
|
|
|
|
1787
|
|
|
|
|
|
|
=item C<$QUOTE> |
1788
|
|
|
|
|
|
|
|
1789
|
|
|
|
|
|
|
=item C<$DQUOTE> |
1790
|
|
|
|
|
|
|
|
1791
|
|
|
|
|
|
|
=item C<$BACKTICK> |
1792
|
|
|
|
|
|
|
|
1793
|
|
|
|
|
|
|
=item C<$PERIOD> |
1794
|
|
|
|
|
|
|
|
1795
|
|
|
|
|
|
|
=item C<$PIPE> |
1796
|
|
|
|
|
|
|
|
1797
|
|
|
|
|
|
|
=item C<$EMPTY> |
1798
|
|
|
|
|
|
|
|
1799
|
|
|
|
|
|
|
=item C<$EQUAL> |
1800
|
|
|
|
|
|
|
|
1801
|
|
|
|
|
|
|
=item C<$SPACE> |
1802
|
|
|
|
|
|
|
|
1803
|
|
|
|
|
|
|
=item C<$SLASH> |
1804
|
|
|
|
|
|
|
|
1805
|
|
|
|
|
|
|
=item C<$BSLASH> |
1806
|
|
|
|
|
|
|
|
1807
|
|
|
|
|
|
|
=item C<$LEFT_PAREN> |
1808
|
|
|
|
|
|
|
|
1809
|
|
|
|
|
|
|
=item C<$RIGHT_PAREN> |
1810
|
|
|
|
|
|
|
|
1811
|
|
|
|
|
|
|
These character constants give clear names to commonly-used strings |
1812
|
|
|
|
|
|
|
that can be hard to read when surrounded by quotes and other |
1813
|
|
|
|
|
|
|
punctuation. Can be imported in one go via the C<:characters> tag. |
1814
|
|
|
|
|
|
|
|
1815
|
|
|
|
|
|
|
=item C<$SEVERITY_HIGHEST> |
1816
|
|
|
|
|
|
|
|
1817
|
|
|
|
|
|
|
=item C<$SEVERITY_HIGH> |
1818
|
|
|
|
|
|
|
|
1819
|
|
|
|
|
|
|
=item C<$SEVERITY_MEDIUM> |
1820
|
|
|
|
|
|
|
|
1821
|
|
|
|
|
|
|
=item C<$SEVERITY_LOW> |
1822
|
|
|
|
|
|
|
|
1823
|
|
|
|
|
|
|
=item C<$SEVERITY_LOWEST> |
1824
|
|
|
|
|
|
|
|
1825
|
|
|
|
|
|
|
These numeric constants define the relative severity of violating each |
1826
|
|
|
|
|
|
|
L<Perl::Critic::Policy|Perl::Critic::Policy>. The C<get_severity> and |
1827
|
|
|
|
|
|
|
C<default_severity> methods of every Policy subclass must return one |
1828
|
|
|
|
|
|
|
of these values. Can be imported via the C<:severities> tag. |
1829
|
|
|
|
|
|
|
|
1830
|
|
|
|
|
|
|
=item C<$DEFAULT_VERBOSITY> |
1831
|
|
|
|
|
|
|
|
1832
|
|
|
|
|
|
|
The default numeric verbosity. |
1833
|
|
|
|
|
|
|
|
1834
|
|
|
|
|
|
|
=item C<$DEFAULT_VERBOSITY_WITH_FILE_NAME> |
1835
|
|
|
|
|
|
|
|
1836
|
|
|
|
|
|
|
The numeric verbosity that corresponds to the format indicated by |
1837
|
|
|
|
|
|
|
C<$DEFAULT_VERBOSITY>, but with the file name prefixed to it. |
1838
|
|
|
|
|
|
|
|
1839
|
|
|
|
|
|
|
=item C<$TRUE> |
1840
|
|
|
|
|
|
|
|
1841
|
|
|
|
|
|
|
=item C<$FALSE> |
1842
|
|
|
|
|
|
|
|
1843
|
|
|
|
|
|
|
These are simple booleans. 1 and 0 respectively. Be mindful of using |
1844
|
|
|
|
|
|
|
these with string equality. C<$FALSE ne $EMPTY>. Can be imported via |
1845
|
|
|
|
|
|
|
the C<:booleans> tag. |
1846
|
|
|
|
|
|
|
|
1847
|
|
|
|
|
|
|
|
1848
|
|
|
|
|
|
|
=back |
1849
|
|
|
|
|
|
|
|
1850
|
|
|
|
|
|
|
|
1851
|
|
|
|
|
|
|
=head1 IMPORT TAGS |
1852
|
|
|
|
|
|
|
|
1853
|
|
|
|
|
|
|
The following groups of functions and constants are available as |
1854
|
|
|
|
|
|
|
parameters to a C<use Perl::Critic::Util> statement. |
1855
|
|
|
|
|
|
|
|
1856
|
|
|
|
|
|
|
=over |
1857
|
|
|
|
|
|
|
|
1858
|
|
|
|
|
|
|
=item C<:all> |
1859
|
|
|
|
|
|
|
|
1860
|
|
|
|
|
|
|
The lot. |
1861
|
|
|
|
|
|
|
|
1862
|
|
|
|
|
|
|
|
1863
|
|
|
|
|
|
|
=item C<:booleans> |
1864
|
|
|
|
|
|
|
|
1865
|
|
|
|
|
|
|
Includes: |
1866
|
|
|
|
|
|
|
C<$TRUE>, C<$FALSE> |
1867
|
|
|
|
|
|
|
|
1868
|
|
|
|
|
|
|
|
1869
|
|
|
|
|
|
|
=item C<:severities> |
1870
|
|
|
|
|
|
|
|
1871
|
|
|
|
|
|
|
Includes: |
1872
|
|
|
|
|
|
|
C<$SEVERITY_HIGHEST>, |
1873
|
|
|
|
|
|
|
C<$SEVERITY_HIGH>, |
1874
|
|
|
|
|
|
|
C<$SEVERITY_MEDIUM>, |
1875
|
|
|
|
|
|
|
C<$SEVERITY_LOW>, |
1876
|
|
|
|
|
|
|
C<$SEVERITY_LOWEST>, |
1877
|
|
|
|
|
|
|
C<@SEVERITY_NAMES> |
1878
|
|
|
|
|
|
|
|
1879
|
|
|
|
|
|
|
|
1880
|
|
|
|
|
|
|
=item C<:characters> |
1881
|
|
|
|
|
|
|
|
1882
|
|
|
|
|
|
|
Includes: |
1883
|
|
|
|
|
|
|
C<$COLON>, |
1884
|
|
|
|
|
|
|
C<$COMMA>, |
1885
|
|
|
|
|
|
|
C<$DQUOTE>, |
1886
|
|
|
|
|
|
|
C<$EMPTY>, |
1887
|
|
|
|
|
|
|
C<$FATCOMMA>, |
1888
|
|
|
|
|
|
|
C<$PERIOD>, |
1889
|
|
|
|
|
|
|
C<$PIPE>, |
1890
|
|
|
|
|
|
|
C<$QUOTE>, |
1891
|
|
|
|
|
|
|
C<$BACKTICK>, |
1892
|
|
|
|
|
|
|
C<$SCOLON>, |
1893
|
|
|
|
|
|
|
C<$SPACE>, |
1894
|
|
|
|
|
|
|
C<$SLASH>, |
1895
|
|
|
|
|
|
|
C<$BSLASH> |
1896
|
|
|
|
|
|
|
C<$LEFT_PAREN> |
1897
|
|
|
|
|
|
|
C<$RIGHT_PAREN> |
1898
|
|
|
|
|
|
|
|
1899
|
|
|
|
|
|
|
|
1900
|
|
|
|
|
|
|
=item C<:classification> |
1901
|
|
|
|
|
|
|
|
1902
|
|
|
|
|
|
|
Includes: |
1903
|
|
|
|
|
|
|
C<is_assignment_operator>, |
1904
|
|
|
|
|
|
|
C<is_class_name>, |
1905
|
|
|
|
|
|
|
C<is_function_call>, |
1906
|
|
|
|
|
|
|
C<is_hash_key>, |
1907
|
|
|
|
|
|
|
C<is_included_module_name>, |
1908
|
|
|
|
|
|
|
C<is_integer>, |
1909
|
|
|
|
|
|
|
C<is_label_pointer>, |
1910
|
|
|
|
|
|
|
C<is_method_call>, |
1911
|
|
|
|
|
|
|
C<is_package_declaration>, |
1912
|
|
|
|
|
|
|
C<is_perl_bareword>, |
1913
|
|
|
|
|
|
|
C<is_perl_builtin>, |
1914
|
|
|
|
|
|
|
C<is_perl_filehandle>, |
1915
|
|
|
|
|
|
|
C<is_perl_global>, |
1916
|
|
|
|
|
|
|
C<is_perl_builtin_with_list_context> |
1917
|
|
|
|
|
|
|
C<is_perl_builtin_with_multiple_arguments> |
1918
|
|
|
|
|
|
|
C<is_perl_builtin_with_no_arguments> |
1919
|
|
|
|
|
|
|
C<is_perl_builtin_with_one_argument> |
1920
|
|
|
|
|
|
|
C<is_perl_builtin_with_optional_argument> |
1921
|
|
|
|
|
|
|
C<is_perl_builtin_with_zero_and_or_one_arguments> |
1922
|
|
|
|
|
|
|
C<is_qualified_name>, |
1923
|
|
|
|
|
|
|
C<is_script>, |
1924
|
|
|
|
|
|
|
C<is_subroutine_name>, |
1925
|
|
|
|
|
|
|
C<is_unchecked_call> |
1926
|
|
|
|
|
|
|
C<is_valid_numeric_verbosity> |
1927
|
|
|
|
|
|
|
|
1928
|
|
|
|
|
|
|
See also L<Perl::Critic::Utils::PPI|Perl::Critic::Utils::PPI>. |
1929
|
|
|
|
|
|
|
|
1930
|
|
|
|
|
|
|
|
1931
|
|
|
|
|
|
|
=item C<:data_conversion> |
1932
|
|
|
|
|
|
|
|
1933
|
|
|
|
|
|
|
Generic manipulation, not having anything specific to do with |
1934
|
|
|
|
|
|
|
Perl::Critic. |
1935
|
|
|
|
|
|
|
|
1936
|
|
|
|
|
|
|
Includes: |
1937
|
|
|
|
|
|
|
C<hashify>, |
1938
|
|
|
|
|
|
|
C<words_from_string>, |
1939
|
|
|
|
|
|
|
C<interpolate> |
1940
|
|
|
|
|
|
|
|
1941
|
|
|
|
|
|
|
|
1942
|
|
|
|
|
|
|
=item C<:ppi> |
1943
|
|
|
|
|
|
|
|
1944
|
|
|
|
|
|
|
Things for dealing with L<PPI|PPI>, other than classification. |
1945
|
|
|
|
|
|
|
|
1946
|
|
|
|
|
|
|
Includes: |
1947
|
|
|
|
|
|
|
C<first_arg>, |
1948
|
|
|
|
|
|
|
C<parse_arg_list> |
1949
|
|
|
|
|
|
|
|
1950
|
|
|
|
|
|
|
See also L<Perl::Critic::Utils::PPI|Perl::Critic::Utils::PPI>. |
1951
|
|
|
|
|
|
|
|
1952
|
|
|
|
|
|
|
|
1953
|
|
|
|
|
|
|
=item C<:internal_lookup> |
1954
|
|
|
|
|
|
|
|
1955
|
|
|
|
|
|
|
Translations between internal representations. |
1956
|
|
|
|
|
|
|
|
1957
|
|
|
|
|
|
|
Includes: |
1958
|
|
|
|
|
|
|
C<severity_to_number>, |
1959
|
|
|
|
|
|
|
C<verbosity_to_format> |
1960
|
|
|
|
|
|
|
|
1961
|
|
|
|
|
|
|
|
1962
|
|
|
|
|
|
|
=item C<:language> |
1963
|
|
|
|
|
|
|
|
1964
|
|
|
|
|
|
|
Information about Perl not programmatically available elsewhere. |
1965
|
|
|
|
|
|
|
|
1966
|
|
|
|
|
|
|
Includes: |
1967
|
|
|
|
|
|
|
C<precedence_of> |
1968
|
|
|
|
|
|
|
|
1969
|
|
|
|
|
|
|
|
1970
|
|
|
|
|
|
|
=item C<:deprecated> |
1971
|
|
|
|
|
|
|
|
1972
|
|
|
|
|
|
|
Not surprisingly, things that are deprecated. It is preferred to use |
1973
|
|
|
|
|
|
|
this tag to get to these functions, rather than the function names |
1974
|
|
|
|
|
|
|
themselves, so as to mark any module using them as needing cleanup. |
1975
|
|
|
|
|
|
|
|
1976
|
|
|
|
|
|
|
Includes: |
1977
|
|
|
|
|
|
|
C<find_keywords> |
1978
|
|
|
|
|
|
|
|
1979
|
|
|
|
|
|
|
|
1980
|
|
|
|
|
|
|
=back |
1981
|
|
|
|
|
|
|
|
1982
|
|
|
|
|
|
|
|
1983
|
|
|
|
|
|
|
=head1 SEE ALSO |
1984
|
|
|
|
|
|
|
|
1985
|
|
|
|
|
|
|
L<Perl::Critic::Utils::Constants|Perl::Critic::Utils::Constants>, |
1986
|
|
|
|
|
|
|
L<Perl::Critic::Utils::McCabe|Perl::Critic::Utils::McCabe>, |
1987
|
|
|
|
|
|
|
L<Perl::Critic::Utils::PPI|Perl::Critic::Utils::PPI>, |
1988
|
|
|
|
|
|
|
|
1989
|
|
|
|
|
|
|
|
1990
|
|
|
|
|
|
|
=head1 AUTHOR |
1991
|
|
|
|
|
|
|
|
1992
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> |
1993
|
|
|
|
|
|
|
|
1994
|
|
|
|
|
|
|
|
1995
|
|
|
|
|
|
|
=head1 COPYRIGHT |
1996
|
|
|
|
|
|
|
|
1997
|
|
|
|
|
|
|
Copyright (c) 2005-2021 Imaginative Software Systems |
1998
|
|
|
|
|
|
|
|
1999
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
2000
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
2001
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module. |
2002
|
|
|
|
|
|
|
|
2003
|
|
|
|
|
|
|
=cut |
2004
|
|
|
|
|
|
|
|
2005
|
|
|
|
|
|
|
# Local Variables: |
2006
|
|
|
|
|
|
|
# mode: cperl |
2007
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
2008
|
|
|
|
|
|
|
# fill-column: 78 |
2009
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
2010
|
|
|
|
|
|
|
# c-indentation-style: bsd |
2011
|
|
|
|
|
|
|
# End: |
2012
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |