blib/lib/Code/TidyAll/Plugin/PodSpell.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 81 CC 8 SCAR 35.5
CC
8
Cov
0%
validate_file
72.0
BEGIN
2.0
BEGIN
2.0
CRAP 34.9
1 package Code::TidyAll::Plugin::PodSpell;
2  
3 use strict;
4 use warnings;
5  
6 use Capture::Tiny qw();
7 use IPC::Run3 qw(run3);
8 use Pod::Spell;
9 use Specio::Library::Builtins;
10 use Specio::Library::String;
11 use Text::ParseWords qw(shellwords);
12  
13 use Moo;
14  
15 extends 'Code::TidyAll::Plugin';
16  
17 our $VERSION = '0.83';
18  
19 has ispell_argv => (
20 is => 'ro',
21 isa => t('Str'),
22 default => q{}
23 );
24  
25 has ispell_cmd => (
26 is => 'ro',
27 isa => t('NonEmptyStr'),
28 default => 'ispell'
29 );
30  
31 has suggest => (
32 is => 'ro',
33 isa => t('Bool'),
34 );
35  
36 sub validate_file {
37 my ( $self, $file ) = @_;
38  
39 my ( $text, $error )
40 = Capture::Tiny::capture { Pod::Spell->new->parse_from_file( $file->stringify ) };
41 die $error if $error;
42  
43 my ($output);
44 my @cmd = ( $self->ispell_cmd, shellwords( $self->ispell_argv ), '-a' );
45 eval { run3( \@cmd, \$text, \$output, \$error ) };
46 $error = $@ if $@;
47 die q{error running '} . join( ' ', @cmd ) . q{': } . $error if $error;
48  
49 my ( @errors, %seen );
50 foreach my $line ( split( "\n", $output ) ) {
51 if ( my ( $original, $remaining ) = ( $line =~ /^[\&\?\#] (\S+)\s+(.*)/ ) ) {
52 if ( !$seen{$original}++ ) {
53 my ($suggestions) = ( $remaining =~ /: (.*)/ );
54 if ( $suggestions && $self->suggest ) {
55 push( @errors, sprintf( '%s (suggestions: %s)', $original, $suggestions ) );
56 }
57 else {
58 push( @errors, $original );
59 }
60 }
61 }
62 }
63 die sprintf( "unrecognized words:\n%s\n", join( "\n", sort @errors ) ) if @errors;
64 }
65  
66 1;
67  
68 # ABSTRACT: Use Pod::Spell + ispell with tidyall
69  
70 __END__
71  
72 =pod
73  
74 =encoding UTF-8
75  
76 =head1 NAME
77  
78 Code::TidyAll::Plugin::PodSpell - Use Pod::Spell + ispell with tidyall
79  
80 =head1 VERSION
81  
82 version 0.83
83  
84 =head1 SYNOPSIS
85  
86 In configuration:
87  
88 [PodSpell]
89 select = lib/**/*.{pm,pod}
90 ispell_argv = -p $ROOT/.ispell_english
91 suggest = 1
92  
93 =head1 DESCRIPTION
94  
95 Uses L<Pod::Spell> in combination with
96 L<ispell|http://fmg-www.cs.ucla.edu/geoff/ispell.html> to spell-check POD. Any
97 seemingly misspelled words will be output one per line.
98  
99 You can specify additional valid words by:
100  
101 =over
102  
103 =item *
104  
105 Adding them to your personal ispell dictionary, e.g. ~/.ispell_english
106  
107 =item *
108  
109 Adding them to an ispell dictionary in the project root, then including this in
110 the configuration:
111  
112 ispell_argv = -p $ROOT/.ispell_english
113  
114 =back
115  
116 The dictionary file should contain one word per line.
117  
118 =head1 INSTALLATION
119  
120 Install ispell from your package manager or from the link above.
121  
122 =head1 CONFIGURATION
123  
124 This plugin accepts the following configuration options:
125  
126 =head2 ispell_argv
127  
128 Arguments to pass to ispell. The "-a" flag will always be passed, in order to
129 parse the results.
130  
131 =head2 ispell_cmd
132  
133 The path for the C<ispell> command. By default this is just C<ispell>, meaning
134 that the user's C<PATH> will be searched for the command.
135  
136 =head2 suggest
137  
138 If true, show suggestions next to misspelled words. Default is false.
139  
140 =head1 SUPPORT
141  
142 Bugs may be submitted at L<https://github.com/houseabsolute/perl-code-tidyall/issues>.
143  
144 =head1 SOURCE
145  
146 The source code repository for Code-TidyAll can be found at L<https://github.com/houseabsolute/perl-code-tidyall>.
147  
148 =head1 AUTHORS
149  
150 =over 4
151  
152 =item *
153  
154 Jonathan Swartz <swartz@pobox.com>
155  
156 =item *
157  
158 Dave Rolsky <autarch@urth.org>
159  
160 =back
161  
162 =head1 COPYRIGHT AND LICENSE
163  
164 This software is copyright (c) 2011 - 2022 by Jonathan Swartz.
165  
166 This is free software; you can redistribute it and/or modify it under
167 the same terms as the Perl 5 programming language system itself.
168  
169 The full text of the license can be found in the
170 F<LICENSE> file included with this distribution.
171  
172 =cut