Test/Spellunker.pm

filter: Statementstmt 87.5% 70 / 80 Branchbran 70.0% 21 / 30 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 15 / 15 Podpod 100% 5 / 5 totaltotal 81.1% 116 / 143 CC 22 SCAR 17.5
CC
22
Cov
81%
pod_file_spelling_ok
11.1
all_pod_files
8.1
_is_perl
7.3
CRAP 5.8
« Spellunker/CLI/Pod.pm ↑ Summary Spellunker/Pod/Parser.pm »
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
BranchTrueFalseTotal
pod_file_spelling_ok($file) or undef $ok 8 0 8
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
BranchTrueFalseTotal
if -d "blib" 1 0 1
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
BranchTrueFalseTotal
@_ ? : 0 1 1
47 1 my @pod;
48  
49 1 ▶ while (@queue) {
Branch: 1 branch
BranchTrueFalseTotal
if (@queue) 22 1 23
50 22 my $file = shift @queue;
51  
52 # recurse into subdirectories
53 22 ▶ if (-d $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $file) 12 10 22
54 12 ▶ opendir(my $dirhandle, $file) or next;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dirhandle, $file or next 12 0 12
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'
!ll&&!rl&&r
0021
MC/DC0%0/2
$_ ne 'CVS' && $_ ne '.svn'
$_ ne 'CVS' $_ ne '.svn'
Truth table33%1/3
A && B
A= $_ ne 'CVS'B= $_ ne '.svn'
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (-f $file) 10 12 22
66 10 ▶ next unless _is_perl($file);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_perl($file) 2 8 10
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
BranchTrueFalseTotal
if $file =~ /\.PL$/ 0 10 10
78 10 ▶ return 1 if $file =~ /\.p(l|lx|m|od)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\.p(l|lx|m|od)$/ 6 4 10
79 4 ▶ return 1 if $file =~ /\.t$/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /\.t$/ 0 4 4
80  
81 4 ▶ open my $handle, '<', $file or return;
Branch: 1 branch
BranchTrueFalseTotal
open my $handle, "<", $file or return 4 0 4
82 4 my $first = <$handle>;
83  
84 4 ▶ return 1 if defined $first && ($first =~ /^#!.*perl/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $first and $first =~ /^#!.*perl/ 2 2 4
Condition66%2/3
defined $first and $first =~ /^#!.*perl/
!ll&&!rl&&r
022
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/
ABresult
0X0
100
111
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"
l!l
08
MC/DC0%0/1
shift() || "POD spelling for $file"
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
92  
93 8 ▶ if ( !-r $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $file) 0 8 8
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
BranchTrueFalseTotal
unless ($ok) 0 8 8
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__
« Spellunker/CLI/Pod.pm ↑ Summary Spellunker/Pod/Parser.pm »