← 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