From: Tony Cook Date: Thu, 27 Aug 2015 12:26:57 +0000 (+1000) Subject: update for a more current Pod::Spell, including a possible bug X-Git-Tag: v1.004~11 X-Git-Url: http://git.imager.perl.org/imager.git/commitdiff_plain/2e3f63344aa4a777a7b32f63c9ff3a15faede0f5 update for a more current Pod::Spell, including a possible bug --- diff --git a/xt/x20spell.t b/xt/x20spell.t index 5a861725..405f0e20 100644 --- a/xt/x20spell.t +++ b/xt/x20spell.t @@ -3,12 +3,15 @@ use strict; use Test::More; use ExtUtils::Manifest qw(maniread); use File::Temp; -eval "use Pod::Spell 1.01"; -plan skip_all => "Pod::Spell 1.01 required for spellchecking POD" if $@; -my $manifest = maniread(); -my @pod = sort grep !/^inc/ && /\.(pm|pl|pod|PL)$/, keys %$manifest; +eval "use Pod::Spell 1.15"; +plan skip_all => "Pod::Spell 1.15 required for spellchecking POD" if $@; +my @pod = @ARGV; +unless (@pod) { + my $manifest = maniread(); + @pod = sort grep !/^inc/ && /\.(pm|pl|pod|PL)$/, keys %$manifest; +} plan tests => scalar(@pod); -my @stopwords = qw/ +my $my_stopwords = <<'WORDS'; API Addi Addi's @@ -76,12 +79,7 @@ unassociated unseekable untransformed varargs -/; - -local %Pod::Wordlist::Wordlist = %Pod::Wordlist::Wordlist; -for my $stop (@stopwords) { - $Pod::Wordlist::Wordlist{$stop} = 1; -} +WORDS # see for example: # https://bugs.launchpad.net/ubuntu/+source/aspell/+bug/71322 @@ -90,9 +88,28 @@ $ENV{LC_ALL} = "C"; for my $file (@pod) { my $check_fh = File::Temp->new; my $check_filename = $check_fh->filename; - open POD, "< $file" + my $work_fh = File::Temp->new; + my $work_filename = $work_fh->filename; + open my $pod, "<", $file or die "Cannot open $file for spell check: $!\n"; - Pod::Spell->new->parse_from_filehandle(\*POD, $check_fh); + my @local_stop; + my $stop_re = qr/\b(xxxxx)\b/; + while (<$pod>) { + if (/^=for\s+stopwords\s+(.*)/) { + push @local_stop, map quotemeta, split ' ', $1; + my $stop_re_str = join('|', @local_stop); + $stop_re = qr/\b($stop_re_str)\b/; + } + else { + s/$stop_re/ /g; + } + print $work_fh $_; + } + seek $work_fh, 0, SEEK_SET; + my $spell = Pod::Spell->new; + $spell->stopwords->learn_stopwords($my_stopwords); + $spell->parse_from_filehandle($work_fh, $check_fh); + close $work_fh; close $check_fh; my @out = `aspell list <$check_filename`;