Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Perl/Critic/Policy/Documentation/PodSpelling.pm |
Statements | Executed 36 statements in 1.49ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 4.99ms | 13.3ms | BEGIN@18 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 902µs | 842ms | BEGIN@21 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 809µs | 900µs | BEGIN@22 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 24µs | 29µs | supported_parameters | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 18µs | 18µs | BEGIN@10 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 13µs | 36µs | BEGIN@30 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 11µs | 442µs | BEGIN@24 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 10µs | 81µs | BEGIN@32 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 8µs | 170µs | BEGIN@20 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 8µs | 12µs | BEGIN@12 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 8µs | 21µs | BEGIN@11 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 8µs | 455µs | BEGIN@14 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 8µs | 27µs | BEGIN@15 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 6µs | 8µs | default_severity | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 5µs | 5µs | BEGIN@17 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 4µs | 4µs | BEGIN@19 | Perl::Critic::Policy::Documentation::PodSpelling::
1 | 1 | 1 | 2µs | 2µs | CORE:qr (opcode) | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | __ANON__[:208] | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | _derive_spell_command_line | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | _get_spell_command | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | _get_spell_command_line | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | _get_stop_words | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | _get_stop_words_file | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | _load_stop_words_file | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | _run_spell_command | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | _set_spell_command_line | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | _set_stop_words | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | _word_from_line | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | applies_to | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | default_themes | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | got_sigpipe | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | initialize_if_enabled | Perl::Critic::Policy::Documentation::PodSpelling::
0 | 0 | 0 | 0s | 0s | violates | Perl::Critic::Policy::Documentation::PodSpelling::
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::PodSpelling; | ||||
9 | |||||
10 | 2 | 48µs | 1 | 18µ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 # spent 18µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@10 |
11 | 2 | 23µs | 2 | 34µ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 # spent 21µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@11
# spent 13µs making 1 call to strict::import |
12 | 2 | 24µs | 2 | 17µ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 # spent 12µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@12
# spent 4µs making 1 call to warnings::import |
13 | |||||
14 | 2 | 24µs | 2 | 903µ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 # spent 455µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@14
# spent 448µs making 1 call to English::import |
15 | 2 | 21µs | 2 | 47µ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 # spent 27µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@15
# spent 20µs making 1 call to Exporter::import |
16 | |||||
17 | 2 | 18µs | 1 | 5µ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 # spent 5µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@17 |
18 | 2 | 106µs | 2 | 13.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 # spent 13.3ms making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@18
# spent 50µs making 1 call to Exporter::import |
19 | 2 | 21µs | 1 | 4µ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 # spent 4µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@19 |
20 | 2 | 24µs | 2 | 332µ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 # spent 170µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@20
# spent 162µs making 1 call to Exporter::Tiny::import |
21 | 2 | 90µs | 1 | 842ms | # 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 # spent 842ms making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@21 |
22 | 2 | 95µs | 1 | 900µ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 # spent 900µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@22 |
23 | |||||
24 | 1 | 600ns | # 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 | ||
25 | :characters | ||||
26 | :booleans | ||||
27 | :severities | ||||
28 | words_from_string | ||||
29 | 1 | 30µs | 2 | 873µs | }; # spent 442µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@24
# spent 431µs making 1 call to Exporter::import |
30 | 2 | 28µs | 2 | 58µ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 # spent 36µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@30
# spent 22µs making 1 call to Exporter::import |
31 | |||||
32 | 2 | 890µs | 2 | 152µ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 # spent 81µs making 1 call to Perl::Critic::Policy::Documentation::PodSpelling::BEGIN@32
# spent 71µs making 1 call to base::import |
33 | |||||
34 | 1 | 600ns | our $VERSION = '1.121'; | ||
35 | |||||
36 | #----------------------------------------------------------------------------- | ||||
37 | |||||
38 | 1 | 11µs | 2 | 47µs | Readonly::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 |
39 | 1 | 1µs | 1 | 22µs | Readonly::Scalar my $DESC => q{Check the spelling in your POD}; # spent 22µs making 1 call to Readonly::Scalar |
40 | 1 | 2µs | 1 | 51µs | Readonly::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 | ||||
45 | return ( | ||||
46 | { | ||||
47 | 1 | 20µs | 4 | 5µ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 | |||||
67 | 1 | 2µ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 | ||
68 | sub default_themes { return qw( core cosmetic pbp ) } | ||||
69 | sub applies_to { return 'PPI::Document' } | ||||
70 | |||||
71 | #----------------------------------------------------------------------------- | ||||
72 | |||||
73 | 1 | 100ns | my $got_sigpipe = 0; | ||
74 | sub got_sigpipe { | ||||
75 | return $got_sigpipe; | ||||
76 | } | ||||
77 | |||||
78 | #----------------------------------------------------------------------------- | ||||
79 | |||||
80 | sub 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 | ||||
93 | END_TEST_CODE | ||||
94 | |||||
95 | $self->_load_stop_words_file(); | ||||
96 | |||||
97 | return $TRUE; | ||||
98 | } | ||||
99 | |||||
100 | #----------------------------------------------------------------------------- | ||||
101 | |||||
102 | sub 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 | |||||
118 | sub _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 | |||||
138 | sub _get_spell_command { | ||||
139 | my ( $self ) = @_; | ||||
140 | |||||
141 | return $self->{_spell_command}; | ||||
142 | } | ||||
143 | |||||
144 | #----------------------------------------------------------------------------- | ||||
145 | |||||
146 | sub _get_spell_command_line { | ||||
147 | my ( $self ) = @_; | ||||
148 | |||||
149 | return $self->{_spell_command_line}; | ||||
150 | } | ||||
151 | |||||
152 | sub _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 | |||||
162 | sub _get_stop_words { | ||||
163 | my ( $self ) = @_; | ||||
164 | |||||
165 | return $self->{_stop_words}; | ||||
166 | } | ||||
167 | |||||
168 | sub _set_stop_words { | ||||
169 | my ( $self, $stop_words ) = @_; | ||||
170 | |||||
171 | $self->{_stop_words} = $stop_words; | ||||
172 | |||||
173 | return; | ||||
174 | } | ||||
175 | |||||
176 | #----------------------------------------------------------------------------- | ||||
177 | |||||
178 | sub _get_stop_words_file { | ||||
179 | my ( $self ) = @_; | ||||
180 | |||||
181 | return $self->{_stop_words_file}; | ||||
182 | } | ||||
183 | |||||
184 | #----------------------------------------------------------------------------- | ||||
185 | |||||
186 | sub _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 | |||||
242 | sub _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 | |||||
265 | sub _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 | |||||
277 | 1 | 9µs | 1; | ||
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 |