| 1 | package Perl::Critic::Policy::Documentation::PodSpellingscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/; |
| 2 | |
| 3 | use 5.010001scip-perl cpan Perl-Critic 1.156 `5.010001`/; |
| 4 | use strictscip-perl cpan Perl-Critic 1.156 strict/; |
| 5 | use warningsscip-perl cpan Perl-Critic 1.156 warnings/; |
| 6 | |
| 7 | use Englishscip-perl cpan Perl-Critic 1.156 English/ qw(-no_match_vars); |
| 8 | use Readonlyscip-perl cpan Perl-Critic 1.156 Readonly/; |
| 9 | |
| 10 | use File::Specscip-perl cpan Perl-Critic 1.156 File/Spec/; |
| 11 | use File::Tempscip-perl cpan Perl-Critic 1.156 File/Temp/; |
| 12 | use List::SomeUtilsscip-perl cpan Perl-Critic 1.156 List/SomeUtils/ qw(uniq); |
| 13 | use Pod::Spellscip-perl cpan Perl-Critic 1.156 Pod/Spell/ qw< >; |
| 14 | use Pod::Wordlistscip-perl cpan Perl-Critic 1.156 Pod/Wordlist/; |
| 15 | use Text::ParseWordsscip-perl cpan Perl-Critic 1.156 Text/ParseWords/ qw< >; |
| 16 | |
| 17 | use Perl::Critic::Utilsscip-perl cpan Perl-Critic 1.156 Perl/Critic/Utils/ qw( |
| 18 | :characters |
| 19 | :booleans |
| 20 | :severities |
| 21 | ); |
| 22 | use Perl::Critic::Exception::Fatal::Genericscip-perl cpan Perl-Critic 1.156 Perl/Critic/Exception/Fatal/Generic/ qw{ throw_generic }; |
| 23 | |
| 24 | use parentscip-perl cpan Perl-Critic 1.156 parent/ 'Perl::Critic::Policy'; |
| 25 | |
| 26 | our $VERSIONscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$VERSION. = '1.156'; |
| 27 | |
| 28 | #----------------------------------------------------------------------------- |
| 29 | |
| 30 | Readonly::Scalarscip-perl cpan Perl-Critic 1.156 Readonly/Scalar(). my $DESC => q{Check the spelling in your POD}; |
| 31 | Readonly::Scalarscip-perl cpan Perl-Critic 1.156 Readonly/Scalar(). my $EXPL => [148]; |
| 32 | |
| 33 | #----------------------------------------------------------------------------- |
| 34 | |
| 35 | sub supported_parametersscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/supported_parameters(). { |
| 36 | return ( |
| 37 | { |
| 38 | name => 'spell_command', |
| 39 | description => 'The command to invoke to check spelling.', |
| 40 | default_string => 'aspell list', |
| 41 | behavior => 'string', |
| 42 | }, |
| 43 | { |
| 44 | name => 'stop_words', |
| 45 | description => 'The words to not consider as misspelled.', |
| 46 | default_string => $EMPTYscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$EMPTY., |
| 47 | behavior => 'string list', |
| 48 | }, |
| 49 | { |
| 50 | name => 'stop_words_file', |
| 51 | description => 'A file containing words to not consider as misspelled.', |
| 52 | default_string => $EMPTYscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$EMPTY., |
| 53 | behavior => 'string', |
| 54 | }, |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | sub default_severityscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/default_severity(). { return $SEVERITY_LOWESTscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$SEVERITY_LOWEST. } |
| 59 | sub default_themesscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/default_themes(). { return qw( core cosmetic pbp ) } |
| 60 | sub applies_toscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/applies_to(). { return 'PPI::Document' } |
| 61 | |
| 62 | #----------------------------------------------------------------------------- |
| 63 | |
| 64 | my $got_sigpipe = 0; |
| 65 | sub got_sigpipescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/got_sigpipe(). { |
| 66 | return $got_sigpipe; |
| 67 | } |
| 68 | |
| 69 | #----------------------------------------------------------------------------- |
| 70 | |
| 71 | sub initialize_if_enabledscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/initialize_if_enabled(). { |
| 72 | my ( $self, undef ) = @_scip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/`@_`.; |
| 73 | |
| 74 | eval { requirescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/require(). File::Which; 1 } or return $FALSEscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$FALSE.; |
| 75 | |
| 76 | return $FALSEscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$FALSE. if not $self->_derive_spell_command_linescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_derive_spell_command_line().(); |
| 77 | |
| 78 | my $test_code = <<'END_TEST_CODE'; |
| 79 | ;pod |
| 80 | |
| 81 | ;head1 Test The Spell Command |
| 82 | |
| 83 | ;cut |
| 84 | END_TEST_CODE |
| 85 | $test_code =~ s/^;/=/msx; |
| 86 | return $FALSEscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$FALSE. if not $self->_run_spell_commandscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_run_spell_command().($test_code); |
| 87 | |
| 88 | $self->_load_stop_words_filescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_load_stop_words_file().(); |
| 89 | |
| 90 | return $TRUEscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$TRUE.; |
| 91 | } |
| 92 | |
| 93 | #----------------------------------------------------------------------------- |
| 94 | |
| 95 | sub violatesscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/violates(). { |
| 96 | my ( $self, undef, $doc ) = @_scip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/`@_`.; |
| 97 | |
| 98 | my $code = $doc->serializescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/serialize().(); |
| 99 | |
| 100 | my $words = $self->_run_spell_commandscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_run_spell_command().($code); |
| 101 | |
| 102 | return if not $words; # error running spell command |
| 103 | |
| 104 | return if not @{$words}; # no problems found |
| 105 | |
| 106 | return $self->violationscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/violation().( "$DESC: @{$words}", $EXPL, $doc ); |
| 107 | } |
| 108 | |
| 109 | #----------------------------------------------------------------------------- |
| 110 | |
| 111 | sub _derive_spell_command_linescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_derive_spell_command_line(). { |
| 112 | my ($self) = @_scip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/`@_`.; |
| 113 | |
| 114 | my @words = Text::ParseWords::shellwordsscip-perl cpan Perl-Critic 1.156 Text/ParseWords/shellwords().($self->_get_spell_commandscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_get_spell_command().()); |
| 115 | if (!@words) { |
| 116 | return; |
| 117 | } |
| 118 | if (! File::Spec->file_name_is_absolutescip-perl cpan Perl-Critic 1.156 File/Spec/file_name_is_absolute().($words[0])) { |
| 119 | $words[0] = File::Which::whichscip-perl cpan Perl-Critic 1.156 File/Which/which().($words[0]); |
| 120 | } |
| 121 | if (! $words[0] || ! -x $words[0]) { |
| 122 | return; |
| 123 | } |
| 124 | $self->_set_spell_command_linescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_set_spell_command_line().(\@words); |
| 125 | |
| 126 | return $self->_get_spell_command_linescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_get_spell_command_line().(); |
| 127 | } |
| 128 | |
| 129 | #----------------------------------------------------------------------------- |
| 130 | |
| 131 | sub _get_spell_commandscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_get_spell_command(). { |
| 132 | my ( $self ) = @_scip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/`@_`.; |
| 133 | |
| 134 | return $self->{_spell_command}; |
| 135 | } |
| 136 | |
| 137 | #----------------------------------------------------------------------------- |
| 138 | |
| 139 | sub _get_spell_command_linescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_get_spell_command_line(). { |
| 140 | my ( $self ) = @_scip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/`@_`.; |
| 141 | |
| 142 | return $self->{_spell_command_line}; |
| 143 | } |
| 144 | |
| 145 | sub _set_spell_command_linescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_set_spell_command_line(). { |
| 146 | my ( $self, $spell_command_line ) = @_scip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/`@_`.; |
| 147 | |
| 148 | $self->{_spell_command_line} = $spell_command_line; |
| 149 | |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | #----------------------------------------------------------------------------- |
| 154 | |
| 155 | sub _get_stop_wordsscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_get_stop_words(). { |
| 156 | my ( $self ) = @_scip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/`@_`.; |
| 157 | |
| 158 | return $self->{_stop_words}; |
| 159 | } |
| 160 | |
| 161 | sub _set_stop_wordsscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_set_stop_words(). { |
| 162 | my ( $self, $stop_words ) = @_scip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/`@_`.; |
| 163 | |
| 164 | $self->{_stop_words} = $stop_words; |
| 165 | |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | #----------------------------------------------------------------------------- |
| 170 | |
| 171 | sub _get_stop_words_filescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_get_stop_words_file(). { |
| 172 | my ( $self ) = @_scip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/`@_`.; |
| 173 | |
| 174 | return $self->{_stop_words_file}; |
| 175 | } |
| 176 | |
| 177 | #----------------------------------------------------------------------------- |
| 178 | |
| 179 | sub _run_spell_commandscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_run_spell_command(). { |
| 180 | my ($self, $code) = @_scip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/`@_`.; |
| 181 | |
| 182 | my $outfh = File::Temp->newscip-perl cpan Perl-Critic 1.156 File/Temp/new().(); |
| 183 | |
| 184 | my $outfile = $outfh->filenamescip-perl cpan Perl-Critic 1.156 File/Temp/filename().(); |
| 185 | my @words; |
| 186 | |
| 187 | local $EVAL_ERRORscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$EVAL_ERROR. = undef; |
| 188 | |
| 189 | eval { |
| 190 | # temporarily add our special wordlist to this annoying global |
| 191 | local %Pod::Wordlist::Wordlistscip-perl cpan Perl-Critic 1.156 Pod/Wordlist/`%Wordlist`. = ## no critic (ProhibitPackageVars) |
| 192 | %{ $self->_get_stop_wordsscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_get_stop_words().() }; |
| 193 | |
| 194 | openscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/open(). my $infh, '<', \$code |
| 195 | or throw_genericscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/throw_generic(). "error opening scalar: $OS_ERROR"; |
| 196 | |
| 197 | Pod::Spell->newscip-perl cpan Perl-Critic 1.156 Pod/Spell/new().()->parse_from_filehandlescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/parse_from_filehandle().($infh, $outfh); |
| 198 | closescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/close(). $infh or throw_genericscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/throw_generic(). "Failed to close in memory file: $OS_ERROR"; |
| 199 | closescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/close(). $outfh or throw_genericscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/throw_generic(). "Failed to close pod temp file: $OS_ERROR"; |
| 200 | return if not -s $outfile; # Bail out if no words to spellcheck |
| 201 | |
| 202 | # run spell command and fetch output |
| 203 | local $SIGscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/`%SIG`.{PIPE} = sub { $got_sigpipe = 1; }; |
| 204 | my $command_line = joinscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/join(). $SPACEscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$SPACE., @{$self->_get_spell_command_linescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_get_spell_command_line().()}; |
| 205 | openscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/open(). my $aspell_out_fh, q{-|}, "$command_line < $outfile" ## Is this portable?? |
| 206 | or throw_genericscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/throw_generic(). "Failed to open handle to spelling program: $OS_ERROR"; |
| 207 | |
| 208 | @words = uniqscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/uniq().( <$aspell_out_fh> ); |
| 209 | closescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/close(). $aspell_out_fh |
| 210 | or throw_genericscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/throw_generic(). "Failed to close handle to spelling program: $OS_ERROR"; |
| 211 | |
| 212 | chompscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/chomp(). @words; |
| 213 | |
| 214 | # Why is this extra step needed??? |
| 215 | @words = grepscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/grep(). { not existsscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/exists(). $Pod::Wordlist::Wordlistscip-perl cpan Perl-Critic 1.156 Pod/Wordlist/`%Wordlist`.{$_scip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$_.} } @words; ## no critic (ProhibitPackageVars) |
| 216 | 1; |
| 217 | } |
| 218 | or do { |
| 219 | # Eat anything we did ourselves above, propagate anything else. |
| 220 | if ( |
| 221 | $EVAL_ERRORscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$EVAL_ERROR. |
| 222 | and not refscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/ref(). Perl::Critic::Exception::Fatal::Generic->caughtscip-perl cpan Perl-Critic 1.156 Perl/Critic/Exception/Fatal/Generic/caught().() |
| 223 | ) { |
| 224 | refscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/ref(). $EVAL_ERRORscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$EVAL_ERROR. ? $EVAL_ERRORscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$EVAL_ERROR.->rethrowscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/rethrow().() : diescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/die(). $EVAL_ERRORscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/$EVAL_ERROR.; ## no critic (ErrorHandling::RequireCarping) |
| 225 | } |
| 226 | |
| 227 | return; |
| 228 | }; |
| 229 | |
| 230 | return [ @words ]; |
| 231 | } |
| 232 | |
| 233 | #----------------------------------------------------------------------------- |
| 234 | |
| 235 | sub _load_stop_words_filescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_load_stop_words_file(). { |
| 236 | my ($self) = @_scip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/`@_`.; |
| 237 | |
| 238 | my %stop_words = %{ $self->_get_stop_wordsscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_get_stop_words().() }; |
| 239 | |
| 240 | my $file_name = $self->_get_stop_words_filescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_get_stop_words_file().() or return; |
| 241 | |
| 242 | openscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/open(). my $handle, '<', $file_name |
| 243 | or do { warnscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/warn(). qq<Could not open "$file_name": $OS_ERROR\n>; return; }; |
| 244 | |
| 245 | while ( my $line = <$handle> ) { |
| 246 | if ( my $word = _word_from_linescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_word_from_line().($line) ) { |
| 247 | $stop_words{$word} = 1; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | closescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/close(). $handle or warnscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/warn(). qq<Could not close "$file_name": $OS_ERROR\n>; |
| 252 | |
| 253 | $self->_set_stop_wordsscip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_set_stop_words().(\%stop_words); |
| 254 | |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | sub _word_from_linescip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/_word_from_line(). { |
| 259 | my ($line) = @_scip-perl cpan Perl-Critic 1.156 Perl/Critic/Policy/Documentation/PodSpelling/`@_`.; |
| 260 | |
| 261 | $line =~ s< [#] .* \z ><>xms; |
| 262 | $line =~ s< \s+ \z ><>xms; |
| 263 | $line =~ s< \A \s+ ><>xms; |
| 264 | |
| 265 | return $line; |
| 266 | } |
| 267 | |
| 268 | #----------------------------------------------------------------------------- |
| 269 | |
| 270 | 1; |
| 271 | |
| 272 | __END__ |
| 273 | |
| 274 | #----------------------------------------------------------------------------- |
| 275 | |
| 276 | =pod |
| 277 | |
| 278 | =for stopwords foobie foobie-bletch Hmm stopwords |
| 279 | |
| 280 | =head1 NAME |
| 281 | |
| 282 | Perl::Critic::Policy::Documentation::PodSpelling - Check your spelling. |
| 283 | |
| 284 | |
| 285 | =head1 AFFILIATION |
| 286 | |
| 287 | This Policy is part of the core L<Perl::Critic|Perl::Critic> |
| 288 | distribution. |
| 289 | |
| 290 | |
| 291 | =head1 DESCRIPTION |
| 292 | |
| 293 | Did you write the documentation? Check. |
| 294 | |
| 295 | Did you document all of the public methods? Check. |
| 296 | |
| 297 | Is your documentation readable? Hmm... |
| 298 | |
| 299 | Ideally, we'd like Perl::Critic to tell you when your documentation is |
| 300 | inadequate. That's hard to code, though. So, inspired by |
| 301 | L<Test::Spelling|Test::Spelling>, this module checks the spelling of |
| 302 | your POD. It does this by pulling the prose out of the code and |
| 303 | passing it to an external spell checker. It skips over words you |
| 304 | flagged to ignore. If the spell checker returns any misspelled words, |
| 305 | this policy emits a violation. |
| 306 | |
| 307 | If anything else goes wrong -- we can't locate the spell checking program or |
| 308 | (gasp!) your module has no POD -- then this policy passes. |
| 309 | |
| 310 | To add exceptions on a module-by-module basis, add "stopwords" as |
| 311 | described in L<Pod::Spell|Pod::Spell>. For example: |
| 312 | |
| 313 | =for stopwords gibbles |
| 314 | |
| 315 | =head1 Gibble::Manip -- manipulate your gibbles |
| 316 | |
| 317 | =cut |
| 318 | |
| 319 | |
| 320 | =head1 CONFIGURATION |
| 321 | |
| 322 | This policy can be configured to tell which spell checker to use or to |
| 323 | set a global list of spelling exceptions. To do this, put entries in |
| 324 | a F<.perlcriticrc> file like this: |
| 325 | |
| 326 | [Documentation::PodSpelling] |
| 327 | spell_command = aspell list |
| 328 | stop_words = gibbles foobar |
| 329 | stop_words_file = some/path/with/stop/words.txt |
| 330 | |
| 331 | The default spell command is C<aspell list> and it is interpreted as a |
| 332 | shell command. We parse the individual arguments via |
| 333 | L<Text::ParseWords|Text::ParseWords> so feel free to use quotes around |
| 334 | your arguments. If the executable path is an absolute file name, it |
| 335 | is used as-is. If it is a relative file name, we employ |
| 336 | L<File::Which|File::Which> to convert it to an absolute path via the |
| 337 | C<PATH> environment variable. As described in Pod::Spell and |
| 338 | Test::Spelling, the spell checker must accept text on STDIN and print |
| 339 | misspelled words one per line on STDOUT. |
| 340 | |
| 341 | You can specify global stop words via the C<stop_words> and |
| 342 | C<stop_words_file> options. The former is simply split up on |
| 343 | whitespace. The latter is looked at line by line, with anything after |
| 344 | an octothorp ("#") removed and then leading and trailing whitespace |
| 345 | removed. Silly example valid file contents: |
| 346 | |
| 347 | # It's a comment! |
| 348 | |
| 349 | foo |
| 350 | arglbargl # Some other comment. |
| 351 | bar |
| 352 | |
| 353 | The values from C<stop_words> and C<stop_words_file> are merged |
| 354 | together into a single list of exemptions. |
| 355 | |
| 356 | |
| 357 | =head1 NOTES |
| 358 | |
| 359 | A spell checking program is not included with Perl::Critic. |
| 360 | |
| 361 | The results of failures for this policy can be confusing when F<aspell> |
| 362 | complains about words containing punctuation such as hyphens and apostrophes. |
| 363 | In this situation F<aspell> will often only emit part of the word that it |
| 364 | thinks is misspelled. For example, if you ask F<aspell> to check |
| 365 | "foobie-bletch", the output only complains about "foobie". Unfortunately, |
| 366 | you'll have to look through your POD to figure out what the real word that |
| 367 | F<aspell> is complaining about is. One thing to try is looking at the output |
| 368 | of C<< perl -MPod::Spell -e 'print |
| 369 | Pod::Spell->new()->parse_from_file("lib/Your/Module.pm")' >> to see what is |
| 370 | actually being checked for spelling. |
| 371 | |
| 372 | |
| 373 | =head1 PREREQUISITES |
| 374 | |
| 375 | This policy will disable itself if L<File::Which|File::Which> is not |
| 376 | available. |
| 377 | |
| 378 | |
| 379 | =head1 CREDITS |
| 380 | |
| 381 | Initial development of this policy was supported by a grant from the |
| 382 | Perl Foundation. |
| 383 | |
| 384 | |
| 385 | =head1 AUTHOR |
| 386 | |
| 387 | Chris Dolan <[email protected]> |
| 388 | |
| 389 | |
| 390 | =head1 COPYRIGHT |
| 391 | |
| 392 | Copyright (c) 2007-2023 Chris Dolan. Many rights reserved. |
| 393 | |
| 394 | This program is free software; you can redistribute it and/or modify |
| 395 | it under the same terms as Perl itself. The full text of this license |
| 396 | can be found in the LICENSE file included with this module |
| 397 | |
| 398 | =cut |
| 399 | |
| 400 | # Local Variables: |
| 401 | # mode: cperl |
| 402 | # cperl-indent-level: 4 |
| 403 | # fill-column: 78 |
| 404 | # indent-tabs-mode: nil |
| 405 | # c-indentation-style: bsd |
| 406 | # End: |
| 407 | # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |