Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Documentation/RequirePodSections.pm |
Statements | Executed 36 statements in 1.13ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 58µs | 76µs | supported_parameters | Perl::Critic::Policy::Documentation::RequirePodSections::
1 | 1 | 1 | 18µs | 18µs | BEGIN@10 | Perl::Critic::Policy::Documentation::RequirePodSections::
1 | 1 | 1 | 12µs | 23µs | BEGIN@11 | Perl::Critic::Policy::Documentation::RequirePodSections::
1 | 1 | 1 | 8µs | 10µs | default_severity | Perl::Critic::Policy::Documentation::RequirePodSections::
1 | 1 | 1 | 8µs | 30µs | BEGIN@13 | Perl::Critic::Policy::Documentation::RequirePodSections::
1 | 1 | 1 | 8µs | 648µs | BEGIN@15 | Perl::Critic::Policy::Documentation::RequirePodSections::
1 | 1 | 1 | 8µs | 12µs | BEGIN@12 | Perl::Critic::Policy::Documentation::RequirePodSections::
1 | 1 | 1 | 7µs | 57µs | BEGIN@16 | Perl::Critic::Policy::Documentation::RequirePodSections::
1 | 1 | 1 | 3µs | 3µs | _parse_lib_sections | Perl::Critic::Policy::Documentation::RequirePodSections::
1 | 1 | 1 | 2µs | 2µs | _parse_script_sections | Perl::Critic::Policy::Documentation::RequirePodSections::
0 | 0 | 0 | 0s | 0s | _parse_sections | Perl::Critic::Policy::Documentation::RequirePodSections::
0 | 0 | 0 | 0s | 0s | _sections_specified | Perl::Critic::Policy::Documentation::RequirePodSections::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::Documentation::RequirePodSections::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::Documentation::RequirePodSections::
0 | 0 | 0 | 0s | 0s | initialize_if_enabled | Perl::Critic::Policy::Documentation::RequirePodSections::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::Documentation::RequirePodSections::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | ############################################################################## | ||||
2 | # $URL$ | ||||
3 | # $Date$ | ||||
4 | # $Author$ | ||||
5 | # $Revision$ | ||||
6 | ############################################################################## | ||||
7 | |||||
8 | package Perl::Critic::Policy::Documentation::RequirePodSections; | ||||
9 | |||||
10 | 2 | 43µs | 1 | 18µ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 # spent 18µs making 1 call to Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@10 |
11 | 2 | 23µs | 2 | 35µ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 # spent 23µs making 1 call to Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@11
# spent 12µs making 1 call to strict::import |
12 | 2 | 20µs | 2 | 16µ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 # spent 12µs making 1 call to Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | 2 | 26µs | 2 | 52µ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 # spent 30µs making 1 call to Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@13
# spent 22µs making 1 call to Exporter::import |
14 | |||||
15 | 2 | 26µs | 2 | 1.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 # spent 648µs making 1 call to Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@15
# spent 640µs making 1 call to Exporter::import |
16 | 2 | 840µs | 2 | 107µ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 # spent 57µs making 1 call to Perl::Critic::Policy::Documentation::RequirePodSections::BEGIN@16
# spent 50µs making 1 call to base::import |
17 | |||||
18 | 1 | 600ns | our $VERSION = '1.121'; | ||
19 | |||||
20 | #----------------------------------------------------------------------------- | ||||
21 | |||||
22 | 1 | 3µs | 1 | 53µs | Readonly::Scalar my $EXPL => [133, 138]; # spent 53µs making 1 call to Readonly::Scalar |
23 | |||||
24 | 1 | 1µs | 1 | 21µs | Readonly::Scalar my $BOOK => 'book'; # spent 21µs making 1 call to Readonly::Scalar |
25 | 1 | 900ns | 1 | 20µs | Readonly::Scalar my $BOOK_FIRST_EDITION => 'book_first_edition'; # spent 20µs making 1 call to Readonly::Scalar |
26 | 1 | 1µs | 1 | 20µs | Readonly::Scalar my $MODULE_STARTER_PBP => 'module_starter_pbp'; # spent 20µs making 1 call to Readonly::Scalar |
27 | 1 | 1µs | 1 | 19µs | Readonly::Scalar my $M_S_PBP_0_0_3 => 'module_starter_pbp_0_0_3'; # spent 19µs making 1 call to Readonly::Scalar |
28 | |||||
29 | 1 | 800ns | 1 | 24µs | Readonly::Scalar my $DEFAULT_SOURCE => $BOOK_FIRST_EDITION; # spent 24µs making 1 call to Readonly::Scalar |
30 | |||||
31 | 1 | 1µs | 1 | 54µs | Readonly::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 | |||||
38 | 1 | 900ns | 1 | 20µs | Readonly::Scalar my $EN_AU => 'en_AU'; # spent 20µs making 1 call to Readonly::Scalar |
39 | 1 | 800ns | 1 | 20µs | Readonly::Scalar my $EN_US => 'en_US'; # spent 20µs making 1 call to Readonly::Scalar |
40 | 1 | 1µs | 1 | 19µs | Readonly::Scalar my $ORIGINAL_MODULE_VERSION => 'original'; # spent 19µs making 1 call to Readonly::Scalar |
41 | |||||
42 | 1 | 1µs | 1 | 35µs | Readonly::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 | |||||
47 | 1 | 4µs | 1 | 47µs | Readonly::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 | |||||
63 | 1 | 31µs | 10 | 3.02ms | Readonly::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 | |||||
116 | 1 | 28µs | 6 | 218µs | Readonly::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 | ||||
203 | return ( | ||||
204 | { | ||||
205 | 1 | 40µs | 15 | 18µ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 | |||||
233 | 1 | 2µ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 | ||
234 | sub default_themes { return qw(core pbp maintenance) } | ||||
235 | sub applies_to { return 'PPI::Document' } | ||||
236 | |||||
237 | #----------------------------------------------------------------------------- | ||||
238 | |||||
239 | sub _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 | ||||
248 | 1 | 400ns | my ($self, $parameter, $config_string) = @_; | ||
249 | |||||
250 | 1 | 300ns | if ( defined $config_string ) { | ||
251 | $self->{_lib_sections} = [ _parse_sections( $config_string ) ]; | ||||
252 | } | ||||
253 | |||||
254 | 1 | 4µ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 | ||||
258 | 1 | 500ns | my ($self, $parameter, $config_string) = @_; | ||
259 | |||||
260 | 1 | 300ns | if ( defined $config_string ) { | ||
261 | $self->{_script_sections} = [ _parse_sections( $config_string ) ]; | ||||
262 | } | ||||
263 | |||||
264 | 1 | 3µs | return; | ||
265 | } | ||||
266 | |||||
267 | #----------------------------------------------------------------------------- | ||||
268 | |||||
269 | sub 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 | |||||
296 | sub _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 | |||||
308 | sub 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 | |||||
355 | 1 | 24µs | 1; | ||
356 | |||||
357 | __END__ |