Test::Spelling makes the following methods available.
add_stopwords
add_stopwords(@words);
add_stopwords(<DATA>); # pull in stop words from the DATA section
Add words that should be skipped by the spell checker. Note that Pod::Spell already skips words believed
to be code, such as everything in verbatim (indented) blocks and code marked up with ""..."", as well as
some common Perl jargon.
all_pod_files
all_pod_files();
all_pod_files(@list_of_directories);
Returns a list of all the Perl files in each directory and its subdirectories, recursively. If no
directories are passed, it defaults to blib if blib exists, or else lib if not. Skips any files in CVS or
.svn directories.
A Perl file is:
• Any file that ends in .PL, .pl, .plx, .pm, .pod or .t.
• Any file that has a first line with a shebang and "perl" on it.
Furthermore, files for which the filter set by "set_pod_file_filter" return false are skipped. By
default, this filter passes everything through.
The order of the files returned is machine-dependent. If you want them sorted, you'll have to sort them
yourself.
all_pod_files_spelling_ok
all_pod_files_spelling_ok(@list_of_files);
all_pod_files_spelling_ok(@list_of_directories);
Checks all the files for "POD" spelling. It gathers "all_pod_files" in Test::Spelling on each
file/directory, and declares a "plan" in Test::More for you (one test for each file), so you must not
call "plan" yourself.
If @files is empty, the function finds all "POD" files in the blib directory if it exists, or the lib
directory if it does not. A "POD" file is one that ends with .pod, .pl, .plx, or .pm; or any file where
the first line looks like a perl shebang line.
If there is no working spellchecker (determined by <Test:Spelling/"has_working_spellchecker">), this test
will issue a "skip all" directive.
If you're testing a distribution, just create an xt/author/pod-spell.t with the code in the "SYNOPSIS".
Returns true if every "POD" file has correct spelling, or false if any of them fail. This function will
show any spelling errors as diagnostics.
* NOTE: This only tests using bytes. This is not decoded content, etc. Do not expect this to work with
Unicode content, for example. This uses an open with no layers and no decoding.
get_pod_parser
# a Pod::Spell -like object
my $object = get_pod_parser();
Get the object we're using to parse the "POD". A new Pod::Spell object should be used for every file.
People providing custom parsers will have to do this themselves.
has_working_spellchecker
my $cmd = has_working_spellchecker;
"has_working_spellchecker" will return "undef" if there is no working spellchecker, or a true value (the
spellchecker command itself) if there is. The module performs a dry-run to determine whether any of the
spellcheckers it can will use work on the current system. You can use this to skip tests if there is no
spellchecker. Note that "all_pod_files_spelling_ok" will do this for you.
A full list of spellcheckers which this method might test can be found in the source of the
"spellchecker_candidates" method.
pod_file_spelling_ok
pod_file_spelling_ok('/path/to/Foo.pm');
pod_file_spelling_ok('/path/to/Foo.pm', 'Foo is well spelled!');
"pod_file_spelling_ok" will test that the given "POD" file has no spelling errors.
When it fails, "pod_file_spelling_ok" will show any spelling errors as diagnostics.
The optional second argument is the name of the test. If it is omitted, "pod_file_spelling_ok" chooses a
default test name "POD spelling for $filename".
* NOTE: This only tests using bytes. This is not decoded content, etc. Do not expect this to work with
Unicode content, for example. This uses an open with no layers and no decoding.
set_pod_file_filter
# code ref
set_pod_file_filter(sub {
my $filename = shift;
return 0 if $filename =~ /_ja.pod$/; # skip Japanese translations
return 1;
});
If your project has "POD" documents written in languages other than English, then obviously you don't
want to be running a spellchecker on every Perl file. "set_pod_file_filter" lets you filter out files
returned from "all_pod_files" (and hence, the documents tested by "all_pod_files_spelling_ok").
set_pod_parser
my $object = Pod::Spell->new();
set_pod_parser($object);
By default Pod::Spell is used to generate text suitable for spellchecking from the input POD. If you
want to use a different parser, perhaps a customized subclass of Pod::Spell, call "set_pod_parser" with
an object that is-a Pod::Parser. Be sure to create a fresh parser object for each file (don't use this
with "all_pod_files_spelling_ok").
set_spell_cmd
set_spell_cmd('hunspell -l'); # current preferred
set_spell_cmd('aspell list');
set_spell_cmd('spell');
set_spell_cmd('ispell -l');
If you want to force this module to use a particular spellchecker, then you can specify which one with
"set_spell_cmd". This is useful to ensure a more consistent lexicon between developers, or if you have an
unusual environment. Any command that takes text from standard input and prints a list of misspelled
words, one per line, to standard output will do.