| 1 | package Test::Spellunker; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use 5.008001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Spellunker::Pod; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use parent qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use version; our $VERSION = version->declare("v0.4.0"); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Test::Builder; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | our $SPELLUNKER = Spellunker::Pod->new(); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 18 | pod_file_spelling_ok | ||||||||||||||||||||||||||||
| 19 | all_pod_files_spelling_ok | ||||||||||||||||||||||||||||
| 20 | add_stopwords | ||||||||||||||||||||||||||||
| 21 | load_dictionary | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | my $TEST = Test::Builder->new(); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub all_pod_files_spelling_ok { | ||||||||||||||||||||||||||
|
Subroutine
all_pod_files_spelling_ok: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 1 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | my @files = all_pod_files(@_); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | $TEST->plan(tests => scalar @files); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | my $ok = 1; | |||||||||||||||||||||||||||
| 34 | 1 | for my $file (@files) { | |||||||||||||||||||||||||||
| 35 | 8 | ▶ | pod_file_spelling_ok($file) or undef $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 1 | return $ok; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | ▶ | sub _starting_points { | ||||||||||||||||||||||||||
|
Subroutine
_starting_points: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||
| 41 | 1 | ▶ | return 'blib' if -d 'blib'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | return grep -d, qw(bin lib script); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | ▶ | sub all_pod_files { | ||||||||||||||||||||||||||
|
Subroutine
all_pod_files: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 1 | ▶ | my @queue = @_ ? @_ : _starting_points(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 1 | my @pod; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | ▶ | while (@queue) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 22 | my $file = shift @queue; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # recurse into subdirectories | ||||||||||||||||||||||||||||
| 53 | 22 | ▶ | if (-d $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 12 | ▶ | opendir(my $dirhandle, $file) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 12 | my @newfiles = readdir($dirhandle); | |||||||||||||||||||||||||||
| 56 | 12 | closedir $dirhandle; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 12 | @newfiles = File::Spec->no_upwards(@newfiles); | |||||||||||||||||||||||||||
| 59 | 12 | ▶ | @newfiles = grep { $_ ne "CVS" && $_ ne ".svn" } @newfiles; | ||||||||||||||||||||||||||
|
Condition33%1/3
$_ ne 'CVS' && $_ ne '.svn'
MC/DC0%0/2
$_ ne 'CVS' && $_ ne '.svn'
$_ ne 'CVS'
$_ ne '.svn'
Truth table33%1/3
A && B
A= $_ ne 'CVS'B= $_ ne '.svn'
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 12 | push @queue, map "$file/$_", @newfiles; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # add the file if it meets our criteria | ||||||||||||||||||||||||||||
| 65 | 22 | ▶ | if (-f $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 10 | ▶ | next unless _is_perl($file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 8 | push @pod, $file; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | return @pod; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 10 | ▶ | sub _is_perl { | ||||||||||||||||||||||||||
|
Subroutine
_is_perl: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||
| 75 | 10 | my $file = shift; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 10 | ▶ | return 1 if $file =~ /\.PL$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 10 | ▶ | return 1 if $file =~ /\.p(l|lx|m|od)$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 4 | ▶ | return 1 if $file =~ /\.t$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 4 | ▶ | open my $handle, '<', $file or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 4 | my $first = <$handle>; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 4 | ▶ | return 1 if defined $first && ($first =~ /^#!.*perl/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $first and $first =~ /^#!.*perl/
MC/DC50%1/2
defined $first and $first =~ /^#!.*perl/
defined $first
$first =~ /^#!.*perl/
Truth table66%2/3
A and B
A= defined $firstB= $first =~ /^#!.*perl/
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 2 | return 0; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 8 | ▶ | sub pod_file_spelling_ok { | ||||||||||||||||||||||||||
|
Subroutine
pod_file_spelling_ok: called CC=6 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 8 | my $file = shift; | |||||||||||||||||||||||||||
| 91 | 8 | ▶ | my $name = shift || "POD spelling for $file"; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || "POD spelling for $file"
MC/DC0%0/1
shift() || "POD spelling for $file"
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 8 | ▶ | if ( !-r $file ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | $TEST->ok( 0, $name ); | |||||||||||||||||||||||||||
| 95 | 0 | $TEST->diag("$file does not exist or is unreadable"); | |||||||||||||||||||||||||||
| 96 | 0 | return; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 8 | my @err = $SPELLUNKER->check_file($file); | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 8 | my $ok = @err == 0; | |||||||||||||||||||||||||||
| 102 | 8 | $TEST->ok($ok, "$name"); | |||||||||||||||||||||||||||
| 103 | 8 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | my $msg = "Errors:\n"; | |||||||||||||||||||||||||||
| 105 | 0 | for (@err) { | |||||||||||||||||||||||||||
| 106 | 0 | my ($lineno, $line, $errs) = @$_; | |||||||||||||||||||||||||||
| 107 | 0 | for my $err (@$errs) { | |||||||||||||||||||||||||||
| 108 | 0 | $msg .= " $lineno: $err\n"; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 0 | $TEST->diag($msg); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 8 | return $ok; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1 | ▶ | sub add_stopwords { | ||||||||||||||||||||||||||
|
Subroutine
add_stopwords: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 1 | $SPELLUNKER->add_stopwords(@_); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | ▶ | sub load_dictionary { | ||||||||||||||||||||||||||
|
Subroutine
load_dictionary: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 1 | $SPELLUNKER->load_dictionary(@_); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 2 | 1; | |||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||