← 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/PodSpelling.pm
StatementsExecuted 36 statements in 1.49ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1114.99ms13.3msPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@18Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@18
111902µs842msPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@21Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@21
111809µs900µsPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@22Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@22
11124µs29µsPerl::Critic::Policy::Documentation::PodSpelling::::supported_parametersPerl::Critic::Policy::Documentation::PodSpelling::supported_parameters
11118µs18µsPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@10Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@10
11113µs36µsPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@30Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@30
11111µs442µsPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@24Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@24
11110µs81µsPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@32Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@32
1118µs170µsPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@20Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@20
1118µs12µsPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@12Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@12
1118µs21µsPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@11Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@11
1118µs455µsPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@14Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@14
1118µs27µsPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@15Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@15
1116µs8µsPerl::Critic::Policy::Documentation::PodSpelling::::default_severityPerl::Critic::Policy::Documentation::PodSpelling::default_severity
1115µs5µsPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@17Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@17
1114µs4µsPerl::Critic::Policy::Documentation::PodSpelling::::BEGIN@19Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@19
1112µs2µsPerl::Critic::Policy::Documentation::PodSpelling::::CORE:qrPerl::Critic::Policy::Documentation::PodSpelling::CORE:qr (opcode)
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::__ANON__[:208]Perl::Critic::Policy::Documentation::PodSpelling::__ANON__[:208]
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::_derive_spell_command_linePerl::Critic::Policy::Documentation::PodSpelling::_derive_spell_command_line
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::_get_spell_commandPerl::Critic::Policy::Documentation::PodSpelling::_get_spell_command
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::_get_spell_command_linePerl::Critic::Policy::Documentation::PodSpelling::_get_spell_command_line
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::_get_stop_wordsPerl::Critic::Policy::Documentation::PodSpelling::_get_stop_words
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::_get_stop_words_filePerl::Critic::Policy::Documentation::PodSpelling::_get_stop_words_file
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::_load_stop_words_filePerl::Critic::Policy::Documentation::PodSpelling::_load_stop_words_file
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::_run_spell_commandPerl::Critic::Policy::Documentation::PodSpelling::_run_spell_command
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::_set_spell_command_linePerl::Critic::Policy::Documentation::PodSpelling::_set_spell_command_line
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::_set_stop_wordsPerl::Critic::Policy::Documentation::PodSpelling::_set_stop_words
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::_word_from_linePerl::Critic::Policy::Documentation::PodSpelling::_word_from_line
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::applies_toPerl::Critic::Policy::Documentation::PodSpelling::applies_to
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::default_themesPerl::Critic::Policy::Documentation::PodSpelling::default_themes
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::got_sigpipePerl::Critic::Policy::Documentation::PodSpelling::got_sigpipe
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::initialize_if_enabledPerl::Critic::Policy::Documentation::PodSpelling::initialize_if_enabled
0000s0sPerl::Critic::Policy::Documentation::PodSpelling::::violatesPerl::Critic::Policy::Documentation::PodSpelling::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::PodSpelling;
9
10248µs118µs
# spent 18µs within Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@10 which was called: # once (18µs+0s) by Module::Pluggable::Object::_require at line 10
use 5.006001;
11223µs234µs
# spent 21µs (8+13) within Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@11 which was called: # once (8µs+13µs) by Module::Pluggable::Object::_require at line 11
use strict;
# spent 21µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@11 # spent 13µs making 1 call to strict::import
12224µs217µs
# spent 12µs (8+4) within Perl::Critic::Policy::Documentation::PodSpelling::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::PodSpelling::BEGIN@12 # spent 4µs making 1 call to warnings::import
13
14224µs2903µs
# spent 455µs (8+448) within Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@14 which was called: # once (8µs+448µs) by Module::Pluggable::Object::_require at line 14
use English qw(-no_match_vars);
# spent 455µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@14 # spent 448µs making 1 call to English::import
15221µs247µs
# spent 27µs (8+20) within Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@15 which was called: # once (8µs+20µs) by Module::Pluggable::Object::_require at line 15
use Readonly;
# spent 27µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@15 # spent 20µs making 1 call to Exporter::import
16
17218µs15µs
# spent 5µs within Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@17 which was called: # once (5µs+0s) by Module::Pluggable::Object::_require at line 17
use File::Spec;
182106µs213.3ms
# spent 13.3ms (4.99+8.30) within Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@18 which was called: # once (4.99ms+8.30ms) by Module::Pluggable::Object::_require at line 18
use File::Temp;
# spent 13.3ms making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@18 # spent 50µs making 1 call to Exporter::import
19221µs14µs
# spent 4µs within Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@19 which was called: # once (4µs+0s) by Module::Pluggable::Object::_require at line 19
use IO::String qw< >;
20224µs2332µs
# spent 170µs (8+162) within Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@20 which was called: # once (8µs+162µs) by Module::Pluggable::Object::_require at line 20
use List::MoreUtils qw(uniq);
# spent 170µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@20 # spent 162µs making 1 call to Exporter::Tiny::import
21290µs1842ms
# spent 842ms (902µs+841) within Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@21 which was called: # once (902µs+841ms) by Module::Pluggable::Object::_require at line 21
use Pod::Spell qw< >;
22295µs1900µs
# spent 900µs (809+91) within Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@22 which was called: # once (809µs+91µs) by Module::Pluggable::Object::_require at line 22
use Text::ParseWords qw< >;
23
241600ns
# spent 442µs (11+431) within Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@24 which was called: # once (11µs+431µs) by Module::Pluggable::Object::_require at line 29
use Perl::Critic::Utils qw{
25 :characters
26 :booleans
27 :severities
28 words_from_string
29130µs2873µs};
# spent 442µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@24 # spent 431µs making 1 call to Exporter::import
30228µs258µs
# spent 36µs (13+22) within Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@30 which was called: # once (13µs+22µs) by Module::Pluggable::Object::_require at line 30
use Perl::Critic::Exception::Fatal::Generic qw{ throw_generic };
# spent 36µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@30 # spent 22µs making 1 call to Exporter::import
31
322890µs2152µs
# spent 81µs (10+71) within Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@32 which was called: # once (10µs+71µs) by Module::Pluggable::Object::_require at line 32
use base 'Perl::Critic::Policy';
# spent 81µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@32 # spent 71µs making 1 call to base::import
33
341600nsour $VERSION = '1.121';
35
36#-----------------------------------------------------------------------------
37
38111µs247µsReadonly::Scalar my $POD_RX => qr{\A = (?: for|begin|end ) }xms;
# spent 46µs making 1 call to Readonly::Scalar # spent 2µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::CORE:qr
3911µs122µsReadonly::Scalar my $DESC => q{Check the spelling in your POD};
# spent 22µs making 1 call to Readonly::Scalar
4012µs151µsReadonly::Scalar my $EXPL => [148];
# spent 51µs making 1 call to Readonly::Scalar
41
42#-----------------------------------------------------------------------------
43
44
# spent 29µs (24+5) within Perl::Critic::Policy::Documentation::PodSpelling::supported_parameters which was called: # once (24µs+5µs) by Perl::Critic::Policy::new at line 88 of Perl/Critic/Policy.pm
sub supported_parameters {
45 return (
46 {
47120µs45µs name => 'spell_command',
# spent 5µs making 4 calls to Readonly::Scalar::FETCH, avg 1µs/call
48 description => 'The command to invoke to check spelling.',
49 default_string => 'aspell list',
50 behavior => 'string',
51 },
52 {
53 name => 'stop_words',
54 description => 'The words to not consider as misspelled.',
55 default_string => $EMPTY,
56 behavior => 'string list',
57 },
58 {
59 name => 'stop_words_file',
60 description => 'A file containing words to not consider as misspelled.',
61 default_string => $EMPTY,
62 behavior => 'string',
63 },
64 );
65}
66
6712µs
# spent 8µs (6+1) within Perl::Critic::Policy::Documentation::PodSpelling::default_severity which was called: # once (6µs+1µs) by Perl::Critic::Policy::get_severity at line 331 of Perl/Critic/Policy.pm
sub default_severity { return $SEVERITY_LOWEST }
68sub default_themes { return qw( core cosmetic pbp ) }
69sub applies_to { return 'PPI::Document' }
70
71#-----------------------------------------------------------------------------
72
731100nsmy $got_sigpipe = 0;
74sub got_sigpipe {
75 return $got_sigpipe;
76}
77
78#-----------------------------------------------------------------------------
79
80sub initialize_if_enabled {
81 my ( $self, $config ) = @_;
82
83 eval { require File::Which; 1 } or return $FALSE;
84
85 return $FALSE if not $self->_derive_spell_command_line();
86
87 return $FALSE if not $self->_run_spell_command( <<'END_TEST_CODE' );
88=pod
89
90=head1 Test The Spell Command
91
92=cut
93END_TEST_CODE
94
95 $self->_load_stop_words_file();
96
97 return $TRUE;
98}
99
100#-----------------------------------------------------------------------------
101
102sub violates {
103 my ( $self, $elem, $doc ) = @_;
104
105 my $code = $doc->serialize();
106
107 my $words = $self->_run_spell_command($code);
108
109 return if not $words; # error running spell command
110
111 return if not @{$words}; # no problems found
112
113 return $self->violation( "$DESC: @{$words}", $EXPL, $doc );
114}
115
116#-----------------------------------------------------------------------------
117
118sub _derive_spell_command_line {
119 my ($self) = @_;
120
121 my @words = Text::ParseWords::shellwords($self->_get_spell_command());
122 if (!@words) {
123 return;
124 }
125 if (! File::Spec->file_name_is_absolute($words[0])) {
126 $words[0] = File::Which::which($words[0]);
127 }
128 if (! $words[0] || ! -x $words[0]) {
129 return;
130 }
131 $self->_set_spell_command_line(\@words);
132
133 return $self->_get_spell_command_line();
134}
135
136#-----------------------------------------------------------------------------
137
138sub _get_spell_command {
139 my ( $self ) = @_;
140
141 return $self->{_spell_command};
142}
143
144#-----------------------------------------------------------------------------
145
146sub _get_spell_command_line {
147 my ( $self ) = @_;
148
149 return $self->{_spell_command_line};
150}
151
152sub _set_spell_command_line {
153 my ( $self, $spell_command_line ) = @_;
154
155 $self->{_spell_command_line} = $spell_command_line;
156
157 return;
158}
159
160#-----------------------------------------------------------------------------
161
162sub _get_stop_words {
163 my ( $self ) = @_;
164
165 return $self->{_stop_words};
166}
167
168sub _set_stop_words {
169 my ( $self, $stop_words ) = @_;
170
171 $self->{_stop_words} = $stop_words;
172
173 return;
174}
175
176#-----------------------------------------------------------------------------
177
178sub _get_stop_words_file {
179 my ( $self ) = @_;
180
181 return $self->{_stop_words_file};
182}
183
184#-----------------------------------------------------------------------------
185
186sub _run_spell_command {
187 my ($self, $code) = @_;
188
189 my $infh = IO::String->new( $code );
190
191 my $outfh = File::Temp->new();
192
193 my $outfile = $outfh->filename();
194 my @words;
195
196 local $EVAL_ERROR = undef;
197
198 eval {
199 # temporarily add our special wordlist to this annoying global
200 local %Pod::Wordlist::Wordlist = ## no critic (ProhibitPackageVars)
201 %{ $self->_get_stop_words() };
202
203 Pod::Spell->new()->parse_from_filehandle($infh, $outfh);
204 close $outfh or throw_generic "Failed to close pod temp file: $OS_ERROR";
205 return if not -s $outfile; # Bail out if no words to spellcheck
206
207 # run spell command and fetch output
208 local $SIG{PIPE} = sub { $got_sigpipe = 1; };
209 my $command_line = join $SPACE, @{$self->_get_spell_command_line()};
210 open my $aspell_out_fh, q{-|}, "$command_line < $outfile" ## Is this portable??
211 or throw_generic "Failed to open handle to spelling program: $OS_ERROR";
212
213 @words = uniq( <$aspell_out_fh> );
214 close $aspell_out_fh
215 or throw_generic "Failed to close handle to spelling program: $OS_ERROR";
216
217 for (@words) {
218 chomp;
219 }
220
221 # Why is this extra step needed???
222 @words = grep { not exists $Pod::Wordlist::Wordlist{$_} } @words; ## no critic (ProhibitPackageVars)
223 1;
224 }
225 or do {
226 # Eat anything we did ourselves above, propagate anything else.
227 if (
228 $EVAL_ERROR
229 and not ref Perl::Critic::Exception::Fatal::Generic->caught()
230 ) {
231 ref $EVAL_ERROR ? $EVAL_ERROR->rethrow() : die $EVAL_ERROR; ## no critic (ErrorHandling::RequireCarping)
232 }
233
234 return;
235 };
236
237 return [ @words ];
238}
239
240#-----------------------------------------------------------------------------
241
242sub _load_stop_words_file {
243 my ($self) = @_;
244
245 my %stop_words = %{ $self->_get_stop_words() };
246
247 my $file_name = $self->_get_stop_words_file() or return;
248
249 open my $handle, '<', $file_name
250 or do { warn qq<Could not open "$file_name": $OS_ERROR\n>; return; };
251
252 while ( my $line = <$handle> ) {
253 if ( my $word = _word_from_line($line) ) {
254 $stop_words{$word} = 1;
255 }
256 }
257
258 close $handle or warn qq<Could not close "$file_name": $OS_ERROR\n>;
259
260 $self->_set_stop_words(\%stop_words);
261
262 return;
263}
264
265sub _word_from_line {
266 my ($line) = @_;
267
268 $line =~ s< [#] .* \z ><>xms;
269 $line =~ s< \s+ \z ><>xms;
270 $line =~ s< \A \s+ ><>xms;
271
272 return $line;
273}
274
275#-----------------------------------------------------------------------------
276
27719µs1;
278
279__END__
 
# spent 2µs within Perl::Critic::Policy::Documentation::PodSpelling::CORE:qr which was called: # once (2µs+0s) by Module::Pluggable::Object::_require at line 38
sub Perl::Critic::Policy::Documentation::PodSpelling::CORE:qr; # opcode