← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:11 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Variables/ProhibitEvilVariables.pm
StatementsExecuted 38 statements in 1.46ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
331101µs108µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::CORE:regcompPerl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:regcomp (opcode)
11121µs25µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::supported_parametersPerl::Critic::Policy::Variables::ProhibitEvilVariables::supported_parameters
11117µs17µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::BEGIN@9Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@9
96111µs11µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::CORE:qrPerl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:qr (opcode)
1118µs28µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::BEGIN@14Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@14
1118µs12µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::BEGIN@11Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@11
1118µs48µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::BEGIN@17Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@17
1118µs29µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::BEGIN@21Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@21
1118µs20µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::BEGIN@10Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@10
1118µs397µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::BEGIN@13Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@13
1118µs392µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::BEGIN@18Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@18
1117µs58µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::BEGIN@23Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@23
1116µs7µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::default_severityPerl::Critic::Policy::Variables::ProhibitEvilVariables::default_severity
1114µs4µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::initialize_if_enabledPerl::Critic::Policy::Variables::ProhibitEvilVariables::initialize_if_enabled
1113µs3µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::_parse_variablesPerl::Critic::Policy::Variables::ProhibitEvilVariables::_parse_variables
1112µs2µsPerl::Critic::Policy::Variables::ProhibitEvilVariables::::_parse_variables_filePerl::Critic::Policy::Variables::ProhibitEvilVariables::_parse_variables_file
0000s0sPerl::Critic::Policy::Variables::ProhibitEvilVariables::::_compute_symbol_namesPerl::Critic::Policy::Variables::ProhibitEvilVariables::_compute_symbol_names
0000s0sPerl::Critic::Policy::Variables::ProhibitEvilVariables::::_handle_variable_specificationPerl::Critic::Policy::Variables::ProhibitEvilVariables::_handle_variable_specification
0000s0sPerl::Critic::Policy::Variables::ProhibitEvilVariables::::_handle_variable_specification_on_linePerl::Critic::Policy::Variables::ProhibitEvilVariables::_handle_variable_specification_on_line
0000s0sPerl::Critic::Policy::Variables::ProhibitEvilVariables::::_make_violationPerl::Critic::Policy::Variables::ProhibitEvilVariables::_make_violation
0000s0sPerl::Critic::Policy::Variables::ProhibitEvilVariables::::applies_toPerl::Critic::Policy::Variables::ProhibitEvilVariables::applies_to
0000s0sPerl::Critic::Policy::Variables::ProhibitEvilVariables::::default_themesPerl::Critic::Policy::Variables::ProhibitEvilVariables::default_themes
0000s0sPerl::Critic::Policy::Variables::ProhibitEvilVariables::::violatesPerl::Critic::Policy::Variables::ProhibitEvilVariables::violates
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1##############################################################################
2# $URL$
3# $Date$
4# $Author$
5# $Revision$
6##############################################################################
7package Perl::Critic::Policy::Variables::ProhibitEvilVariables;
8
9245µs117µs
# spent 17µs within Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@9 which was called: # once (17µs+0s) by Module::Pluggable::Object::_require at line 9
use 5.006001;
10221µs232µs
# spent 20µs (8+12) within Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@10 which was called: # once (8µs+12µs) by Module::Pluggable::Object::_require at line 10
use strict;
# spent 20µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@10 # spent 12µs making 1 call to strict::import
11222µs216µs
# spent 12µs (8+4) within Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@11 which was called: # once (8µs+4µs) by Module::Pluggable::Object::_require at line 11
use warnings;
# spent 12µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@11 # spent 4µs making 1 call to warnings::import
12
13223µs2786µs
# spent 397µs (8+389) within Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@13 which was called: # once (8µs+389µs) by Module::Pluggable::Object::_require at line 13
use English qw(-no_match_vars);
# spent 397µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@13 # spent 389µs making 1 call to English::import
14224µs248µs
# spent 28µs (8+20) within Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@14 which was called: # once (8µs+20µs) by Module::Pluggable::Object::_require at line 14
use Readonly;
# spent 28µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@14 # spent 20µs making 1 call to Exporter::import
15
16use Perl::Critic::Exception::Configuration::Option::Policy::ParameterValue
17225µs288µs
# spent 48µs (8+40) within Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@17 which was called: # once (8µs+40µs) by Module::Pluggable::Object::_require at line 17
qw{ throw_policy_value };
# spent 48µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@17 # spent 40µs making 1 call to Exporter::import
181200ns
# spent 392µs (8+385) within Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@18 which was called: # once (8µs+385µs) by Module::Pluggable::Object::_require at line 20
use Perl::Critic::Utils qw{
19 :characters :severities :data_conversion
20125µs2777µs};
# spent 392µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@18 # spent 385µs making 1 call to Exporter::import
21222µs251µs
# spent 29µs (8+21) within Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@21 which was called: # once (8µs+21µs) by Module::Pluggable::Object::_require at line 21
use Perl::Critic::Utils::DataConversion qw{ dor };
# spent 29µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@21 # spent 21µs making 1 call to Exporter::import
22
2321.03ms2109µs
# spent 58µs (7+51) within Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@23 which was called: # once (7µs+51µs) by Module::Pluggable::Object::_require at line 23
use base 'Perl::Critic::Policy';
# spent 58µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::BEGIN@23 # spent 51µs making 1 call to base::import
24
251600nsour $VERSION = '1.121';
26
27#-----------------------------------------------------------------------------
28
2912µs132µsReadonly::Scalar my $EXPL => q{Find an alternative variable};
# spent 32µs making 1 call to Readonly::Scalar
30
3113µs231µsReadonly::Hash my %SUBSCRIPTED_TYPE => hashify(qw{@ %});
# spent 28µs making 1 call to Readonly::Hash # spent 3µs making 1 call to Perl::Critic::Utils::hashify
32
3317µs233µsReadonly::Scalar my $VARIABLE_NAME_REGEX => qr< [\$\@%] \S+ >xms;
# spent 32µs making 1 call to Readonly::Scalar # spent 1µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:qr
3414µs221µsReadonly::Scalar my $REGULAR_EXPRESSION_REGEX =>
# spent 20µs making 1 call to Readonly::Scalar # spent 1µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:qr
35 qr< [/] ( [^/]+ ) [/] >xms;
36111µs524µsReadonly::Array my @DESCRIPTION_REGEXES =>
# spent 21µs making 1 call to Readonly::Array # spent 3µs making 4 calls to Perl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:qr, avg 725ns/call
37 qr< [{] ( [^}]+ ) [}] >xms,
38 qr{ < ( [^>]+ ) > }xms,
39 qr{ [[] ( [^]]+ ) []] }xms,
40 qr{ [(] ( [^)]+ ) [)] }xms,
41;
42Readonly::Scalar my $DESCRIPTION_REGEX =>
43149µs856µs qr< @{[join '|', @DESCRIPTION_REGEXES]} >xms;
# spent 26µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:regcomp # spent 22µs making 1 call to Readonly::Scalar # spent 5µs making 4 calls to Readonly::Array::FETCH, avg 1µs/call # spent 1µs making 1 call to Readonly::Array::FETCHSIZE # spent 1µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:qr
44
45# It's kind of unfortunate that I had to put capturing parentheses in the
46# component regexes above, because they're not visible here and so make
47# figuring out the positions of captures hard. Too bad we can't make the
48# minimum perl version 5.10. :]
49152µs680µsReadonly::Scalar my $VARIABLES_REGEX =>
# spent 52µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:regcomp # spent 23µs making 1 call to Readonly::Scalar # spent 4µs making 3 calls to Readonly::Scalar::FETCH, avg 1µs/call # spent 1µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:qr
50 qr<
51 \A
52 \s*
53 (?:
54 ( $VARIABLE_NAME_REGEX )
55 | $REGULAR_EXPRESSION_REGEX
56 )
57 (?: \s* $DESCRIPTION_REGEX )?
58 \s*
59 >xms;
60
61135µs558µsReadonly::Scalar my $VARIABLES_FILE_LINE_REGEX =>
# spent 30µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:regcomp # spent 23µs making 1 call to Readonly::Scalar # spent 3µs making 1 call to Perl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:qr # spent 2µs making 2 calls to Readonly::Scalar::FETCH, avg 1µs/call
62 qr<
63 \A
64 \s*
65 (?:
66 ( $VARIABLE_NAME_REGEX )
67 | $REGULAR_EXPRESSION_REGEX
68 )
69 \s*
70 ( \S (?: .* \S )? )?
71 \s*
72 \z
73 >xms;
74
75# Indexes in the arrays of regexes for the "variables" option.
7611µs120µsReadonly::Scalar my $INDEX_REGEX => 0;
# spent 20µs making 1 call to Readonly::Scalar
771900ns119µsReadonly::Scalar my $INDEX_DESCRIPTION => 1;
# spent 19µs making 1 call to Readonly::Scalar
78
79#-----------------------------------------------------------------------------
80
81
# spent 25µs (21+5) within Perl::Critic::Policy::Variables::ProhibitEvilVariables::supported_parameters which was called: # once (21µs+5µs) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters {
82 return (
83 {
84116µs45µs name => 'variables',
# spent 5µs making 4 calls to Readonly::Scalar::FETCH, avg 1µs/call
85 description => 'The names of or patterns for variables to forbid.',
86 default_string => $EMPTY,
87 parser => \&_parse_variables,
88 },
89 {
90 name => 'variables_file',
91 description => 'A file containing names of or patterns for variables to forbid.',
92 default_string => $EMPTY,
93 parser => \&_parse_variables_file,
94 },
95 );
96}
97
9812µs
# spent 7µs (6+1) within Perl::Critic::Policy::Variables::ProhibitEvilVariables::default_severity which was called: # once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm
sub default_severity { return $SEVERITY_HIGHEST }
99sub default_themes { return qw( core bugs ) }
100sub applies_to { return qw{PPI::Token::Symbol} }
101
102#-----------------------------------------------------------------------------
103
104
# spent 3µs within Perl::Critic::Policy::Variables::ProhibitEvilVariables::_parse_variables which was called: # once (3µs+0s) by Perl::Critic::PolicyParameter::parse_and_validate_config_value at line 231 of Perl/Critic/PolicyParameter.pm
sub _parse_variables {
1051500ns my ($self, $parameter, $config_string) = @_;
106
10714µs return if not $config_string;
108 return if $config_string =~ m< \A \s* \z >xms;
109
110 my $variable_specifications = $config_string;
111
112 while ( my ($variable, $regex_string, @descrs) =
113 $variable_specifications =~ m< $VARIABLES_REGEX >xms) {
114
115 substr $variable_specifications, 0, $LAST_MATCH_END[0], $EMPTY;
116 my $description = dor(@descrs);
117
118 $self->_handle_variable_specification(
119 variable => $variable,
120 regex_string => $regex_string,
121 description => $description,
122 option_name => 'variables',
123 option_value => $config_string,
124 );
125 }
126
127 if ($variable_specifications) {
128 throw_policy_value
129 policy => $self->get_short_name(),
130 option_name => 'variables',
131 option_value => $config_string,
132 message_suffix =>
133 qq{contains unparseable data: "$variable_specifications"};
134 }
135
136 return;
137}
138
139
# spent 2µs within Perl::Critic::Policy::Variables::ProhibitEvilVariables::_parse_variables_file which was called: # once (2µs+0s) by Perl::Critic::PolicyParameter::parse_and_validate_config_value at line 231 of Perl/Critic/PolicyParameter.pm
sub _parse_variables_file {
1401400ns my ($self, $parameter, $config_string) = @_;
141
14214µs return if not $config_string;
143 return if $config_string =~ m< \A \s* \z >xms;
144
145 open my $handle, '<', $config_string
146 or throw_policy_value
147 policy => $self->get_short_name(),
148 option_name => 'variables_file',
149 option_value => $config_string,
150 message_suffix =>
151 qq<refers to a file that could not be opened: $OS_ERROR>;
152 while ( my $line = <$handle> ) {
153 $self->_handle_variable_specification_on_line($line, $config_string);
154 }
155 close $handle or warn qq<Could not close "$config_string": $OS_ERROR\n>;
156
157 return;
158}
159
160sub _handle_variable_specification_on_line {
161 my ($self, $line, $config_string) = @_;
162
163 $line =~ s< [#] .* \z ><>xms;
164 $line =~ s< \s+ \z ><>xms;
165 $line =~ s< \A \s+ ><>xms;
166
167 return if not $line;
168
169 if ( my ($variable, $regex_string, $description) =
170 $line =~ m< $VARIABLES_FILE_LINE_REGEX >xms) {
171
172 $self->_handle_variable_specification(
173 variable => $variable,
174 regex_string => $regex_string,
175 description => $description,
176 option_name => 'variables_file',
177 option_value => $config_string,
178 );
179 }
180 else {
181 throw_policy_value
182 policy => $self->get_short_name(),
183 option_name => 'variables_file',
184 option_value => $config_string,
185 message_suffix =>
186 qq{contains unparseable data: "$line"};
187 }
188
189 return;
190}
191
192sub _handle_variable_specification {
193 my ($self, %arguments) = @_;
194
195 my $description = $arguments{description} || $EMPTY;
196
197 if ( my $regex_string = $arguments{regex_string} ) {
198 # These are variable name patterns (e.g. /acme/)
199 my $actual_regex;
200
201 eval { $actual_regex = qr/$regex_string/sm; ## no critic (ExtendedFormatting)
202 1 }
203 or throw_policy_value
204 policy => $self->get_short_name(),
205 option_name => $arguments{option_name},
206 option_value => $arguments{option_value},
207 message_suffix =>
208 qq{contains an invalid regular expression: "$regex_string"};
209
210 # Can't use a hash due to stringification, so this is an AoA.
211 push
212 @{ $self->{_evil_variables_regexes} ||= [] },
213 [ $actual_regex, $description ];
214 }
215 else {
216 # These are literal variable names (e.g. $[)
217 $self->{_evil_variables} ||= {};
218 my $name = $arguments{variable};
219 $self->{_evil_variables}{$name} = $description;
220 }
221
222 return;
223}
224
225#-----------------------------------------------------------------------------
226
227
# spent 4µs within Perl::Critic::Policy::Variables::ProhibitEvilVariables::initialize_if_enabled which was called: # once (4µs+0s) by Perl::Critic::Config::_add_policy_if_enabled at line 202 of Perl/Critic/Config.pm
sub initialize_if_enabled {
2281600ns my ($self, $config) = @_;
229
230 # Disable if no variables are specified; there's no point in running if
231 # there aren't any.
232 return
23315µs exists $self->{_evil_variables}
234 || exists $self->{_evil_variables_regexes};
235}
236
237#-----------------------------------------------------------------------------
238
239sub violates {
240 my ( $self, $elem, undef ) = @_;
241 return if not $elem;
242
243 my @names = $self->_compute_symbol_names( $elem )
244 or return;
245
246 my $evil_variables = $self->{_evil_variables};
247 my $evil_variables_regexes = $self->{_evil_variables_regexes};
248
249 foreach my $variable (@names) {
250 exists $evil_variables->{$variable}
251 and return $self->_make_violation(
252 $variable,
253 $evil_variables->{$variable},
254 $elem,
255 );
256 }
257
258 foreach my $variable (@names) {
259 foreach my $regex ( @{$evil_variables_regexes} ) {
260 $variable =~ $regex->[$INDEX_REGEX]
261 and return $self->_make_violation(
262 $variable,
263 $regex->[$INDEX_DESCRIPTION],
264 $elem,
265 );
266 }
267 }
268
269 return; # ok!
270}
271
272#-----------------------------------------------------------------------------
273
274# We are unconditionally interested in the names of the symbol itself. If the
275# symbol is subscripted, we are interested in the subscripted form as well.
276
277sub _compute_symbol_names {
278 my ($self, $elem) = @_;
279
280 my @names;
281
282 my $name = $elem->symbol();
283 push @names, $name;
284
285 if ($SUBSCRIPTED_TYPE{$elem->symbol_type()}) {
286 $name = $elem->content();
287 my $next = $elem->snext_sibling();
288 my @subscr;
289 while ($next and $next->isa('PPI::Structure::Subscript')) {
290 push @subscr, $next->content();
291 $next = $next->snext_sibling();
292 }
293 if (@subscr) {
294 push @names, join $EMPTY, $name, @subscr;
295 }
296 }
297
298 return @names;
299}
300
301#-----------------------------------------------------------------------------
302
303sub _make_violation {
304 my ($self, $variable, $description, $elem) = @_;
305 return $self->violation(
306 $description || qq<Prohibited variable "$variable" used>,
307 $EXPL,
308 $elem,
309 );
310}
311
312125µs1;
313
314__END__
 
# spent 11µs within Perl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:qr which was called 9 times, avg 1µs/call: # 4 times (3µs+0s) by Module::Pluggable::Object::_require at line 36, avg 725ns/call # once (3µs+0s) by Module::Pluggable::Object::_require at line 61 # once (1µs+0s) by Module::Pluggable::Object::_require at line 33 # once (1µs+0s) by Module::Pluggable::Object::_require at line 49 # once (1µs+0s) by Module::Pluggable::Object::_require at line 34 # once (1µs+0s) by Module::Pluggable::Object::_require at line 43
sub Perl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:qr; # opcode
# spent 108µs (101+6) within Perl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:regcomp which was called 3 times, avg 36µs/call: # once (48µs+4µs) by Module::Pluggable::Object::_require at line 49 # once (27µs+2µs) by Module::Pluggable::Object::_require at line 61 # once (26µs+0s) by Module::Pluggable::Object::_require at line 43
sub Perl::Critic::Policy::Variables::ProhibitEvilVariables::CORE:regcomp; # opcode