← 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/Documentation/RequirePodSections.pm
StatementsExecuted 36 statements in 1.13ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11158µs76µsPerl::Critic::Policy::Documentation::RequirePodSections::::supported_parametersPerl::Critic::Policy::Documentation::RequirePodSections::supported_parameters
11118µs18µsPerl::Critic::Policy::Documentation::RequirePodSections::::BEGIN@10Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@10
11112µs23µsPerl::Critic::Policy::Documentation::RequirePodSections::::BEGIN@11Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@11
1118µs10µsPerl::Critic::Policy::Documentation::RequirePodSections::::default_severityPerl::Critic::Policy::Documentation::RequirePodSections::default_severity
1118µs30µsPerl::Critic::Policy::Documentation::RequirePodSections::::BEGIN@13Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@13
1118µs648µsPerl::Critic::Policy::Documentation::RequirePodSections::::BEGIN@15Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@15
1118µs12µsPerl::Critic::Policy::Documentation::RequirePodSections::::BEGIN@12Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@12
1117µs57µsPerl::Critic::Policy::Documentation::RequirePodSections::::BEGIN@16Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@16
1113µs3µsPerl::Critic::Policy::Documentation::RequirePodSections::::_parse_lib_sectionsPerl::Critic::Policy::Documentation::RequirePodSections::_parse_lib_sections
1112µs2µsPerl::Critic::Policy::Documentation::RequirePodSections::::_parse_script_sectionsPerl::Critic::Policy::Documentation::RequirePodSections::_parse_script_sections
0000s0sPerl::Critic::Policy::Documentation::RequirePodSections::::_parse_sectionsPerl::Critic::Policy::Documentation::RequirePodSections::_parse_sections
0000s0sPerl::Critic::Policy::Documentation::RequirePodSections::::_sections_specifiedPerl::Critic::Policy::Documentation::RequirePodSections::_sections_specified
0000s0sPerl::Critic::Policy::Documentation::RequirePodSections::::applies_toPerl::Critic::Policy::Documentation::RequirePodSections::applies_to
0000s0sPerl::Critic::Policy::Documentation::RequirePodSections::::default_themesPerl::Critic::Policy::Documentation::RequirePodSections::default_themes
0000s0sPerl::Critic::Policy::Documentation::RequirePodSections::::initialize_if_enabledPerl::Critic::Policy::Documentation::RequirePodSections::initialize_if_enabled
0000s0sPerl::Critic::Policy::Documentation::RequirePodSections::::violatesPerl::Critic::Policy::Documentation::RequirePodSections::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##############################################################################
7
8package Perl::Critic::Policy::Documentation::RequirePodSections;
9
10243µs118µs
# spent 18µs within Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@10 which was called: # once (18µs+0s) by Module::Pluggable::Object::_require at line 10
use 5.006001;
11223µs235µs
# spent 23µs (12+12) within Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@11 which was called: # once (12µs+12µs) by Module::Pluggable::Object::_require at line 11
use strict;
# spent 23µs making 1 call to Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@11 # spent 12µs making 1 call to strict::import
12220µs216µs
# spent 12µs (8+4) within Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@12 which was called: # once (8µs+4µs) by Module::Pluggable::Object::_require at line 12
use warnings;
# spent 12µs making 1 call to Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@12 # spent 4µs making 1 call to warnings::import
13226µs252µs
# spent 30µs (8+22) within Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@13 which was called: # once (8µs+22µs) by Module::Pluggable::Object::_require at line 13
use Readonly;
# spent 30µs making 1 call to Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@13 # spent 22µs making 1 call to Exporter::import
14
15226µs21.29ms
# spent 648µs (8+640) within Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@15 which was called: # once (8µs+640µs) by Module::Pluggable::Object::_require at line 15
use Perl::Critic::Utils qw{ :booleans :characters :severities :classification };
# spent 648µs making 1 call to Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@15 # spent 640µs making 1 call to Exporter::import
162840µs2107µs
# spent 57µs (7+50) within Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@16 which was called: # once (7µs+50µs) by Module::Pluggable::Object::_require at line 16
use base 'Perl::Critic::Policy';
# spent 57µs making 1 call to Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@16 # spent 50µs making 1 call to base::import
17
181600nsour $VERSION = '1.121';
19
20#-----------------------------------------------------------------------------
21
2213µs153µsReadonly::Scalar my $EXPL => [133, 138];
# spent 53µs making 1 call to Readonly::Scalar
23
2411µs121µsReadonly::Scalar my $BOOK => 'book';
# spent 21µs making 1 call to Readonly::Scalar
251900ns120µsReadonly::Scalar my $BOOK_FIRST_EDITION => 'book_first_edition';
# spent 20µs making 1 call to Readonly::Scalar
2611µs120µsReadonly::Scalar my $MODULE_STARTER_PBP => 'module_starter_pbp';
# spent 20µs making 1 call to Readonly::Scalar
2711µs119µsReadonly::Scalar my $M_S_PBP_0_0_3 => 'module_starter_pbp_0_0_3';
# spent 19µs making 1 call to Readonly::Scalar
28
291800ns124µsReadonly::Scalar my $DEFAULT_SOURCE => $BOOK_FIRST_EDITION;
# spent 24µs making 1 call to Readonly::Scalar
30
3111µs154µsReadonly::Hash my %SOURCE_TRANSLATION => (
# spent 54µs making 1 call to Readonly::Hash
32 $BOOK => $BOOK_FIRST_EDITION,
33 $BOOK_FIRST_EDITION => $BOOK_FIRST_EDITION,
34 $MODULE_STARTER_PBP => $M_S_PBP_0_0_3,
35 $M_S_PBP_0_0_3 => $M_S_PBP_0_0_3,
36);
37
381900ns120µsReadonly::Scalar my $EN_AU => 'en_AU';
# spent 20µs making 1 call to Readonly::Scalar
391800ns120µsReadonly::Scalar my $EN_US => 'en_US';
# spent 20µs making 1 call to Readonly::Scalar
4011µs119µsReadonly::Scalar my $ORIGINAL_MODULE_VERSION => 'original';
# spent 19µs making 1 call to Readonly::Scalar
41
4211µs135µsReadonly::Hash my %SOURCE_DEFAULT_LANGUAGE => (
# spent 35µs making 1 call to Readonly::Hash
43 $BOOK_FIRST_EDITION => $ORIGINAL_MODULE_VERSION,
44 $M_S_PBP_0_0_3 => $EN_AU,
45);
46
4714µs147µsReadonly::Scalar my $BOOK_FIRST_EDITION_US_LIB_SECTIONS =>
# spent 47µs making 1 call to Readonly::Scalar
48 [
49 'NAME',
50 'VERSION',
51 'SYNOPSIS',
52 'DESCRIPTION',
53 'SUBROUTINES/METHODS',
54 'DIAGNOSTICS',
55 'CONFIGURATION AND ENVIRONMENT',
56 'DEPENDENCIES',
57 'INCOMPATIBILITIES',
58 'BUGS AND LIMITATIONS',
59 'AUTHOR',
60 'LICENSE AND COPYRIGHT',
61 ];
62
63131µs103.02msReadonly::Hash my %DEFAULT_LIB_SECTIONS => (
# spent 3.01ms making 1 call to Readonly::Hash # spent 10µs making 9 calls to Readonly::Scalar::FETCH, avg 1µs/call
64 $BOOK_FIRST_EDITION => {
65 $ORIGINAL_MODULE_VERSION => $BOOK_FIRST_EDITION_US_LIB_SECTIONS,
66 $EN_AU => [
67 'NAME',
68 'VERSION',
69 'SYNOPSIS',
70 'DESCRIPTION',
71 'SUBROUTINES/METHODS',
72 'DIAGNOSTICS',
73 'CONFIGURATION AND ENVIRONMENT',
74 'DEPENDENCIES',
75 'INCOMPATIBILITIES',
76 'BUGS AND LIMITATIONS',
77 'AUTHOR',
78 'LICENCE AND COPYRIGHT',
79 ],
80 $EN_US => $BOOK_FIRST_EDITION_US_LIB_SECTIONS,
81 },
82 $M_S_PBP_0_0_3 => {
83 $EN_AU => [
84 'NAME',
85 'VERSION',
86 'SYNOPSIS',
87 'DESCRIPTION',
88 'INTERFACE',
89 'DIAGNOSTICS',
90 'CONFIGURATION AND ENVIRONMENT',
91 'DEPENDENCIES',
92 'INCOMPATIBILITIES',
93 'BUGS AND LIMITATIONS',
94 'AUTHOR',
95 'LICENCE AND COPYRIGHT',
96 'DISCLAIMER OF WARRANTY',
97 ],
98 $EN_US => [
99 'NAME',
100 'VERSION',
101 'SYNOPSIS',
102 'DESCRIPTION',
103 'INTERFACE',
104 'DIAGNOSTICS',
105 'CONFIGURATION AND ENVIRONMENT',
106 'DEPENDENCIES',
107 'INCOMPATIBILITIES',
108 'BUGS AND LIMITATIONS',
109 'AUTHOR',
110 'LICENSE AND COPYRIGHT',
111 'DISCLAIMER OF WARRANTY'
112 ],
113 },
114);
115
116128µs6218µsReadonly::Hash my %DEFAULT_SCRIPT_SECTIONS => (
# spent 212µs making 1 call to Readonly::Hash # spent 6µs making 5 calls to Readonly::Scalar::FETCH, avg 1µs/call
117 $BOOK_FIRST_EDITION => {
118 $ORIGINAL_MODULE_VERSION => [
119 'NAME',
120 'USAGE',
121 'DESCRIPTION',
122 'REQUIRED ARGUMENTS',
123 'OPTIONS',
124 'DIAGNOSTICS',
125 'EXIT STATUS',
126 'CONFIGURATION',
127 'DEPENDENCIES',
128 'INCOMPATIBILITIES',
129 'BUGS AND LIMITATIONS',
130 'AUTHOR',
131 'LICENSE AND COPYRIGHT',
132 ],
133 $EN_AU => [
134 'NAME',
135 'VERSION',
136 'USAGE',
137 'REQUIRED ARGUMENTS',
138 'OPTIONS',
139 'DESCRIPTION',
140 'DIAGNOSTICS',
141 'CONFIGURATION AND ENVIRONMENT',
142 'DEPENDENCIES',
143 'INCOMPATIBILITIES',
144 'BUGS AND LIMITATIONS',
145 'AUTHOR',
146 'LICENCE AND COPYRIGHT',
147 ],
148 $EN_US => [
149 'NAME',
150 'VERSION',
151 'USAGE',
152 'REQUIRED ARGUMENTS',
153 'OPTIONS',
154 'DESCRIPTION',
155 'DIAGNOSTICS',
156 'CONFIGURATION AND ENVIRONMENT',
157 'DEPENDENCIES',
158 'INCOMPATIBILITIES',
159 'BUGS AND LIMITATIONS',
160 'AUTHOR',
161 'LICENSE AND COPYRIGHT',
162 ],
163 },
164 $M_S_PBP_0_0_3 => {
165 $EN_AU => [
166 'NAME',
167 'VERSION',
168 'USAGE',
169 'REQUIRED ARGUMENTS',
170 'OPTIONS',
171 'DESCRIPTION',
172 'DIAGNOSTICS',
173 'CONFIGURATION AND ENVIRONMENT',
174 'DEPENDENCIES',
175 'INCOMPATIBILITIES',
176 'BUGS AND LIMITATIONS',
177 'AUTHOR',
178 'LICENCE AND COPYRIGHT',
179 'DISCLAIMER OF WARRANTY',
180 ],
181 $EN_US => [
182 'NAME',
183 'VERSION',
184 'USAGE',
185 'REQUIRED ARGUMENTS',
186 'OPTIONS',
187 'DESCRIPTION',
188 'DIAGNOSTICS',
189 'CONFIGURATION AND ENVIRONMENT',
190 'DEPENDENCIES',
191 'INCOMPATIBILITIES',
192 'BUGS AND LIMITATIONS',
193 'AUTHOR',
194 'LICENSE AND COPYRIGHT',
195 'DISCLAIMER OF WARRANTY',
196 ],
197 },
198);
199
200#-----------------------------------------------------------------------------
201
202
# spent 76µs (58+18) within Perl::Critic::Policy::Documentation::RequirePodSections::supported_parameters which was called: # once (58µs+18µs) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters {
203 return (
204 {
205140µs1518µs name => 'lib_sections',
# spent 11µs making 10 calls to Readonly::Scalar::FETCH, avg 1µs/call # spent 4µs making 4 calls to Readonly::Hash::NEXTKEY, avg 1µs/call # spent 2µs making 1 call to Readonly::Hash::FIRSTKEY
206 description => 'The sections to require for modules (separated by qr/\s* [|] \s*/xms).',
207 default_string => $EMPTY,
208 parser => \&_parse_lib_sections,
209 },
210 {
211 name => 'script_sections',
212 description => 'The sections to require for programs (separated by qr/\s* [|] \s*/xms).',
213 default_string => $EMPTY,
214 parser => \&_parse_script_sections,
215 },
216 {
217 name => 'source',
218 description => 'The origin of sections to use.',
219 default_string => $DEFAULT_SOURCE,
220 behavior => 'enumeration',
221 enumeration_values => [ keys %SOURCE_TRANSLATION ],
222 },
223 {
224 name => 'language',
225 description => 'The spelling of sections to use.',
226 default_string => $EMPTY,
227 behavior => 'enumeration',
228 enumeration_values => [ $EN_AU, $EN_US ],
229 },
230 );
231}
232
23312µs
# spent 10µs (8+2) within Perl::Critic::Policy::Documentation::RequirePodSections::default_severity which was called: # once (8µs+2µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm
sub default_severity { return $SEVERITY_LOW }
234sub default_themes { return qw(core pbp maintenance) }
235sub applies_to { return 'PPI::Document' }
236
237#-----------------------------------------------------------------------------
238
239sub _parse_sections {
240 my $config_string = shift;
241
242 my @sections = split m{ \s* [|] \s* }xms, $config_string;
243
244 return map { uc $_ } @sections; # Normalize CaSe!
245}
246
247
# spent 3µs within Perl::Critic::Policy::Documentation::RequirePodSections::_parse_lib_sections 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_lib_sections {
2481400ns my ($self, $parameter, $config_string) = @_;
249
2501300ns if ( defined $config_string ) {
251 $self->{_lib_sections} = [ _parse_sections( $config_string ) ];
252 }
253
25414µs return;
255}
256
257
# spent 2µs within Perl::Critic::Policy::Documentation::RequirePodSections::_parse_script_sections 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_script_sections {
2581500ns my ($self, $parameter, $config_string) = @_;
259
2601300ns if ( defined $config_string ) {
261 $self->{_script_sections} = [ _parse_sections( $config_string ) ];
262 }
263
26413µs return;
265}
266
267#-----------------------------------------------------------------------------
268
269sub initialize_if_enabled {
270 my ($self, $config) = @_;
271
272 my $source = $self->{_source};
273 if ( not defined $source or not defined $DEFAULT_LIB_SECTIONS{$source} ) {
274 $source = $DEFAULT_SOURCE;
275 }
276
277 my $language = $self->{_language};
278 if (
279 not defined $language
280 or not defined $DEFAULT_LIB_SECTIONS{$source}{$language}
281 ) {
282 $language = $SOURCE_DEFAULT_LANGUAGE{$source};
283 }
284
285 if ( not $self->_sections_specified('_lib_sections') ) {
286 $self->{_lib_sections} = $DEFAULT_LIB_SECTIONS{$source}{$language};
287 }
288 if ( not $self->_sections_specified('_script_sections') ) {
289 $self->{_script_sections} =
290 $DEFAULT_SCRIPT_SECTIONS{$source}{$language};
291 }
292
293 return $TRUE;
294}
295
296sub _sections_specified {
297 my ( $self, $sections_key ) = @_;
298
299 my $sections = $self->{$sections_key};
300
301 return 0 if not defined $sections;
302
303 return scalar @{ $sections };
304}
305
306#-----------------------------------------------------------------------------
307
308sub violates {
309 my ( $self, $elem, $doc ) = @_;
310
311 # This policy does not apply unless there is some real code in the
312 # file. For example, if this file is just pure POD, then
313 # presumably this file is ancillary documentation and you can use
314 # whatever headings you want.
315 return if ! $doc->schild(0);
316
317 my %found_sections = ();
318 my @violations = ();
319
320 my @required_sections =
321 $doc->is_program()
322 ? @{ $self->{_script_sections} }
323 : @{ $self->{_lib_sections} };
324
325 my $pods_ref = $doc->find('PPI::Token::Pod');
326 return if not $pods_ref;
327
328 # Round up the names of all the =head1 sections
329 my $pod_of_record;
330 for my $pod ( @{ $pods_ref } ) {
331 for my $found ( $pod =~ m{ ^ =head1 \s+ ( .+? ) \s* $ }gxms ) {
332 # Use first matching POD as POD of record (RT #59268)
333 $pod_of_record ||= $pod;
334 #Leading/trailing whitespace is already removed
335 $found_sections{ uc $found } = 1;
336 }
337 }
338
339 # Compare the required sections against those we found
340 for my $required ( @required_sections ) {
341 if ( not exists $found_sections{$required} ) {
342 my $desc = qq{Missing "$required" section in POD};
343 # Report any violations against POD of record rather than whole
344 # document (the point of RT #59268)
345 # But if there are no =head1 records at all, rat out the
346 # first pod found, as being better than blowing up. RT #67231
347 push @violations, $self->violation( $desc, $EXPL,
348 $pod_of_record || $pods_ref->[0] );
349 }
350 }
351
352 return @violations;
353}
354
355124µs1;
356
357__END__