← 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/Utils/POD.pm
StatementsExecuted 26 statements in 2.46ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111322µs1.37msPerl::Critic::Utils::POD::::BEGIN@22Perl::Critic::Utils::POD::BEGIN@22
11116µs16µsPerl::Critic::Utils::POD::::BEGIN@10Perl::Critic::Utils::POD::BEGIN@10
11112µs396µsPerl::Critic::Utils::POD::::BEGIN@23Perl::Critic::Utils::POD::BEGIN@23
11112µs20µsPerl::Critic::Utils::POD::::BEGIN@25Perl::Critic::Utils::POD::BEGIN@25
1117µs28µsPerl::Critic::Utils::POD::::BEGIN@21Perl::Critic::Utils::POD::BEGIN@21
1117µs11µsPerl::Critic::Utils::POD::::BEGIN@12Perl::Critic::Utils::POD::BEGIN@12
1117µs18µsPerl::Critic::Utils::POD::::BEGIN@11Perl::Critic::Utils::POD::BEGIN@11
1117µs362µsPerl::Critic::Utils::POD::::BEGIN@14Perl::Critic::Utils::POD::BEGIN@14
1114µs4µsPerl::Critic::Utils::POD::::BEGIN@16Perl::Critic::Utils::POD::BEGIN@16
1113µs3µsPerl::Critic::Utils::POD::::BEGIN@17Perl::Critic::Utils::POD::BEGIN@17
1113µs3µsPerl::Critic::Utils::POD::::BEGIN@18Perl::Critic::Utils::POD::BEGIN@18
0000s0sPerl::Critic::Utils::POD::::_get_module_abstract_from_filePerl::Critic::Utils::POD::_get_module_abstract_from_file
0000s0sPerl::Critic::Utils::POD::::_get_module_abstract_from_filehandlePerl::Critic::Utils::POD::_get_module_abstract_from_filehandle
0000s0sPerl::Critic::Utils::POD::::_get_module_abstract_from_stringPerl::Critic::Utils::POD::_get_module_abstract_from_string
0000s0sPerl::Critic::Utils::POD::::_get_pod_section_from_filePerl::Critic::Utils::POD::_get_pod_section_from_file
0000s0sPerl::Critic::Utils::POD::::_get_pod_section_from_filehandlePerl::Critic::Utils::POD::_get_pod_section_from_filehandle
0000s0sPerl::Critic::Utils::POD::::_get_pod_section_from_stringPerl::Critic::Utils::POD::_get_pod_section_from_string
0000s0sPerl::Critic::Utils::POD::::get_module_abstract_for_modulePerl::Critic::Utils::POD::get_module_abstract_for_module
0000s0sPerl::Critic::Utils::POD::::get_module_abstract_from_filePerl::Critic::Utils::POD::get_module_abstract_from_file
0000s0sPerl::Critic::Utils::POD::::get_module_abstract_from_filehandlePerl::Critic::Utils::POD::get_module_abstract_from_filehandle
0000s0sPerl::Critic::Utils::POD::::get_module_abstract_from_stringPerl::Critic::Utils::POD::get_module_abstract_from_string
0000s0sPerl::Critic::Utils::POD::::get_pod_file_for_modulePerl::Critic::Utils::POD::get_pod_file_for_module
0000s0sPerl::Critic::Utils::POD::::get_pod_section_for_modulePerl::Critic::Utils::POD::get_pod_section_for_module
0000s0sPerl::Critic::Utils::POD::::get_pod_section_from_filePerl::Critic::Utils::POD::get_pod_section_from_file
0000s0sPerl::Critic::Utils::POD::::get_pod_section_from_filehandlePerl::Critic::Utils::POD::get_pod_section_from_filehandle
0000s0sPerl::Critic::Utils::POD::::get_pod_section_from_stringPerl::Critic::Utils::POD::get_pod_section_from_string
0000s0sPerl::Critic::Utils::POD::::get_raw_module_abstract_for_modulePerl::Critic::Utils::POD::get_raw_module_abstract_for_module
0000s0sPerl::Critic::Utils::POD::::get_raw_module_abstract_from_filePerl::Critic::Utils::POD::get_raw_module_abstract_from_file
0000s0sPerl::Critic::Utils::POD::::get_raw_module_abstract_from_filehandlePerl::Critic::Utils::POD::get_raw_module_abstract_from_filehandle
0000s0sPerl::Critic::Utils::POD::::get_raw_module_abstract_from_stringPerl::Critic::Utils::POD::get_raw_module_abstract_from_string
0000s0sPerl::Critic::Utils::POD::::get_raw_pod_section_for_modulePerl::Critic::Utils::POD::get_raw_pod_section_for_module
0000s0sPerl::Critic::Utils::POD::::get_raw_pod_section_from_filePerl::Critic::Utils::POD::get_raw_pod_section_from_file
0000s0sPerl::Critic::Utils::POD::::get_raw_pod_section_from_filehandlePerl::Critic::Utils::POD::get_raw_pod_section_from_filehandle
0000s0sPerl::Critic::Utils::POD::::get_raw_pod_section_from_stringPerl::Critic::Utils::POD::get_raw_pod_section_from_string
0000s0sPerl::Critic::Utils::POD::::trim_pod_sectionPerl::Critic::Utils::POD::trim_pod_section
0000s0sPerl::Critic::Utils::POD::::trim_raw_pod_sectionPerl::Critic::Utils::POD::trim_raw_pod_section
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::Utils::POD;
9
10243µs116µs
# spent 16µs within Perl::Critic::Utils::POD::BEGIN@10 which was called: # once (16µs+0s) by Perl::Critic::Violation::BEGIN@26 at line 10
use 5.006001;
# spent 16µs making 1 call to Perl::Critic::Utils::POD::BEGIN@10
11219µs230µs
# spent 18µs (7+11) within Perl::Critic::Utils::POD::BEGIN@11 which was called: # once (7µs+11µs) by Perl::Critic::Violation::BEGIN@26 at line 11
use strict;
# spent 18µs making 1 call to Perl::Critic::Utils::POD::BEGIN@11 # spent 11µs making 1 call to strict::import
12223µs214µs
# spent 11µs (7+4) within Perl::Critic::Utils::POD::BEGIN@12 which was called: # once (7µs+4µs) by Perl::Critic::Violation::BEGIN@26 at line 12
use warnings;
# spent 11µs making 1 call to Perl::Critic::Utils::POD::BEGIN@12 # spent 4µs making 1 call to warnings::import
13
14222µs2718µs
# spent 362µs (7+356) within Perl::Critic::Utils::POD::BEGIN@14 which was called: # once (7µs+356µs) by Perl::Critic::Violation::BEGIN@26 at line 14
use English qw< -no_match_vars >;
# spent 362µs making 1 call to Perl::Critic::Utils::POD::BEGIN@14 # spent 356µs making 1 call to English::import
15
16216µs14µs
# spent 4µs within Perl::Critic::Utils::POD::BEGIN@16 which was called: # once (4µs+0s) by Perl::Critic::Violation::BEGIN@26 at line 16
use IO::String ();
# spent 4µs making 1 call to Perl::Critic::Utils::POD::BEGIN@16
17214µs13µs
# spent 3µs within Perl::Critic::Utils::POD::BEGIN@17 which was called: # once (3µs+0s) by Perl::Critic::Violation::BEGIN@26 at line 17
use Pod::PlainText ();
# spent 3µs making 1 call to Perl::Critic::Utils::POD::BEGIN@17
18218µs13µs
# spent 3µs within Perl::Critic::Utils::POD::BEGIN@18 which was called: # once (3µs+0s) by Perl::Critic::Violation::BEGIN@26 at line 18
use Pod::Select ();
# spent 3µs making 1 call to Perl::Critic::Utils::POD::BEGIN@18
19
20# TODO: non-fatal generic?
21220µs248µs
# spent 28µs (7+21) within Perl::Critic::Utils::POD::BEGIN@21 which was called: # once (7µs+21µs) by Perl::Critic::Violation::BEGIN@26 at line 21
use Perl::Critic::Exception::Fatal::Generic qw< throw_generic >;
# spent 28µs making 1 call to Perl::Critic::Utils::POD::BEGIN@21 # spent 21µs making 1 call to Exporter::import
222153µs21.44ms
# spent 1.37ms (322µs+1.05) within Perl::Critic::Utils::POD::BEGIN@22 which was called: # once (322µs+1.05ms) by Perl::Critic::Violation::BEGIN@26 at line 22
use Perl::Critic::Exception::IO qw< throw_io >;
# spent 1.37ms making 1 call to Perl::Critic::Utils::POD::BEGIN@22 # spent 66µs making 1 call to Exporter::import
23241µs2780µs
# spent 396µs (12+384) within Perl::Critic::Utils::POD::BEGIN@23 which was called: # once (12µs+384µs) by Perl::Critic::Violation::BEGIN@26 at line 23
use Perl::Critic::Utils qw< :characters >;
# spent 396µs making 1 call to Perl::Critic::Utils::POD::BEGIN@23 # spent 384µs making 1 call to Exporter::import
24
2522.07ms228µs
# spent 20µs (12+8) within Perl::Critic::Utils::POD::BEGIN@25 which was called: # once (12µs+8µs) by Perl::Critic::Violation::BEGIN@26 at line 25
use Exporter 'import';
# spent 20µs making 1 call to Perl::Critic::Utils::POD::BEGIN@25 # spent 8µs making 1 call to Exporter::import
26
2711µsour $VERSION = '1.121';
28
29#-----------------------------------------------------------------------------
30
3116µsour @EXPORT_OK = qw(
32 get_pod_file_for_module
33 get_raw_pod_section_from_file
34 get_raw_pod_section_from_filehandle
35 get_raw_pod_section_from_string
36 get_raw_pod_section_for_module
37 get_pod_section_from_file
38 get_pod_section_from_filehandle
39 get_pod_section_from_string
40 get_pod_section_for_module
41 trim_raw_pod_section
42 trim_pod_section
43 get_raw_module_abstract_from_file
44 get_raw_module_abstract_from_filehandle
45 get_raw_module_abstract_from_string
46 get_raw_module_abstract_for_module
47 get_module_abstract_from_file
48 get_module_abstract_from_filehandle
49 get_module_abstract_from_string
50 get_module_abstract_for_module
51);
52
5312µsour %EXPORT_TAGS = (
54 all => \@EXPORT_OK,
55);
56
57#-----------------------------------------------------------------------------
58
59sub get_pod_file_for_module {
60 my ($module_name) = @_;
61
62 # No File::Spec: %INC always uses forward slashes.
63 (my $relative_path = $module_name) =~ s< :: ></>xmsg;
64 $relative_path .= '.pm';
65
66 my $absolute_path = $INC{$relative_path} or return;
67
68 (my $pod_path = $absolute_path) =~ s< [.] [^.]+ \z><.pod>xms;
69 return $pod_path if -f $pod_path;
70
71 return $absolute_path;
72}
73
74#-----------------------------------------------------------------------------
75
76sub get_raw_pod_section_from_file {
77 my ($file_name, $section_name) = @_;
78
79 return _get_pod_section_from_file(
80 $file_name,
81 $section_name,
82 Pod::Select->new(),
83 );
84}
85
86#-----------------------------------------------------------------------------
87
88sub get_raw_pod_section_from_filehandle {
89 my ($file_handle, $section_name) = @_;
90
91 return _get_pod_section_from_filehandle(
92 $file_handle,
93 $section_name,
94 Pod::Select->new(),
95 );
96}
97
98#-----------------------------------------------------------------------------
99
100sub get_raw_pod_section_from_string {
101 my ($source, $section_name) = @_;
102
103 return _get_pod_section_from_string(
104 $source,
105 $section_name,
106 Pod::Select->new(),
107 );
108}
109
110#-----------------------------------------------------------------------------
111
112sub get_raw_pod_section_for_module {
113 my ($module_name, $section_name) = @_;
114
115 my $file_name = get_pod_file_for_module($module_name)
116 or throw_generic qq<Could not find POD for "$module_name".>;
117
118 return get_raw_pod_section_from_file($file_name, $section_name);
119}
120
121#-----------------------------------------------------------------------------
122
123sub get_pod_section_from_file {
124 my ($file_name, $section_name) = @_;
125
126 return _get_pod_section_from_file(
127 $file_name,
128 $section_name,
129 Pod::PlainText->new(),
130 );
131}
132
133#-----------------------------------------------------------------------------
134
135sub get_pod_section_from_filehandle {
136 my ($file_handle, $section_name) = @_;
137
138 return _get_pod_section_from_filehandle(
139 $file_handle,
140 $section_name,
141 Pod::PlainText->new(),
142 );
143}
144
145#-----------------------------------------------------------------------------
146
147sub get_pod_section_from_string {
148 my ($source, $section_name) = @_;
149
150 return _get_pod_section_from_string(
151 $source,
152 $section_name,
153 Pod::PlainText->new(),
154 );
155}
156
157#-----------------------------------------------------------------------------
158
159sub get_pod_section_for_module {
160 my ($module_name, $section_name) = @_;
161
162 my $file_name = get_pod_file_for_module($module_name)
163 or throw_generic qq<Could not find POD for "$module_name".>;
164
165 return get_pod_section_from_file($file_name, $section_name);
166}
167
168#-----------------------------------------------------------------------------
169
170sub _get_pod_section_from_file {
171 my ($file_name, $section_name, $parser) = @_;
172
173 open my $file_handle, '<', $file_name
174 or throw_io
175 message => qq<Could not open "$file_name": $ERRNO>,
176 file_name => $file_name,
177 errno => $ERRNO;
178
179 my $content =
180 _get_pod_section_from_filehandle(
181 $file_handle, $section_name, $parser,
182 );
183
184 close $file_handle
185 or throw_io
186 message => qq<Could not close "$file_name": $ERRNO>,
187 file_name => $file_name,
188 errno => $ERRNO;
189
190 return $content;
191}
192
193#-----------------------------------------------------------------------------
194
195sub _get_pod_section_from_filehandle {
196 my ($file_handle, $section_name, $parser) = @_;
197
198 $parser->select($section_name);
199
200 my $content = $EMPTY;
201 my $content_handle = IO::String->new( \$content );
202
203 $parser->parse_from_filehandle( $file_handle, $content_handle );
204
205 return if $content eq $EMPTY;
206 return $content;
207}
208
209#-----------------------------------------------------------------------------
210
211sub _get_pod_section_from_string {
212 my ($source, $section_name, $parser) = @_;
213
214 my $source_handle = IO::String->new( \$source );
215
216 return
217 _get_pod_section_from_filehandle(
218 $source_handle, $section_name, $parser,
219 );
220}
221
222#-----------------------------------------------------------------------------
223
224sub trim_raw_pod_section {
225 my ($pod) = @_;
226
227 return if not defined $pod;
228
229 $pod =~ s< \A =head1 \b [^\n]* \n $ ><>xms;
230 $pod =~ s< \A \s+ ><>xms;
231 $pod =~ s< \s+ \z ><>xms;
232
233 return $pod;
234}
235
236#-----------------------------------------------------------------------------
237
238sub trim_pod_section {
239 my ($pod) = @_;
240
241 return if not defined $pod;
242
243 $pod =~ s< \A [^\n]* \n ><>xms;
244 $pod =~ s< \A \s* \n ><>xms;
245 $pod =~ s< \s+ \z ><>xms;
246
247 return $pod;
248}
249
250#-----------------------------------------------------------------------------
251
252sub get_raw_module_abstract_from_file {
253 my ($file_name) = @_;
254
255 return
256 _get_module_abstract_from_file(
257 $file_name,
258 Pod::Select->new(),
259 \&trim_raw_pod_section,
260 );
261}
262
263#-----------------------------------------------------------------------------
264
265sub get_raw_module_abstract_from_filehandle {
266 my ($file_handle) = @_;
267
268 return
269 _get_module_abstract_from_filehandle(
270 $file_handle,
271 Pod::Select->new(),
272 \&trim_raw_pod_section,
273 );
274}
275
276#-----------------------------------------------------------------------------
277
278sub get_raw_module_abstract_from_string {
279 my ($source) = @_;
280
281 return
282 _get_module_abstract_from_string(
283 $source,
284 Pod::Select->new(),
285 \&trim_raw_pod_section,
286 );
287}
288
289#-----------------------------------------------------------------------------
290
291sub get_raw_module_abstract_for_module {
292 my ($module_name) = @_;
293
294 my $file_name = get_pod_file_for_module($module_name)
295 or throw_generic qq<Could not find POD for "$module_name".>;
296
297 return get_raw_module_abstract_from_file($file_name);
298}
299
300#-----------------------------------------------------------------------------
301
302sub get_module_abstract_from_file {
303 my ($file_name) = @_;
304
305 return
306 _get_module_abstract_from_file(
307 $file_name,
308 Pod::PlainText->new(),
309 \&trim_pod_section,
310 );
311}
312
313#-----------------------------------------------------------------------------
314
315sub get_module_abstract_from_filehandle {
316 my ($file_handle) = @_;
317
318 return
319 _get_module_abstract_from_filehandle(
320 $file_handle,
321 Pod::PlainText->new(),
322 \&trim_pod_section,
323 );
324}
325
326#-----------------------------------------------------------------------------
327
328sub get_module_abstract_from_string {
329 my ($source) = @_;
330
331 return
332 _get_module_abstract_from_string(
333 $source,
334 Pod::PlainText->new(),
335 \&trim_pod_section,
336 );
337}
338
339#-----------------------------------------------------------------------------
340
341sub get_module_abstract_for_module {
342 my ($module_name) = @_;
343
344 my $file_name = get_pod_file_for_module($module_name)
345 or throw_generic qq<Could not find POD for "$module_name".>;
346
347 return get_module_abstract_from_file($file_name);
348}
349
350#-----------------------------------------------------------------------------
351
352sub _get_module_abstract_from_file {
353 my ($file_name, $parser, $trimmer) = @_;
354
355 open my $file_handle, '<', $file_name
356 or throw_io
357 message => qq<Could not open "$file_name": $ERRNO>,
358 file_name => $file_name,
359 errno => $ERRNO;
360
361 my $module_abstract =
362 _get_module_abstract_from_filehandle(
363 $file_handle, $parser, $trimmer,
364 );
365
366 close $file_handle
367 or throw_io
368 message => qq<Could not close "$file_name": $ERRNO>,
369 file_name => $file_name,
370 errno => $ERRNO;
371
372 return $module_abstract;
373}
374
375#-----------------------------------------------------------------------------
376
377sub _get_module_abstract_from_filehandle { ## no critic (RequireFinalReturn)
378 my ($file_handle, $parser, $trimmer) = @_;
379
380 my $name_section =
381 _get_pod_section_from_filehandle( $file_handle, 'NAME', $parser );
382 return if not $name_section;
383
384 $name_section = $trimmer->($name_section);
385 return if not $name_section;
386
387 # Testing for parser class, blech. But it's a lot simpler and it's all
388 # hidden in the implementation.
389 if ('Pod::Select' eq ref $parser) {
390 if ( $name_section =~ m< \n >xms ) {
391 throw_generic
392 qq<Malformed NAME section in "$name_section". >
393 . q<It must be on a single line>;
394 }
395 }
396 else {
397 $name_section =~ s< \s+ >< >xmsg;
398
399 # Ugh. Pod::PlainText splits up module names.
400 if (
401 $name_section =~ m<
402 \A
403 \s*
404 (
405 \w [ \w:]+ \w
406 )
407 (
408 \s*
409 -
410 .*
411 )?
412 \z
413 >xms
414 ) {
415 my ($module_name, $rest) = ($1, $2);
416
417 $module_name =~ s/ [ ] //xms;
418
419 $name_section = $module_name . ( $rest ? $rest : $EMPTY );
420 }
421 }
422
423 if (
424 $name_section =~ m<
425 \A
426 \s*
427 [\w:]+ # Module name.
428 \s+
429 - # The required single hyphen.
430 \s+
431 (
432 \S # At least one non-whitespace.
433 (?: .* \S)? # Everything up to the last non-whitespace.
434 )
435 \s*
436 \z
437 >xms
438 ) {
439 my $module_abstract = $1;
440 return $module_abstract;
441 }
442
443 if (
444 $name_section =~ m<
445 \A
446 \s*
447 [\w:]+ # Module name.
448 (?: \s* - )? # The single hyphen is now optional.
449 \s*
450 \z
451 >xms
452 ) {
453 return;
454 }
455
456 throw_generic qq<Malformed NAME section in "$name_section".>;
457}
458
459#-----------------------------------------------------------------------------
460
461sub _get_module_abstract_from_string {
462 my ($source, $parser, $trimmer) = @_;
463
464 my $source_handle = IO::String->new( \$source );
465
466 return
467 _get_module_abstract_from_filehandle(
468 $source_handle, $parser, $trimmer,
469 );
470}
471
472#-----------------------------------------------------------------------------
473
47418µs1;
475
476__END__