blib/lib/Test/Pod/Coverage/Permissive.pm

filter: Statementstmt 97.0% 97 / 100 Branchbran 76.1% 32 / 42 Conditioncond 59.3% 19 / 32 MC/DCmcdc 35.0% 7 / 20 Subroutinesub 100% 13 / 13 Podpod 100% 3 / 3 totaltotal 81.4% 171 / 210 CC 36 SCAR 25.4
CC
36
Cov
85%
all_modules
19.1
pod_coverage_ok
16.2
all_pod_coverage_ok
5.8
CRAP 12.6
↑ Summary
1 package Test::Pod::Coverage::Permissive;
2  
3 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use 5.008009;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Test::More 0.88;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Pod::Coverage;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use YAML::Syck qw(LoadFile DumpFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 9 my $Test = Test::Builder->new;
12  
13 8 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
14 8 my $self = shift;
15 8 my $caller = caller;
16 9 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 8 *{$caller.'::pod_coverage_ok'} = \&pod_coverage_ok;
18 8 *{$caller.'::all_pod_coverage_ok'} = \&all_pod_coverage_ok;
19 8 *{$caller.'::all_modules'} = \&all_modules;
20  
21 8 $Test->exported_to($caller);
22 8 $Test->plan(@_);
23 }
24  
25 =head1 NAME
26  
27 Test::Pod::Coverage::Permissive - Checks for pod coverage regression.
28  
29 =head1 VERSION
30  
31 Version 0.05
32  
33 =cut
34  
35 9 our $VERSION = '0.05';
36  
37 =head1 SYNOPSIS
38  
39 Checks for POD coverage regressions in your code. This module is for large projects, which can't be covered by POD for a
40 5 minutes. If you have small module or your project is fully covered - use L<Test::Pod::Coverage> instead.
41  
42 After first run, this module creates data file, where saves all uncovered subroutines. If you create new uncovered
43 subroutine, it will fail. If you create new package with uncovered subroutines, it will fail. Otherwise it will show
44 diagnostic messages like these:
45  
46 t/03podcoverage.t .. 2/? # YourProject::Controller::Root: naked 4 subroutine(s)
47 # YourProject::Controller::NotRoot: naked 8 subroutine(s)
48 # YorProject::Controller::AlsoNotRoot: naked 3 subroutine(s)
49 ...
50  
51 This module will help you to cover your project step-by-step. And your new code will be covered by POD.
52  
53 Interface is like L<Test::Pod::Coverage>:
54  
55 use Test::Pod::Coverage::Permissive;
56  
57 use Test::More;
58 eval "use Test::Pod::Coverage::Permissive";
59 plan skip_all => "Test::Pod::Coverage::Permissive required for testing POD coverage" if $@;
60 all_pod_coverage_ok();
61  
62 =head1 FUNCTIONS
63  
64 =head2 all_pod_coverage_ok( [$parms] )
65  
66 Checks that the POD code in all modules in the distro have proper POD
67 coverage.
68  
69 If the I<$parms> hashref if passed in, they're passed into the
70 C<Pod::Coverage> object that the function uses. Check the
71 L<Pod::Coverage> manual for what those can be.
72  
73 The exception is the C<coverage_class> parameter, which specifies a class to
74 use for coverage testing. It defaults to C<Pod::Coverage>.
75  
76 =cut
77  
78 1 ▶sub all_pod_coverage_ok {
Subroutine all_pod_coverage_ok: called CC=5 SCAR=17.5
Pod documented
79 1 ▶ my $parms = ( @_ && ( ref $_[0] eq "HASH" ) ) ? shift : {};
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[0] eq 'HASH' ? : 0 1 1
Condition33%1/3
@_ and ref $_[0] eq "HASH"
!ll&&!rl&&r
100
MC/DC0%0/2
@_ and ref $_[0] eq "HASH"
@_ ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
80 1 my $msg = shift;
81  
82 1 my $ok = 1;
83 1 my @modules = all_modules();
84 1 ▶ if (@modules) {
Branch: 1 branch
BranchTrueFalseTotal
if (@modules) { } 1 0 1
85 1 for my $module (@modules) {
86 1 pod_coverage_ok($module, $parms, $msg);
87 }
88 }
89 else {
90 0 ok( 1, "No modules found." );
91 }
92  
93 1 return $ok;
94 }
95  
96 =head2 pod_coverage_ok( $module, [$parms,] $msg )
97  
98 Checks that the POD code in I<$module> has proper POD coverage.
99  
100 If the I<$parms> hashref if passed in, they're passed into the
101 C<Pod::Coverage> object that the function uses. Check the
102 L<Pod::Coverage> manual for what those can be.
103  
104 The exception is the C<coverage_class> parameter, which specifies a class to
105 use for coverage testing. It defaults to C<Pod::Coverage>.
106  
107 =cut
108  
109 11 ▶sub pod_coverage_ok {
Subroutine pod_coverage_ok: called CC=16 SCAR=27.8
Pod documented
110 11 my $module = shift;
111 11 ▶ my %parms = (@_ && (ref $_[0] eq "HASH")) ? %{(shift)} : ();
Branch: 1 branch
BranchTrueFalseTotal
@_ && ref $_[0] eq 'HASH' ? : 3 8 11
Condition100%3/3
@_ and ref $_[0] eq "HASH"
!ll&&!rl&&r
263
MC/DC100%2/2
@_ and ref $_[0] eq "HASH"
@_ ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
112 11 ▶ my $msg = @_ ? shift : "Pod coverage on $module";
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 8 3 11
113 11 my $first_time = !-e 't/pod_correct.yaml';
114 11 ▶ my $correct = eval { LoadFile('t/pod_correct.yaml') } || {};
Condition50%1/2
eval { do { LoadFile('t/pod_correct.yaml') } } || {}
l!l
110
MC/DC0%0/1
eval { do { LoadFile('t/pod_correct.yaml') } } || {}
eval { do { LoadFile('t/pod_correct.yaml') } }
Truth table50%1/2
A
A= eval { do { LoadFile('t/pod_correct.yaml') } }
Aresult
11
00
115 11 my $coverage = Pod::Coverage->new( package => $module, %parms );
116 11 ▶ my $v = $coverage->naked || 0;
Condition100%2/2
$coverage->naked || 0
l!l
110
MC/DC100%1/1
$coverage->naked || 0
$coverage->naked
Truth table100%2/2
A
A= $coverage->naked
Aresult
11
00
117 11 my $ok = 1;
118 11 ▶ if ( defined $coverage->coverage ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $coverage->coverage) { } 8 3 11
119 8 ▶ $correct->{$module} = $v if $first_time;
Branch: 1 branch
BranchTrueFalseTotal
if $first_time 0 8 8
120 8 ▶ if ( $ok = $Test->ok($v <= ($correct->{$module}||0), $msg) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok = $Test->ok($v <= ($correct->{$module} || 0), $msg)) 7 1 8
Condition50%1/2
$correct->{$module} || 0
l!l
08
MC/DC0%0/1
$correct->{$module} || 0
$correct->{$module}
Truth table50%1/2
A
A= $correct->{$module}
Aresult
11
00
121 7 $correct->{$module} = $v;
122 }
123 8 ▶ if ( my $count = $coverage->naked ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $count = $coverage->naked) 1 7 8
124 1 $Test->diag("${module}: naked $count subroutine(s)");
125 }
126 }
127 else { # No symbols
128 3 my $why = $coverage->why_unrated;
129 3 my $nopublics = ( $why =~ "no public symbols defined" );
130 3 ▶ my $verbose = $ENV{HARNESS_VERBOSE} || 0;
Condition100%2/2
$ENV{'HARNESS_VERBOSE'} || 0
l!l
12
MC/DC100%1/1
$ENV{'HARNESS_VERBOSE'} || 0
$ENV{'HARNESS_VERBOSE'}
Truth table100%2/2
A
A= $ENV{'HARNESS_VERBOSE'}
Aresult
11
00
131 3 ▶ $correct->{$module} = undef if $first_time;
Branch: 1 branch
BranchTrueFalseTotal
if $first_time 0 3 3
132 3 ▶ $ok = $nopublics || exists $coverage->{$module};
Condition66%2/3
$nopublics || exists $coverage->{$module}
l!l&&r!l&&!r
201
MC/DC50%1/2
$nopublics || exists $coverage->{$module}
$nopublics exists $coverage->{$module}
Truth table66%2/3
A || B
A= $nopublicsB= exists $coverage->{$module}
ABresult
1X1
011
000
133 3 $Test->ok( $ok, $msg );
134 3 ▶ $Test->diag( "$module: $why" ) unless ( $nopublics && !$verbose );
Branch: 1 branch
BranchTrueFalseTotal
unless $nopublics and not $verbose 2 1 3
Condition100%3/3
$nopublics and not $verbose
!ll&&!rl&&r
111
MC/DC100%2/2
$nopublics and not $verbose
$nopublics not $verbose
Truth table100%3/3
A and not(B)
A= $nopublicsB= not $verbose
ABresult
0X0
100
111
135 }
136  
137 11 DumpFile( 't/pod_correct.yaml', $correct );
138 }
139  
140 =head2 all_modules( [@dirs] )
141  
142 Returns a list of all modules in I<$dir> and in directories below. If
143 no directories are passed, it defaults to F<blib> if F<blib> exists,
144 or F<lib> if not.
145  
146 Note that the modules are as "Foo::Bar", not "Foo/Bar.pm".
147  
148 The order of the files returned is machine-dependent. If you want them
149 sorted, you'll have to sort them yourself.
150  
151 =cut
152  
153 2 ▶sub all_modules {
Subroutine all_modules: called CC=16 SCAR=29.5
Pod documented
154 2 ▶ my @starters = @_ ? @_ : _starting_points();
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 1 2
155 2 my %starters = map { $_, 1 } @starters;
156  
157 2 my @queue = @starters;
158  
159 2 my @modules;
160 2 ▶ while (@queue) {
Branch: 1 branch
BranchTrueFalseTotal
if (@queue) 58 2 60
161 58 my $file = shift @queue;
162 58 ▶ if ( -d $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $file) 40 18 58
163 40 local *DH;
164 40 ▶ opendir DH, $file or next;
Branch: 1 branch
BranchTrueFalseTotal
opendir DH, $file or next 40 0 40
165 40 my @newfiles = readdir DH;
166 40 closedir DH;
167  
168 40 @newfiles = File::Spec->no_upwards(@newfiles);
169 40 ▶ @newfiles = grep { $_ ne "CVS" && $_ ne ".svn" } @newfiles;
Condition33%1/3
$_ ne 'CVS' && $_ ne '.svn'
!ll&&!rl&&r
0056
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
170  
171 40 push @queue, map "$file/$_", @newfiles;
172 }
173 58 ▶ if ( -f $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $file) 18 40 58
174 18 ▶ next unless $file =~ /\.pm$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /\.pm$/ 16 2 18
175  
176 2 my @parts = File::Spec->splitdir($file);
177 2 ▶ shift @parts if @parts && exists $starters{ $parts[0] };
Branch: 1 branch
BranchTrueFalseTotal
if @parts and exists $starters{$parts[0]} 2 0 2
Condition33%1/3
@parts and exists $starters{$parts[0]}
!ll&&!rl&&r
002
MC/DC0%0/2
@parts and exists $starters{$parts[0]}
@parts exists $starters{$parts[0]}
Truth table33%1/3
A and B
A= @partsB= exists $starters{$parts[0]}
ABresult
0X0
100
111
178 2 ▶ shift @parts if @parts && $parts[0] eq "lib";
Branch: 1 branch
BranchTrueFalseTotal
if @parts and $parts[0] eq "lib" 2 0 2
Condition33%1/3
@parts and $parts[0] eq "lib"
!ll&&!rl&&r
002
MC/DC0%0/2
@parts and $parts[0] eq "lib"
@parts $parts[0] eq "lib"
Truth table33%1/3
A and B
A= @partsB= $parts[0] eq "lib"
ABresult
0X0
100
111
179 2 ▶ $parts[-1] =~ s/\.pm$// if @parts;
Branch: 1 branch
BranchTrueFalseTotal
if @parts 2 0 2
180  
181 # Untaint the parts
182 2 for (@parts) {
183 8 ▶ if ( /^([a-zA-Z0-9_\.\-]+)$/ && ( $_ eq $1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^([a-zA-Z0-9_\.\-]+)$/ and $_ eq $1) { } 8 0 8
Condition33%1/3
/^([a-zA-Z0-9_\.\-]+)$/ and $_ eq $1
!ll&&!rl&&r
008
MC/DC0%0/2
/^([a-zA-Z0-9_\.\-]+)$/ and $_ eq $1
/^([a-zA-Z0-9_\.\-]+)$/ $_ eq $1
Truth table33%1/3
A and B
A= /^([a-zA-Z0-9_\.\-]+)$/B= $_ eq $1
ABresult
0X0
100
111
184 8 $_ = $1; # Untaint the original
185 }
186 else {
187 0 die qq{Invalid and untaintable filename "$file"!};
188 }
189 }
190 2 my $module = join( "::", @parts );
191 2 push( @modules, $module );
192 }
193 } # while
194  
195 2 return @modules;
196 }
197  
198 1 ▶sub _starting_points {
Subroutine _starting_points: called CC=2 SCAR=9.2
199 1 ▶ return 'blib' if -e 'blib';
Branch: 1 branch
BranchTrueFalseTotal
if -e "blib" 1 0 1
200 0 return 'lib';
201 }
202  
203 =head1 AUTHOR
204  
205 Andrey Kostenko, C<< <andrey at kostenko.name> >>
206  
207 =head1 BUGS
208  
209 Please report any bugs or feature requests to C<bug-test-pod-coverage-permissive at rt.cpan.org>, or through
210 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Pod-Coverage-Permissive>. I will be notified, and then you'll
211 automatically be notified of progress on your bug as I make changes.
212  
213  
214  
215  
216 =head1 SUPPORT
217  
218 You can find documentation for this module with the perldoc command.
219  
220 perldoc Test::Pod::Coverage::Permissive
221  
222  
223 You can also look for information at:
224  
225 =over 4
226  
227 =item * RT: CPAN's request tracker
228  
229 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Pod-Coverage-Permissive>
230  
231 =item * AnnoCPAN: Annotated CPAN documentation
232  
233 L<http://annocpan.org/dist/Test-Pod-Coverage-Permissive>
234  
235 =item * CPAN Ratings
236  
237 L<http://cpanratings.perl.org/d/Test-Pod-Coverage-Permissive>
238  
239 =item * Search CPAN
240  
241 L<http://search.cpan.org/dist/Test-Pod-Coverage-Permissive/>
242  
243 =back
244  
245  
246 =head1 ACKNOWLEDGEMENTS
247  
248 Thanks to author of L<Test::Pod::Coverage>. 90% of this module is a copy-paste from L<Test::Pod::Coverage>.
249  
250 =head1 LICENSE AND COPYRIGHT
251  
252 Copyright 2010 Andrey Kostenko, based on Andy Lester's L<Test::Pod::Coverage>
253  
254 This program is free software; you can redistribute it and/or modify it
255 under the terms of either: the GNU General Public License as published
256 by the Free Software Foundation; or the Artistic License.
257  
258 See http://dev.perl.org/licenses/ for more information.
259  
260  
261 =cut
262  
263 9 1; # End of Test::Pod::Coverage::Permissive
↑ Summary