← 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:12 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Modules/ProhibitEvilModules.pm
StatementsExecuted 9042 statements in 7.11ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
982116.11ms37.1msPerl::Critic::Policy::Modules::ProhibitEvilModules::::violatesPerl::Critic::Policy::Modules::ProhibitEvilModules::violates
14411305µs305µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::applies_toPerl::Critic::Policy::Modules::ProhibitEvilModules::applies_to
741143µs155µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::CORE:regcompPerl::Critic::Policy::Modules::ProhibitEvilModules::CORE:regcomp (opcode)
11164µs186µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::_parse_modulesPerl::Critic::Policy::Modules::ProhibitEvilModules::_parse_modules
41129µs29µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::_handle_module_specificationPerl::Critic::Policy::Modules::ProhibitEvilModules::_handle_module_specification
11122µs26µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::supported_parametersPerl::Critic::Policy::Modules::ProhibitEvilModules::supported_parameters
52118µs18µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::CORE:substPerl::Critic::Policy::Modules::ProhibitEvilModules::CORE:subst (opcode)
11116µs16µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::BEGIN@9Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@9
11110µs30µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::BEGIN@17Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@17
1118µs410µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::BEGIN@13Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@13
1118µs74µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::BEGIN@22Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@22
1118µs27µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::BEGIN@14Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@14
1117µs11µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::BEGIN@11Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@11
1117µs9µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::default_severityPerl::Critic::Policy::Modules::ProhibitEvilModules::default_severity
1117µs471µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::BEGIN@18Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@18
1117µs18µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::BEGIN@10Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@10
5516µs6µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::CORE:qrPerl::Critic::Policy::Modules::ProhibitEvilModules::CORE:qr (opcode)
1114µs4µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::initialize_if_enabledPerl::Critic::Policy::Modules::ProhibitEvilModules::initialize_if_enabled
1112µs2µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::CORE:matchPerl::Critic::Policy::Modules::ProhibitEvilModules::CORE:match (opcode)
1112µs2µsPerl::Critic::Policy::Modules::ProhibitEvilModules::::_parse_modules_filePerl::Critic::Policy::Modules::ProhibitEvilModules::_parse_modules_file
0000s0sPerl::Critic::Policy::Modules::ProhibitEvilModules::::_handle_module_specification_on_linePerl::Critic::Policy::Modules::ProhibitEvilModules::_handle_module_specification_on_line
0000s0sPerl::Critic::Policy::Modules::ProhibitEvilModules::::default_themesPerl::Critic::Policy::Modules::ProhibitEvilModules::default_themes
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::Modules::ProhibitEvilModules;
8
9240µs116µs
# spent 16µs within Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@9 which was called: # once (16µs+0s) by Module::Pluggable::Object::_require at line 9
use 5.006001;
10222µs229µs
# spent 18µs (7+11) within Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@10 which was called: # once (7µs+11µs) by Module::Pluggable::Object::_require at line 10
use strict;
# spent 18µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@10 # spent 11µs making 1 call to strict::import
11221µs214µs
# spent 11µs (7+4) within Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@11 which was called: # once (7µs+4µs) by Module::Pluggable::Object::_require at line 11
use warnings;
# spent 11µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@11 # spent 4µs making 1 call to warnings::import
12
13224µs2812µs
# spent 410µs (8+402) within Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@13 which was called: # once (8µs+402µs) by Module::Pluggable::Object::_require at line 13
use English qw(-no_match_vars);
# spent 410µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@13 # spent 402µs making 1 call to English::import
14223µs246µs
# spent 27µs (8+19) within Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@14 which was called: # once (8µs+19µs) by Module::Pluggable::Object::_require at line 14
use Readonly;
# spent 27µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@14 # spent 19µs making 1 call to Exporter::import
15
16use Perl::Critic::Exception::Configuration::Option::Policy::ParameterValue
17225µs250µs
# spent 30µs (10+20) within Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@17 which was called: # once (10µs+20µs) by Module::Pluggable::Object::_require at line 17
qw{ throw_policy_value };
# spent 30µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@17 # spent 20µs making 1 call to Exporter::import
181200ns
# spent 471µs (7+464) within Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@18 which was called: # once (7µs+464µs) by Module::Pluggable::Object::_require at line 20
use Perl::Critic::Utils qw{
19 :booleans :characters :severities :data_conversion
20124µs2936µs};
# spent 471µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@18 # spent 464µs making 1 call to Exporter::import
21
222910µs2141µs
# spent 74µs (8+66) within Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@22 which was called: # once (8µs+66µs) by Module::Pluggable::Object::_require at line 22
use base 'Perl::Critic::Policy';
# spent 74µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::BEGIN@22 # spent 66µs making 1 call to base::import
23
241700nsour $VERSION = '1.121';
25
26#-----------------------------------------------------------------------------
27
2812µs133µsReadonly::Scalar my $EXPL => q{Find an alternative module};
# spent 33µs making 1 call to Readonly::Scalar
29
3017µs224µsReadonly::Scalar my $MODULE_NAME_REGEX =>
# spent 23µs making 1 call to Readonly::Scalar # spent 1µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:qr
31 qr<
32 \b
33 [[:alpha:]_]
34 (?:
35 (?: \w | :: )*
36 \w
37 )?
38 \b
39 >xms;
4015µs222µsReadonly::Scalar my $REGULAR_EXPRESSION_REGEX => qr< [/] ( [^/]+ ) [/] >xms;
# spent 21µs making 1 call to Readonly::Scalar # spent 1µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:qr
4114µs221µsReadonly::Scalar my $DESCRIPTION_REGEX => qr< [{] ( [^}]+ ) [}] >xms;
# spent 20µs making 1 call to Readonly::Scalar # spent 1µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:qr
42
43# It's kind of unfortunate that I had to put capturing parentheses in the
44# component regexes above, because they're not visible here and so make
45# figuring out the positions of captures hard. Too bad we can't make the
46# minimum perl version 5.10. :]
47148µs672µsReadonly::Scalar my $MODULES_REGEX =>
# spent 44µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::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::Modules::ProhibitEvilModules::CORE:qr
48 qr<
49 \A
50 \s*
51 (?:
52 ( $MODULE_NAME_REGEX )
53 | $REGULAR_EXPRESSION_REGEX
54 )
55 (?: \s* $DESCRIPTION_REGEX )?
56 \s*
57 >xms;
58
59141µs565µsReadonly::Scalar my $MODULES_FILE_LINE_REGEX =>
# spent 38µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:regcomp # spent 23µs making 1 call to Readonly::Scalar # spent 2µs making 2 calls to Readonly::Scalar::FETCH, avg 1µs/call # spent 1µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:qr
60 qr<
61 \A
62 \s*
63 (?:
64 ( $MODULE_NAME_REGEX )
65 | $REGULAR_EXPRESSION_REGEX
66 )
67 \s*
68 ( \S (?: .* \S )? )?
69 \s*
70 \z
71 >xms;
72
73Readonly::Scalar my $DEFAULT_MODULES =>
74 join
75 $SPACE,
7618µs223µs map { "$_ {Found use of $_. This module is deprecated by the Perl 5 Porters.}" }
# spent 21µs making 1 call to Readonly::Scalar # spent 2µs making 1 call to Readonly::Scalar::FETCH
77 qw< Class::ISA Pod::Plainer Shell Switch >;
78
79# Indexes in the arrays of regexes for the "modules" option.
8011µs120µsReadonly::Scalar my $INDEX_REGEX => 0;
# spent 20µs making 1 call to Readonly::Scalar
811900ns120µsReadonly::Scalar my $INDEX_DESCRIPTION => 1;
# spent 20µs making 1 call to Readonly::Scalar
82
83#-----------------------------------------------------------------------------
84
85
# spent 26µs (22+5) within Perl::Critic::Policy::Modules::ProhibitEvilModules::supported_parameters which was called: # once (22µs+5µs) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters {
86 return (
87 {
88117µs45µs name => 'modules',
# spent 5µs making 4 calls to Readonly::Scalar::FETCH, avg 1µs/call
89 description => 'The names of or patterns for modules to forbid.',
90 default_string => $DEFAULT_MODULES,
91 parser => \&_parse_modules,
92 },
93 {
94 name => 'modules_file',
95 description => 'A file containing names of or patterns for modules to forbid.',
96 default_string => $EMPTY,
97 parser => \&_parse_modules_file,
98 },
99 );
100}
101
10212µs
# spent 9µs (7+2) within Perl::Critic::Policy::Modules::ProhibitEvilModules::default_severity which was called: # once (7µs+2µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm
sub default_severity { return $SEVERITY_HIGHEST }
103sub default_themes { return qw( core bugs certrule ) }
104144379µs
# spent 305µs within Perl::Critic::Policy::Modules::ProhibitEvilModules::applies_to which was called 144 times, avg 2µs/call: # 144 times (305µs+0s) by Perl::Critic::_critique at line 165 of Perl/Critic.pm, avg 2µs/call
sub applies_to { return 'PPI::Statement::Include' }
105
106#-----------------------------------------------------------------------------
107
108
# spent 186µs (64+122) within Perl::Critic::Policy::Modules::ProhibitEvilModules::_parse_modules which was called: # once (64µs+122µs) by Perl::Critic::PolicyParameter::parse_and_validate_config_value at line 231 of Perl/Critic/PolicyParameter.pm
sub _parse_modules {
1091400ns my ($self, $parameter, $config_string) = @_;
110
11112µs11µs my $module_specifications =
# spent 1µs making 1 call to Perl::Critic::PolicyParameter::get_default_string
112 defined $config_string
113 ? $config_string
114 : $parameter->get_default_string();
115
1161300ns return if not $module_specifications;
11718µs12µs return if $module_specifications =~ m< \A \s* \z >xms;
118
119164µs358µs while ( $module_specifications =~ s< $MODULES_REGEX ><>xms ) {
# spent 50µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:regcomp # spent 6µs making 1 call to Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:subst # spent 1µs making 1 call to Readonly::Scalar::FETCH
12046µs my ($module, $regex_string, $description) = ($1, $2, $3);
121
122448µs1668µs $self->_handle_module_specification(
# spent 29µs making 4 calls to Perl::Critic::Policy::Modules::ProhibitEvilModules::_handle_module_specification, avg 7µs/call # spent 23µs making 4 calls to Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:regcomp, avg 6µs/call # spent 12µs making 4 calls to Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:subst, avg 3µs/call # spent 5µs making 4 calls to Readonly::Scalar::FETCH, avg 1µs/call
123 module => $module,
124 regex_string => $regex_string,
125 description => $description,
126 option_name => 'modules',
127 option_value => $config_string,
128 );
129 }
130
1311200ns if ($module_specifications) {
132 throw_policy_value
133 policy => $self->get_short_name(),
134 option_name => 'modules',
135 option_value => $config_string,
136 message_suffix =>
137 qq{contains unparseable data: "$module_specifications"};
138 }
139
14014µs return;
141}
142
143
# spent 2µs within Perl::Critic::Policy::Modules::ProhibitEvilModules::_parse_modules_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_modules_file {
1441400ns my ($self, $parameter, $config_string) = @_;
145
14614µs return if not $config_string;
147 return if $config_string =~ m< \A \s* \z >xms;
148
149 open my $handle, '<', $config_string
150 or throw_policy_value
151 policy => $self->get_short_name(),
152 option_name => 'modules_file',
153 option_value => $config_string,
154 message_suffix =>
155 qq<refers to a file that could not be opened: $OS_ERROR>;
156 while ( my $line = <$handle> ) {
157 $self->_handle_module_specification_on_line($line, $config_string);
158 }
159 close $handle or warn qq<Could not close "$config_string": $OS_ERROR\n>;
160
161 return;
162}
163
164sub _handle_module_specification_on_line {
165 my ($self, $line, $config_string) = @_;
166
167 $line =~ s< [#] .* \z ><>xms;
168 $line =~ s< \s+ \z ><>xms;
169 $line =~ s< \A \s+ ><>xms;
170
171 return if not $line;
172
173 if ( $line =~ s< $MODULES_FILE_LINE_REGEX ><>xms ) {
174 my ($module, $regex_string, $description) = ($1, $2, $3);
175
176 $self->_handle_module_specification(
177 module => $module,
178 regex_string => $regex_string,
179 description => $description,
180 option_name => 'modules_file',
181 option_value => $config_string,
182 );
183 }
184 else {
185 throw_policy_value
186 policy => $self->get_short_name(),
187 option_name => 'modules_file',
188 option_value => $config_string,
189 message_suffix =>
190 qq{contains unparseable data: "$line"};
191 }
192
193 return;
194}
195
196
# spent 29µs within Perl::Critic::Policy::Modules::ProhibitEvilModules::_handle_module_specification which was called 4 times, avg 7µs/call: # 4 times (29µs+0s) by Perl::Critic::Policy::Modules::ProhibitEvilModules::_parse_modules at line 122, avg 7µs/call
sub _handle_module_specification {
19749µs my ($self, %arguments) = @_;
198
19942µs my $description = $arguments{description} || $EMPTY;
200
20142µs if ( my $regex_string = $arguments{regex_string} ) {
202 # These are module name patterns (e.g. /Acme/)
203 my $actual_regex;
204
205 eval { $actual_regex = qr/$regex_string/; 1 } ## no critic (ExtendedFormatting, LineBoundaryMatching, DotMatchAnything)
206 or throw_policy_value
207 policy => $self->get_short_name(),
208 option_name => $arguments{option_name},
209 option_value => $arguments{option_value},
210 message_suffix =>
211 qq{contains an invalid regular expression: "$regex_string"};
212
213 # Can't use a hash due to stringification, so this is an AoA.
214 $self->{_evil_modules_regexes} ||= [];
215
216 push
217 @{ $self->{_evil_modules_regexes} },
218 [ $actual_regex, $description ];
219 }
220 else {
221 # These are literal module names (e.g. Acme::Foo)
22242µs $self->{_evil_modules} ||= {};
22344µs $self->{_evil_modules}{ $arguments{module} } = $description;
224 }
225
226413µs return;
227}
228
229#-----------------------------------------------------------------------------
230
231
# spent 4µs within Perl::Critic::Policy::Modules::ProhibitEvilModules::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 {
2321400ns my ($self, $config) = @_;
233
234 # Disable if no modules are specified; there's no point in running if
235 # there aren't any.
236 return
23716µs exists $self->{_evil_modules}
238 || exists $self->{_evil_modules_regexes};
239}
240
241#-----------------------------------------------------------------------------
242
243
# spent 37.1ms (6.11+31.0) within Perl::Critic::Policy::Modules::ProhibitEvilModules::violates which was called 982 times, avg 38µs/call: # 982 times (6.11ms+31.0ms) by Perl::Critic::_critique at line 183 of Perl/Critic.pm, avg 38µs/call
sub violates {
244982295µs my ( $self, $elem, undef ) = @_;
245
2469821.39ms98231.0ms my $module = $elem->module();
# spent 31.0ms making 982 calls to PPI::Statement::Include::module, avg 32µs/call
247982393µs return if not $module;
248
249840324µs my $evil_modules = $self->{_evil_modules};
250840185µs my $evil_modules_regexes = $self->{_evil_modules_regexes};
25184025µs my $description;
252
253840342µs if ( exists $evil_modules->{$module} ) {
254 $description = $evil_modules->{ $module };
255 }
256 else {
257 REGEX:
258840564µs foreach my $regex ( @{$evil_modules_regexes} ) {
259 if ( $module =~ $regex->[$INDEX_REGEX] ) {
260 $description = $regex->[$INDEX_DESCRIPTION];
261 last REGEX;
262 }
263 }
264 }
265
266840109µs if (defined $description) {
267 $description ||= qq<Prohibited module "$module" used>;
268
269 return $self->violation( $description, $EXPL, $elem );
270 }
271
2728401.69ms return; # ok!
273}
274
275115µs1;
276
277__END__
 
# spent 2µs within Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:match which was called: # once (2µs+0s) by Perl::Critic::Policy::Modules::ProhibitEvilModules::_parse_modules at line 117
sub Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:match; # opcode
# spent 6µs within Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:qr which was called 5 times, avg 1µs/call: # once (1µs+0s) by Module::Pluggable::Object::_require at line 47 # once (1µs+0s) by Module::Pluggable::Object::_require at line 30 # once (1µs+0s) by Module::Pluggable::Object::_require at line 59 # once (1µs+0s) by Module::Pluggable::Object::_require at line 40 # once (1µs+0s) by Module::Pluggable::Object::_require at line 41
sub Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:qr; # opcode
# spent 155µs (143+12) within Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:regcomp which was called 7 times, avg 22µs/call: # 4 times (18µs+5µs) by Perl::Critic::Policy::Modules::ProhibitEvilModules::_parse_modules at line 122, avg 6µs/call # once (49µs+1µs) by Perl::Critic::Policy::Modules::ProhibitEvilModules::_parse_modules at line 119 # once (41µs+4µs) by Module::Pluggable::Object::_require at line 47 # once (36µs+2µs) by Module::Pluggable::Object::_require at line 59
sub Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:regcomp; # opcode
# spent 18µs within Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:subst which was called 5 times, avg 4µs/call: # 4 times (12µs+0s) by Perl::Critic::Policy::Modules::ProhibitEvilModules::_parse_modules at line 122, avg 3µs/call # once (6µs+0s) by Perl::Critic::Policy::Modules::ProhibitEvilModules::_parse_modules at line 119
sub Perl::Critic::Policy::Modules::ProhibitEvilModules::CORE:subst; # opcode