← 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__