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 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 83 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.85';
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__