Test/Pod/Coverage/TrustMe.pm

filter: Statementstmt 92.9% 106 / 114 Branchbran 69.5% 32 / 46 Conditioncond 50.0% 18 / 36 MC/DCmcdc 20.0% 4 / 20 Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 75.8% 176 / 232 CC 39 SCAR 21.7
CC
39
Cov
80%
pod_coverage_ok
14.1
_lib
11.8
all_pod_coverage_ok
9.0
CRAP 8.8
↑ Summary Pod/Coverage/TrustMe/Parser.pm »
1 package Test::Pod::Coverage::TrustMe;
2 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 14 our $VERSION = '0.002002';
6 14 $VERSION =~ tr/_//d;
7  
8 14 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use Test::Builder ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 14 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 14 *import = \&Exporter::import;
14  
15 14 our @EXPORT = qw(
16 all_modules
17 pod_coverage_ok
18 all_pod_coverage_ok
19 );
20  
21 1 ▶sub _blib {
Subroutine _blib: called CC=5 SCAR=19.7
22 1 my $dir = File::Spec->curdir;
23 1 my $try = 5;
24 1 ▶ while ($try--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($try--) 1 0 1
25 1 my $blib = File::Spec->catdir($dir, 'blib');
26 1 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (-d $blib and -d "File::Spec"->catdir($blib, "arch") and -d "File::Spec"->catdir($blib, "lib")) 1 0 1
Condition33%2/6
-d $blib and -d "File::Spec"->catdir($blib, "arch") and -d "File::Spec"->catdir($blib, "lib")
!ll&&!rl&&r
001
-d $blib and -d "File::Spec"->catdir($blib, "arch")
!ll&&!rl&&r
001
MC/DC0%0/3
-d $blib and -d "File::Spec"->catdir($blib, "arch") and -d "File::Spec"->catdir($blib, "lib")
-d $blib -d "File::Spec"->catdir($blib, "arch") -d "File::Spec"->catdir($blib, "lib")
Truth table25%1/4
A and B and C
A= -d $blibB= -d "File::Spec"->catdir($blib, "arch")C= -d "File::Spec"->catdir($blib, "lib")
ABCresult
0XX0
10X0
1100
1111
27 -d $blib
28 && -d File::Spec->catdir($blib, 'arch')
29 && -d File::Spec->catdir($blib, 'lib')
30 ) {
31 1 return $blib;
32 }
33  
34 0 $dir = File::Spec->catdir($dir, File::Spec->updir);
35 }
36 0 return undef;
37 }
38  
39 1 ▶sub _lib {
Subroutine _lib: called CC=7 SCAR=24.7
40 1 my $dir = File::Spec->curdir;
41 1 my $try = 5;
42 1 ▶ while ($try--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($try--) 1 0 1
43 1 my $lib = File::Spec->catdir($dir, 'lib');
44 1 ▶ if (-d $lib) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $lib) 1 0 1
45 1 my @parts = File::Spec->splitdir(Cwd::realpath($lib));
46 1 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (@parts >= 2 and $parts[-1] eq "lib" and $parts[-2] eq "t" || $parts[-2] eq "xt") 0 1 1
Condition33%3/9
@parts >= 2 and $parts[-1] eq "lib" and $parts[-2] eq "t" || $parts[-2] eq "xt"
!ll&&!rl&&r
010
@parts >= 2 and $parts[-1] eq "lib"
!ll&&!rl&&r
001
$parts[-2] eq "t" or $parts[-2] eq "xt"
l!l&&r!l&&!r
001
MC/DC0%0/4
@parts >= 2 and $parts[-1] eq "lib" and $parts[-2] eq "t" || $parts[-2] eq "xt"
@parts >= 2 $parts[-1] eq "lib" $parts[-2] eq "t" $parts[-2] eq "xt"
Truth table20%1/5
A and B and C or D
A= @parts >= 2B= $parts[-1] eq "lib"C= $parts[-2] eq "t"D= $parts[-2] eq "xt"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
47 @parts >= 2
48 && $parts[-1] eq 'lib'
49 && ($parts[-2] eq 't' || $parts[-2] eq 'xt')
50 ) {
51 0 next;
52 }
53  
54 1 return $lib;
55 }
56  
57 0 $dir = File::Spec->catdir($dir, File::Spec->updir);
58 }
59 0 return undef;
60 }
61  
62 1 ▶sub _base_dirs {
Subroutine _base_dirs: called CC=3 SCAR=11.1
63 1 my %find;
64 1 ▶ if (my $lib = _lib()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lib = _lib()) 1 0 1
65 1 $find{Cwd::realpath($lib)}++;
66 }
67 1 ▶ if (my $blib = _blib()) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $blib = _blib()) 1 0 1
68 1 $find{Cwd::realpath(File::Spec->catdir($blib, 'arch'))}++;
69 1 $find{Cwd::realpath(File::Spec->catdir($blib, 'lib'))}++;
70 }
71  
72 1 my @dirs = grep $find{Cwd::realpath($_)}, @INC;
73 1 return @dirs;
74 }
75  
76 1 ▶sub all_modules {
Subroutine all_modules: called CC=7 SCAR=19.6
Pod documented
77 1 my @dirs = @_;
78 1 ▶ @dirs = _base_dirs
Branch: 1 branch
BranchTrueFalseTotal
unless @dirs 1 0 1
79 if !@dirs;
80  
81 1 my %searched;
82 my @modules;
83 1 my %modules;
84  
85 1 my @search = map [$_], @dirs;
86 1 ▶ while (my $search = shift @search) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $search = shift @search) 17 1 18
87 17 my ($dir, @pre) = @$search;
88 next
89 17 ▶ if $searched{Cwd::realpath($dir)}++;
Branch: 1 branch
BranchTrueFalseTotal
if $searched{Cwd::realpath($dir)}++ 1 16 17
90 16 ▶ opendir my $dh, $dir or die;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or die 16 0 16
91 16 my @found = File::Spec->no_upwards(readdir $dh);
92 16 closedir $dh;
93  
94 16 ▶ my @mods = grep /\.pm\z/ && -f File::Spec->catfile($dir, $_), @found;
Condition66%2/3
/\.pm\z/ && -f 'File::Spec'->catfile($dir, $_)
!ll&&!rl&&r
1803
MC/DC50%1/2
/\.pm\z/ && -f 'File::Spec'->catfile($dir, $_)
/\.pm\z/ -f 'File::Spec'->catfile($dir, $_)
Truth table66%2/3
A && B
A= /\.pm\z/B= -f 'File::Spec'->catfile($dir, $_)
ABresult
0X0
100
111
95 16 s/\.pm\z// for @mods;
96 push @modules,
97 16 grep !$modules{$_}++,
98 map join('::', @pre, $_),
99 grep !/\W/,
100 @mods;
101  
102 16 unshift @search,
103 map [ $_->[0], @pre, $_->[1] ],
104 grep -d $_->[0],
105 map [ File::Spec->catdir($dir, $_) => $_ ],
106 grep !/\W/,
107 @found;
108 }
109  
110 1 return @modules;
111 }
112  
113 6 ▶sub _fh_has_encoding {
Subroutine _fh_has_encoding: called CC=2 SCAR=8.1
114 6 my $fh = shift;
115 return !!(
116 6 ▶ defined &PerlIO::get_layers
Condition33%1/3
defined &PerlIO::get_layers && grep(($_ eq 'utf8'), &PerlIO::get_layers($fh))
!ll&&!rl&&r
060
MC/DC0%0/2
defined &PerlIO::get_layers && grep(($_ eq 'utf8'), &PerlIO::get_layers($fh))
defined &PerlIO::get_layers grep(($_ eq 'utf8'), &PerlIO::get_layers($fh))
Truth table33%1/3
A && B
A= defined &PerlIO::get_layersB= grep(($_ eq 'utf8'), &PerlIO::get_layers($fh))
ABresult
0X0
100
111
117 and grep $_ eq 'utf8', PerlIO::get_layers($fh)
118 );
119 }
120  
121 23 ▶sub pod_coverage_ok {
Subroutine pod_coverage_ok: called CC=14 SCAR=26.4
Pod documented
122 23 my $module = shift;
123 23 ▶ my %opts = ref $_[0] eq 'HASH' ? %{ +shift } : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 16 7 23
124 23 ▶ my $msg = shift || "Pod coverage on $module";
Condition100%2/2
shift() || "Pod coverage on $module"
l!l
149
MC/DC100%1/1
shift() || "Pod coverage on $module"
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
125  
126 23 $opts{package} = $module;
127  
128 23 ▶ my $class = delete $opts{coverage_class} || 'Pod::Coverage::TrustMe';
Condition100%2/2
delete $opts{'coverage_class'} || 'Pod::Coverage::TrustMe'
l!l
1112
MC/DC100%1/1
delete $opts{'coverage_class'} || 'Pod::Coverage::TrustMe'
delete $opts{'coverage_class'}
Truth table100%2/2
A
A= delete $opts{'coverage_class'}
Aresult
11
00
129 23 (my $mod = "$class.pm") =~ s{::}{/}g;
130 23 require $mod;
131  
132 23 my $cover = $class->new(%opts);
133  
134 23 ▶ our $Test ||= Test::Builder->new;
Condition66%2/3
our $Test ||= "Test::Builder"->new
l!l&&r!l&&!r
11120
MC/DC0%0/2
our $Test ||= "Test::Builder"->new
our $Test "Test::Builder"->new
Truth table66%2/3
A ||= B
A= our $TestB= "Test::Builder"->new
ABresult
1X1
011
000
135 23 local $Test::Builder::Level = $Test::Builder::Level + 1;
136  
137 23 my $ok;
138 my $extra;
139 23 my $rating = $cover->coverage;
140 23 ▶ if (!defined $rating) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rating) { } 3 20 23
141 3 my $why = $cover->why_unrated;
142 my $symbols
143 = $cover->can('symbols') ? $cover->symbols
144 3 ▶ : do {
Branch: 1 branch
BranchTrueFalseTotal
$cover->can('symbols') ? : 1 2 3
145 # shim for using with Pod::Coverage subclasses rather than TrustMe
146 2 my @symbs = $cover->_get_syms($module);
147 2 ▶ $cover->why_unrated =~ /\Arequiring .* failed\z/
Branch: 1 branch
BranchTrueFalseTotal
$cover->why_unrated =~ /\Arequiring .* failed\z/ ? : 0 2 2
148 ? undef : { map +($_ => 1), @symbs };
149 };
150 3 ▶ $ok = $Test->ok( defined $symbols && !%$symbols, $msg );
Condition66%2/3
defined $symbols && !%$symbols
!ll&&!rl&&r
012
MC/DC50%1/2
defined $symbols && !%$symbols
defined $symbols !%$symbols
Truth table66%2/3
A && not(B)
A= defined $symbolsB= !%$symbols
ABresult
0X0
100
111
151 3 $extra = "$module: $why";
152 }
153 else {
154 20 $ok = $Test->is_eq((map sprintf('%3.0f%%', $_ * 100), $rating, 1), $msg);
155 20 ▶ if (!$ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 3 17 20
156 3 $extra = join('',
157 "Naked subroutines:\n",
158 map " $_\n", sort $cover->uncovered,
159 );
160 }
161 }
162 23 ▶ if (defined $extra) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extra) 6 17 23
163 6 ▶ my $fh = $ok ? $Test->output : $Test->_diag_fh;
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 2 4 6
164 6 ▶ if (!_fh_has_encoding($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_fh_has_encoding($fh)) 6 0 6
165 6 utf8::encode($extra);
166 }
167 6 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 2 4 6
168 2 $Test->note( $extra );
169 }
170 else {
171 4 $Test->diag( $extra );
172 }
173 }
174 23 return $ok;
175 }
176  
177 1 ▶sub all_pod_coverage_ok {
Subroutine all_pod_coverage_ok: called CC=7 SCAR=22.0
Pod documented
178 0 ▶ my %opts = ref $_[0] eq 'HASH' ? %{ +shift } : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 1 1
179 1 my $dirs = delete $opts{dirs};
180 1 ▶ my @modules = all_modules(@{ $dirs || [] });
Condition50%1/2
$dirs || []
l!l
01
MC/DC0%0/1
$dirs || []
$dirs
Truth table50%1/2
A
A= $dirs
Aresult
11
00
181  
182 1 ▶ our $Test ||= Test::Builder->new;
Condition33%1/3
our $Test ||= "Test::Builder"->new
l!l&&r!l&&!r
010
MC/DC0%0/2
our $Test ||= "Test::Builder"->new
our $Test "Test::Builder"->new
Truth table33%1/3
A ||= B
A= our $TestB= "Test::Builder"->new
ABresult
1X1
011
000
183 1 local $Test::Builder::Level = $Test::Builder::Level + 1;
184 1 my $ok = 1;
185  
186 1 ▶ if ( @modules ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@modules) { } 1 0 1
187 1 $Test->plan( tests => scalar @modules );
188  
189 1 for my $module ( @modules ) {
190 3 ▶ pod_coverage_ok( $module, \%opts, @_ ) or $ok = 0;
Branch: 1 branch
BranchTrueFalseTotal
pod_coverage_ok($module, \%opts, @_) or $ok = 0 3 0 3
191 }
192 }
193 else {
194 0 $Test->plan( tests => 1 );
195 0 $Test->ok( 1, "No modules found." );
196 }
197  
198 1 return $ok;
199 }
200  
201 14 1;
202 __END__
↑ Summary Pod/Coverage/TrustMe/Parser.pm »