Simple/Search.pm

filter: Statementstmt 66.5% 264 / 397 Branchbran 41.1% 111 / 270 Conditioncond 47.7% 54 / 113 MC/DCmcdc 21.3% 13 / 61 Subroutinesub 78.9% 30 / 38 Podpod 57.1% 4 / 7 totaltotal 53.7% 476 / 886 CC 179 SCAR 44.7
CC
179
Cov
55%
_path2modname
268.0
find
158.3
__ANON__
110.0
CRAP 87.7
« Simple/RTF.pm ↑ Summary Simple/Debug.pm »
1 package Pod::Simple::Search;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 13 our $VERSION = '3.48'; ## Current version of this package
6  
7 13 ▶BEGIN { *DEBUG = sub () {0} unless defined &DEBUG; } # set DEBUG level
Subroutine BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
unless defined &Pod::Simple::Search::DEBUG 13 0 13
8 13 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 13 our $SLEEPY;
11 13 ▶$SLEEPY = 1 if !defined $SLEEPY and $^O =~ /mswin|mac/i;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $Pod::Simple::Search::SLEEPY and $^O =~ /mswin|mac/i 0 13 13
Condition33%1/3
not defined $Pod::Simple::Search::SLEEPY and $^O =~ /mswin|mac/i
!ll&&!rl&&r
0130
MC/DC0%0/2
not defined $Pod::Simple::Search::SLEEPY and $^O =~ /mswin|mac/i
not defined $Pod::Simple::Search::SLEEPY $^O =~ /mswin|mac/i
Truth table33%1/3
not(A) and B
A= not defined $Pod::Simple::Search::SLEEPYB= $^O =~ /mswin|mac/i
ABresult
0X0
100
111
12 # flag to occasionally sleep for $SLEEPY - 1 seconds.
13  
14 13 ▶our $MAX_VERSION_WITHIN ||= 60;
Condition50%1/2
our $MAX_VERSION_WITHIN ||= 60
l!l
013
MC/DC0%0/1
our $MAX_VERSION_WITHIN ||= 60
our $MAX_VERSION_WITHIN
Truth table50%1/2
A
A= our $MAX_VERSION_WITHIN
Aresult
11
00
15  
16 #############################################################################
17  
18 #use diagnostics;
19 13 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 13 ▶use File::Basename qw( basename dirname );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 13 ▶use Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 13 ▶use Cwd qw( cwd );
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 #==========================================================================
25 13 __PACKAGE__->_accessorize( # Make my dumb accessor methods
26 'callback', 'progress', 'dir_prefix', 'inc', 'laborious', 'limit_glob',
27 'limit_re', 'shadows', 'verbose', 'name2path', 'path2name', 'recurse',
28 'ciseen', 'is_case_insensitive'
29 );
30 #==========================================================================
31  
32 12 ▶sub new {
Subroutine new: called CC=2 SCAR=7.4
Pod undocumented
33 12 my $class = shift;
34 12 ▶ my $self = bless {}, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0120
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
35 12 $self->init;
36 12 return $self;
37 }
38  
39 12 ▶sub init {
Subroutine init: called CC=2 SCAR=7.1
Pod undocumented
40 12 my $self = shift;
41 12 $self->inc(1);
42 12 $self->recurse(1);
43 12 $self->verbose(DEBUG);
44 12 ▶ $self->is_case_insensitive(-e uc __FILE__ && -e lc __FILE__);
Condition33%1/3
-e '/HOME/CPANCOVER/.CPAN/BUILD/POD-SIMPLE-3.48-0/BLIB/LIB/POD/SIMPLE/SEARCH.PM' && -e '/home/cpancover/.cpan/build/pod-simple-3.48-0/blib/lib/pod/simple/search.pm'
!ll&&!rl&&r
1200
MC/DC0%0/2
-e '/HOME/CPANCOVER/.CPAN/BUILD/POD-SIMPLE-3.48-0/BLIB/LIB/POD/SIMPLE/SEARCH.PM' && -e '/home/cpancover/.cpan/build/pod-simple-3.48-0/blib/lib/pod/simple/search.pm'
-e '/HOME/CPANCOVER/.CPAN/BUILD/POD-SIMPLE-3.48-0/BLIB/LIB/POD/SIMPLE/SEARCH.PM' -e '/home/cpancover/.cpan/build/pod-simple-3.48-0/blib/lib/pod/simple/search.pm'
Truth table33%1/3
A && B
A= -e '/HOME/CPANCOVER/.CPAN/BUILD/POD-SIMPLE-3.48-0/BLIB/LIB/POD/SIMPLE/SEARCH.PM'B= -e '/home/cpancover/.cpan/build/pod-simple-3.48-0/blib/lib/pod/simple/search.pm'
ABresult
0X0
100
111
45 12 return $self;
46 }
47  
48 #--------------------------------------------------------------------------
49  
50 14 ▶sub survey {
Subroutine survey: called CC=20 SCAR=36.8
Pod documented
51 14 my($self, @search_dirs) = @_;
52 14 ▶ $self = $self->new unless ref $self; # tolerate being a class method
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 14 14
53  
54 14 $self->_expand_inc( \@search_dirs );
55  
56 14 $self->{'_scan_count'} = 0;
57 14 $self->{'_dirs_visited'} = {};
58 14 $self->path2name( {} );
59 14 $self->name2path( {} );
60 14 $self->ciseen( {} );
61 14 ▶ $self->limit_re( $self->_limit_glob_to_limit_re ) if $self->{'limit_glob'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"limit_glob"} 5 9 14
62 14 my $cwd = cwd();
63 14 my $verbose = $self->verbose;
64 14 local $_; # don't clobber the caller's $_ !
65  
66 14 foreach my $try (@search_dirs) {
67 29 ▶ unless( File::Spec->file_name_is_absolute($try) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("File::Spec"->file_name_is_absolute($try)) 0 29 29
68 # make path absolute
69 0 $try = File::Spec->catfile( $cwd ,$try);
70 }
71 # simplify path
72 29 $try = File::Spec->canonpath($try);
73  
74 29 my $start_in;
75 my $modname_prefix;
76 29 ▶ if($self->{'dir_prefix'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'dir_prefix'}) { } 3 26 29
77 $start_in = File::Spec->catdir(
78 $try,
79 3 grep length($_), split '[\\/:]+', $self->{'dir_prefix'}
80 );
81 3 $modname_prefix = [grep length($_), split m{[:/\\]}, $self->{'dir_prefix'}];
82 3 ▶ $verbose and print "Appending \"$self->{'dir_prefix'}\" to $try, ",
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print qq[Appending "$self->{"dir_prefix"}" to $try, ], "giving $start_in (= @$modname_prefix)\n" 0 3 3
83 "giving $start_in (= @$modname_prefix)\n";
84 } else {
85 26 $start_in = $try;
86 }
87  
88 29 ▶ if( $self->{'_dirs_visited'}{$start_in} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_dirs_visited'}{$start_in}) { } 0 29 29
89 0 ▶ $verbose and print "Directory '$start_in' already seen, skipping.\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Directory '${start_in}' already seen, skipping.\n" 0 0 0
90 0 next;
91 } else {
92 29 $self->{'_dirs_visited'}{$start_in} = 1;
93 }
94  
95 29 ▶ unless(-e $start_in) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $start_in) 0 29 29
96 0 ▶ $verbose and print "Skipping non-existent $start_in\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Skipping non-existent $start_in\n" 0 0 0
97 0 next;
98 }
99  
100 29 my $closure = $self->_make_search_callback;
101  
102 29 ▶ if(-d $start_in) {
Branch: 2 branches
BranchTrueFalseTotal
if (-d $start_in) { } 29 0 29
elsif (-f _) { } 0 0 0
103 # Normal case:
104 29 ▶ $verbose and print "Beginning excursion under $start_in\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Beginning excursion under $start_in\n" 0 29 29
105 29 $self->_recurse_dir( $start_in, $closure, $modname_prefix );
106 29 ▶ $verbose and print "Back from excursion under $start_in\n\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Back from excursion under $start_in\n\n" 0 29 29
107  
108 } elsif(-f _) {
109 # A excursion consisting of just one file!
110 0 $_ = basename($start_in);
111 0 ▶ $verbose and print "Pondering $start_in ($_)\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Pondering $start_in ($_)\n" 0 0 0
112 0 $closure->($start_in, $_, 0, []);
113  
114 } else {
115 0 ▶ $verbose and print "Skipping mysterious $start_in\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Skipping mysterious $start_in\n" 0 0 0
116 }
117 }
118 14 ▶ $self->progress and $self->progress->done(
Branch: 1 branch
BranchTrueFalseTotal
$self->progress and $self->progress->done(qq[Noted $self->{"_scan_count"} Pod files total]) 0 14 14
119 "Noted $$self{'_scan_count'} Pod files total");
120 14 $self->ciseen( {} );
121  
122 14 ▶ return unless defined wantarray; # void
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 1 13 14
123 13 ▶ return $self->name2path unless wantarray; # scalar
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 13 13
124 13 return $self->name2path, $self->path2name; # list
125 }
126  
127 #==========================================================================
128 29 ▶sub _make_search_callback {
Subroutine _make_search_callback: called CC=2 SCAR=8.2
129 29 my $self = $_[0];
130  
131 # Put the options in variables, for easy access
132 29 my( $laborious, $verbose, $shadows, $limit_re, $callback, $progress,
133 $path2name, $name2path, $recurse, $ciseen, $is_case_insensitive) =
134 map scalar($self->$_()),
135 qw(laborious verbose shadows limit_re callback progress
136 path2name name2path recurse ciseen is_case_insensitive);
137 29 my ($seen, $remember, $files_for);
138 29 ▶ if ($is_case_insensitive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_case_insensitive) { } 0 29 29
139 0 ▶ $seen = sub { $ciseen->{ lc $_[0] } };
Subroutine __ANON__: not called CC=1 SCAR=6.9
140 0 ▶ $remember = sub { $name2path->{ $_[0] } = $ciseen->{ lc $_[0] } = $_[1]; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
141 0 ▶ $files_for = sub { my $n = lc $_[0]; grep { lc $path2name->{$_} eq $n } %{ $path2name } };
Subroutine __ANON__: not called CC=1 SCAR=6.9
142 } else {
143 29 ▶ $seen = sub { $name2path->{ $_[0] } };
Subroutine __ANON__: called CC=1 SCAR=0.0
144 29 ▶ $remember = sub { $name2path->{ $_[0] } = $_[1] };
Subroutine __ANON__: called CC=1 SCAR=0.0
145 0 ▶ $files_for = sub { my $n = $_[0]; grep { $path2name->{$_} eq $n } %{ $path2name } };
Subroutine __ANON__: not called CC=1 SCAR=4.1
146 }
147  
148 29 my($file, $shortname, $isdir, $modname_bits);
149 272 ▶ return sub {
Subroutine __ANON__: called CC=35 SCAR=46.0
150 272 ($file, $shortname, $isdir, $modname_bits) = @_;
151  
152 272 ▶ if($isdir) { # this never gets called on the startdir itself, just subdirs
Branch: 1 branch
BranchTrueFalseTotal
if ($isdir) 81 191 272
153  
154 81 ▶ unless( $recurse ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($recurse) 16 65 81
155 16 ▶ $verbose and print "Not recursing into '$file' as per requested.\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Not recursing into '${file}' as per requested.\n" 0 16 16
156 16 return 'PRUNE';
157 }
158  
159 65 ▶ if( $self->{'_dirs_visited'}{$file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_dirs_visited"}{$file}) 0 65 65
160 0 ▶ $verbose and print "Directory '$file' already seen, skipping.\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Directory '${file}' already seen, skipping.\n" 0 0 0
161 0 return 'PRUNE';
162 }
163  
164 65 ▶ print "Looking in dir $file\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 65 65
165  
166 65 ▶ unless ($laborious) { # $laborious overrides pruning
Branch: 1 branch
BranchTrueFalseTotal
unless ($laborious) 65 0 65
167 65 ▶ if( m/^(\d+\.[\d_]{3,})\z/s
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\d+\.[\d_]{3,})\z/s and do { my $x = $1; $x =~ tr/_//d; $x != $] }) 0 65 65
Condition33%1/3
/^(\d+\.[\d_]{3,})\z/s and do { my $x = $1; $x =~ tr/_//d; $x != $] }
!ll&&!rl&&r
6500
MC/DC0%0/2
/^(\d+\.[\d_]{3,})\z/s and do { my $x = $1; $x =~ tr/_//d; $x != $] }
/^(\d+\.[\d_]{3,})\z/s do { my $x = $1; $x =~ tr/_//d; $x != $] }
Truth table33%1/3
A and B
A= /^(\d+\.[\d_]{3,})\z/sB= do { my $x = $1; $x =~ tr/_//d; $x != $] }
ABresult
0X0
100
111
168 0 and do { my $x = $1; $x =~ tr/_//d; $x != $] }
169 ) {
170 0 ▶ $verbose and print "Perl $] version mismatch on $_, skipping.\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Perl $] version mismatch on $_, skipping.\n" 0 0 0
171 0 return 'PRUNE';
172 }
173  
174 65 ▶ if( m/^([A-Za-z][a-zA-Z0-9_]*)\z/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^([A-Za-z][a-zA-Z0-9_]*)\z/s) { } 65 0 65
175 65 ▶ $verbose and print "$_ is a well-named module subdir. Looking....\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "$_ is a well-named module subdir. Looking....\n" 0 65 65
176 } else {
177 0 ▶ $verbose and print "$_ is a fishy directory name. Skipping.\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "$_ is a fishy directory name. Skipping.\n" 0 0 0
178 0 return 'PRUNE';
179 }
180 } # end unless $laborious
181  
182 65 $self->{'_dirs_visited'}{$file} = 1;
183 65 return; # (not pruning);
184 }
185  
186 # Make sure it's a file even worth even considering
187 191 ▶ if($laborious) {
Branch: 1 branch
BranchTrueFalseTotal
if ($laborious) { } 0 191 191
188 0 ▶ unless(
Branch: 1 branch
BranchTrueFalseTotal
unless (/\.(pod|pm|plx?)\z/i || -x _ and -T _) 0 0 0
Condition0%0/6
/\.(pod|pm|plx?)\z/i || -x _ and -T _
!ll&&!rl&&r
000
/\.(pod|pm|plx?)\z/i or -x _
l!l&&r!l&&!r
000
MC/DC0%0/3
/\.(pod|pm|plx?)\z/i || -x _ and -T _
/\.(pod|pm|plx?)\z/i -x _ -T _
Truth table0%0/5
A or B and C
A= /\.(pod|pm|plx?)\z/iB= -x _C= -T _
ABCresult
00X0
1X00
0100
1X11
0111
189 m/\.(pod|pm|plx?)\z/i || -x _ and -T _
190 # Note that the cheapest operation (the RE) is run first.
191 ) {
192 0 ▶ $verbose > 1 and print " Brushing off uninteresting $file\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 1 and print " Brushing off uninteresting $file\n" 0 0 0
193 0 return;
194 }
195 } else {
196 191 ▶ unless( m/^[-_a-zA-Z0-9]+\.(?:pod|pm|plx?)\z/is ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/^[-_a-zA-Z0-9]+\.(?:pod|pm|plx?)\z/is) 24 167 191
197 24 ▶ $verbose > 1 and print " Brushing off oddly-named $file\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 1 and print " Brushing off oddly-named $file\n" 0 24 24
198 24 return;
199 }
200 }
201  
202 167 ▶ $verbose and print "Considering item $file\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Considering item $file\n" 0 167 167
203 167 my $name = $self->_path2modname( $file, $shortname, $modname_bits );
204 167 ▶ $verbose > 0.01 and print " Nominating $file as $name\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > "0.01" and print " Nominating $file as $name\n" 0 167 167
205  
206 167 ▶ if($limit_re and $name !~ m/$limit_re/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit_re and not $name =~ /$limit_re/i) 62 105 167
Condition100%3/3
$limit_re and not $name =~ /$limit_re/i
!ll&&!rl&&r
822362
MC/DC100%2/2
$limit_re and not $name =~ /$limit_re/i
$limit_re not $name =~ /$limit_re/i
Truth table100%3/3
A and not(B)
A= $limit_reB= not $name =~ /$limit_re/i
ABresult
0X0
100
111
207 62 ▶ $verbose and print "Shunning $name as not matching $limit_re\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Shunning $name as not matching $limit_re\n" 0 62 62
208 62 return;
209 }
210  
211 105 ▶ if( !$shadows and $seen->($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $shadows and &$seen($name)) 4 101 105
Condition100%3/3
not $shadows and &$seen($name)
!ll&&!rl&&r
43584
MC/DC100%2/2
not $shadows and &$seen($name)
not $shadows &$seen($name)
Truth table100%3/3
not(A) and B
A= not $shadowsB= &$seen($name)
ABresult
0X0
100
111
212 4 ▶ $verbose and print "Not worth considering $file ",
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Not worth considering $file ", "-- already saw $name as ", join(" ", &$files_for($name)), "\n" 0 4 4
213 "-- already saw $name as ",
214 join(' ', $files_for->($name)), "\n";
215 4 return;
216 }
217  
218 # Put off until as late as possible the expense of
219 # actually reading the file:
220 101 ▶ $progress and $progress->reach($self->{'_scan_count'}, "Scanning $file");
Branch: 1 branch
BranchTrueFalseTotal
$progress and $progress->reach($self->{"_scan_count"}, "Scanning $file") 0 101 101
221 101 ▶ return unless $self->contains_pod( $file );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->contains_pod($file) 6 95 101
222 95 ++ $self->{'_scan_count'};
223  
224 # Or finally take note of it:
225 95 ▶ if ( my $prev = $seen->($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $prev = &$seen($name)) { } 10 85 95
226 10 ▶ $verbose and print
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Duplicate POD found (shadowing?): $name ($file)\n", " Already seen in ", join(" ", &$files_for($name)), "\n" 0 10 10
227 "Duplicate POD found (shadowing?): $name ($file)\n",
228 " Already seen in ", join(' ', $files_for->($name)), "\n";
229 } else {
230 85 $remember->($name, $file); # Noting just the first occurrence
231 }
232 95 ▶ $verbose and print " Noting $name = $file\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print " Noting $name = $file\n" 0 95 95
233 95 ▶ if( $callback ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($callback) 18 77 95
234 18 local $_ = $_; # insulate from changes, just in case
235 18 $callback->($file, $name);
236 }
237 95 $path2name->{$file} = $name;
238 95 return;
239 }
240 29 }
241  
242 #==========================================================================
243  
244 167 ▶sub _path2modname {
Subroutine _path2modname: called CC=27 SCAR=55.9
245 167 my($self, $file, $shortname, $modname_bits) = @_;
246  
247 # this code simplifies the POD name for Perl modules:
248 # * remove "site_perl"
249 # * remove e.g. "i586-linux" (from 'archname')
250 # * remove e.g. 5.00503
251 # * remove pod/ if followed by perl*.pod (e.g. in pod/perlfunc.pod)
252 # * dig into the file for case-preserved name if not already mixed case
253  
254 167 my @m = @$modname_bits;
255 167 my $x;
256 167 my $verbose = $self->verbose;
257  
258 # Shaving off leading naughty-bits
259 167 ▶ while(@m
Branch: 1 branch
BranchTrueFalseTotal
if (@m and defined($x = lc $m[0]) and $x eq "site_perl" || $x =~ /^pods?$/ && @m == 1 && $shortname =~ /^perl.*\.pod$/s || $x =~ /\\d+\\.z\\d+([_.]?\\d+)?/ || $x eq lc $Config::Config{"archname"}) 36 167 203
Condition71%15/21
@m and defined($x = lc $m[0]) and $x eq "site_perl" || $x =~ /^pods?$/ && @m == 1 && $shortname =~ /^perl.*\.pod$/s || $x =~ /\\d+\\.z\\d+([_.]?\\d+)?/ || $x eq lc $Config::Config{"archname"}
!ll&&!rl&&r
798836
@m and defined($x = lc $m[0])
!ll&&!rl&&r
790124
$x eq "site_perl" or $x =~ /^pods?$/ and @m == 1 and $shortname =~ /^perl.*\.pod$/s or $x =~ /\\d+\\.z\\d+([_.]?\\d+)?/ or $x eq lc $Config::Config{"archname"}
l!l&&r!l&&!r
36088
$x eq "site_perl" or $x =~ /^pods?$/ and @m == 1 and $shortname =~ /^perl.*\.pod$/s or $x =~ /\\d+\\.z\\d+([_.]?\\d+)?/
l!l&&r!l&&!r
36088
$x eq "site_perl" or $x =~ /^pods?$/ and @m == 1 and $shortname =~ /^perl.*\.pod$/s
l!l&&r!l&&!r
03688
$x =~ /^pods?$/ and @m == 1 and $shortname =~ /^perl.*\.pod$/s
!ll&&!rl&&r
88036
$x =~ /^pods?$/ and @m == 1
!ll&&!rl&&r
88036
MC/DC25%2/8
@m and defined($x = lc $m[0]) and $x eq "site_perl" || $x =~ /^pods?$/ && @m == 1 && $shortname =~ /^perl.*\.pod$/s || $x =~ /\\d+\\.z\\d+([_.]?\\d+)?/ || $x eq lc $Config::Config{"archname"}
@m defined($x = lc $m[0]) $x eq "site_perl" $x =~ /^pods?$/ @m == 1 $shortname =~ /^perl.*\.pod$/s $x =~ /\\d+\\.z\\d+([_.]?\\d+)?/ $x eq lc $Config::Config{"archname"}
Truth table23%3/13
A and B and C or D and E and F or G or H
A= @mB= defined($x = lc $m[0])C= $x eq "site_perl"D= $x =~ /^pods?$/E= @m == 1F= $shortname =~ /^perl.*\.pod$/sG= $x =~ /\\d+\\.z\\d+([_.]?\\d+)?/H= $x eq lc $Config::Config{"archname"}
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
1100XX000
11010X000
110110000
111XXXXX1
110111XX1
1100XX1X1
11010X1X1
1101101X1
1100XX011
11010X011
110110011
260 and defined($x = lc( $m[0] ))
261 and( $x eq 'site_perl'
262 or($x =~ m/^pods?$/ and @m == 1 and $shortname =~ m{^perl.*\.pod$}s )
263 or $x =~ m{\\d+\\.z\\d+([_.]?\\d+)?} # if looks like a vernum
264 or $x eq lc( $Config::Config{'archname'} )
265 36 )) { shift @m }
266  
267 167 my $name = join '::', @m, $shortname;
268 167 $self->_simplify_base($name);
269  
270 # On VMS, case-preserved document names can't be constructed from
271 # filenames, so try to extract them from the "=head1 NAME" tag in the
272 # file instead.
273 167 ▶ if ($^O eq 'VMS' && ($name eq lc($name) || $name eq uc($name))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "VMS" and $name eq lc $name || $name eq uc $name) 0 167 167
Condition16%1/6
$^O eq "VMS" and $name eq lc $name || $name eq uc $name
!ll&&!rl&&r
16700
$name eq lc $name or $name eq uc $name
l!l&&r!l&&!r
000
MC/DC0%0/3
$^O eq "VMS" and $name eq lc $name || $name eq uc $name
$^O eq "VMS" $name eq lc $name $name eq uc $name
Truth table25%1/4
A and B or C
A= $^O eq "VMS"B= $name eq lc $nameC= $name eq uc $name
ABCresult
0XX0
1000
11X1
1011
274 0 ▶ open PODFILE, "<$file" or die "_path2modname: Can't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open PODFILE, "<$file" or die "_path2modname: Can't open ${file}: $!" 0 0 0
275 0 my $in_pod = 0;
276 0 my $in_name = 0;
277 0 my $line;
278 0 ▶ while ($line = <PODFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline PODFILE)) 0 0 0
279 0 chomp $line;
280 0 ▶ $in_pod = 1 if ($line =~ m/^=\w/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^=\w/ 0 0 0
281 0 ▶ $in_pod = 0 if ($line =~ m/^=cut/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^=cut/ 0 0 0
282 0 ▶ next unless $in_pod; # skip non-pod text
Branch: 1 branch
BranchTrueFalseTotal
unless $in_pod 0 0 0
283 0 ▶ next if ($line =~ m/^\s*\z/); # and blank lines
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*\z/ 0 0 0
284 0 ▶ next if ($in_pod && ($line =~ m/^X</)); # and commands
Branch: 1 branch
BranchTrueFalseTotal
if $in_pod and $line =~ /^X</ 0 0 0
Condition0%0/3
$in_pod and $line =~ /^X</
!ll&&!rl&&r
000
MC/DC0%0/2
$in_pod and $line =~ /^X</
$in_pod $line =~ /^X</
Truth table0%0/3
A and B
A= $in_podB= $line =~ /^X</
ABresult
0X0
100
111
285 0 ▶ if ($in_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_name) 0 0 0
286 0 ▶ if ($line =~ m/(\w+::)?(\w+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /(\w+::)?(\w+)/) 0 0 0
287 # substitute case-preserved version of name
288 0 my $podname = $2;
289 0 ▶ my $prefix = $1 || '';
Condition0%0/2
$1 || ''
l!l
00
MC/DC0%0/1
$1 || ''
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
290 0 ▶ $verbose and print "Attempting case restore of '$name' from '$prefix$podname'\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Attempting case restore of '${name}' from '$prefix${podname}'\n" 0 0 0
291 0 ▶ unless ($name =~ s/$prefix$podname/$prefix$podname/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name =~ s/$prefix$podname/$prefix$podname/i) 0 0 0
292 0 ▶ $verbose and print "Attempting case restore of '$name' from '$podname'\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Attempting case restore of '${name}' from '${podname}'\n" 0 0 0
293 0 $name =~ s/$podname/$podname/i;
294 }
295 0 last;
296 }
297 }
298 0 ▶ $in_name = 1 if ($line =~ m/^=head1 NAME/);
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^=head1 NAME/ 0 0 0
299 }
300 0 close PODFILE;
301 }
302  
303 167 return $name;
304 }
305  
306 #==========================================================================
307  
308 29 ▶sub _recurse_dir {
Subroutine _recurse_dir: called CC=3 SCAR=11.8
309 29 my($self, $startdir, $callback, $modname_bits) = @_;
310  
311 29 ▶ my $maxdepth = $self->{'fs_recursion_maxdepth'} || 10;
Condition50%1/2
$self->{'fs_recursion_maxdepth'} || 10
l!l
029
MC/DC0%0/1
$self->{'fs_recursion_maxdepth'} || 10
$self->{'fs_recursion_maxdepth'}
Truth table50%1/2
A
A= $self->{'fs_recursion_maxdepth'}
Aresult
11
00
312 29 my $verbose = $self->verbose;
313  
314 29 my $here_string = File::Spec->curdir;
315 29 my $up_string = File::Spec->updir;
316 29 ▶ $modname_bits ||= [];
Condition100%2/2
$modname_bits ||= []
l!l
326
MC/DC100%1/1
$modname_bits ||= []
$modname_bits
Truth table100%2/2
A
A= $modname_bits
Aresult
11
00
317  
318 29 my $recursor;
319 94 ▶ $recursor = sub {
Subroutine __ANON__: called CC=23 SCAR=38.2
320 94 my($dir_long, $dir_bare) = @_;
321 94 ▶ if( @$modname_bits >= 10 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$modname_bits >= 10) 0 94 94
322 0 ▶ $verbose and print "Too deep! [@$modname_bits]\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Too deep! [@$modname_bits]\n" 0 0 0
323 0 return;
324 }
325  
326 94 ▶ unless(-d $dir_long) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir_long) 0 94 94
327 0 ▶ $verbose > 2 and print "But it's not a dir! $dir_long\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 2 and print "But it's not a dir! $dir_long\n" 0 0 0
328 0 return;
329 }
330 94 ▶ unless( opendir(INDIR, $dir_long) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (opendir INDIR, $dir_long) 0 94 94
331 0 ▶ $verbose > 2 and print "Can't opendir $dir_long : $!\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 2 and print "Can't opendir $dir_long : $!\n" 0 0 0
332 0 closedir(INDIR);
333 return
334 0 }
335  
336 # Load all items; put no extension before .pod before .pm before .plx?.
337 460 my @items = map { $_->[0] }
338 648 ▶ sort { $a->[1] cmp $b->[1] || $b->[2] cmp $a->[2] }
Condition66%2/3
$Pod::Simple::Search::a->[1] cmp $Pod::Simple::Search::b->[1] || $Pod::Simple::Search::b->[2] cmp $Pod::Simple::Search::a->[2]
l!l&&r!l&&!r
637110
MC/DC0%0/2
$Pod::Simple::Search::a->[1] cmp $Pod::Simple::Search::b->[1] || $Pod::Simple::Search::b->[2] cmp $Pod::Simple::Search::a->[2]
$Pod::Simple::Search::a->[1] cmp $Pod::Simple::Search::b->[1] $Pod::Simple::Search::b->[2] cmp $Pod::Simple::Search::a->[2]
Truth table66%2/3
A || B
A= $Pod::Simple::Search::a->[1] cmp $Pod::Simple::Search::b->[1]B= $Pod::Simple::Search::b->[2] cmp $Pod::Simple::Search::a->[2]
ABresult
1X1
011
000
339 map {
340 94 (my $t = $_) =~ s/[.]p(m|lx?|od)\z//;
341 460 ▶ [$_, $t, lc($1 || 'z') ]
Condition100%2/2
$1 || 'z'
l!l
167293
MC/DC100%1/1
$1 || 'z'
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
342 } readdir(INDIR);
343 94 closedir(INDIR);
344  
345 94 ▶ push @$modname_bits, $dir_bare unless $dir_bare eq '';
Branch: 1 branch
BranchTrueFalseTotal
unless $dir_bare eq "" 65 29 94
346  
347 94 my $i_full;
348 94 foreach my $i (@items) {
349 460 ▶ next if $i eq $here_string or $i eq $up_string or $i eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $i eq $here_string or $i eq $up_string or $i eq "" 188 272 460
Condition83%5/6
$i eq $here_string or $i eq $up_string or $i eq ""
l!l&&r!l&&!r
1880272
$i eq $here_string or $i eq $up_string
l!l&&r!l&&!r
9494272
MC/DC66%2/3
$i eq $here_string or $i eq $up_string or $i eq ""
$i eq $here_string $i eq $up_string $i eq ""
Truth table75%3/4
A or B or C
A= $i eq $here_stringB= $i eq $up_stringC= $i eq ""
ABCresult
1XX1
01X1
0011
0000
350 272 $i_full = File::Spec->catfile( $dir_long, $i );
351  
352 272 ▶ if(!-r $i_full) {
Branch: 3 branches
BranchTrueFalseTotal
if (not -r $i_full) { } 0 272 272
elsif (-f $i_full) { } 191 81 272
elsif (-d _) { } 81 0 81
353 0 ▶ $verbose and print "Skipping unreadable $i_full\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Skipping unreadable $i_full\n" 0 0 0
354  
355 } elsif(-f $i_full) {
356 191 $_ = $i;
357 191 $callback->( $i_full, $i, 0, $modname_bits );
358  
359 } elsif(-d _) {
360 81 ▶ $i =~ s/\.DIR\z//i if $^O eq 'VMS';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "VMS" 0 81 81
361 81 $_ = $i;
362 81 ▶ my $rv = $callback->( $i_full, $i, 1, $modname_bits ) || '';
Condition100%2/2
&$callback($i_full, $i, 1, $modname_bits) || ''
l!l
1665
MC/DC100%1/1
&$callback($i_full, $i, 1, $modname_bits) || ''
&$callback($i_full, $i, 1, $modname_bits)
Truth table100%2/2
A
A= &$callback($i_full, $i, 1, $modname_bits)
Aresult
11
00
363  
364 81 ▶ if($rv eq 'PRUNE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv eq 'PRUNE') { } 16 65 81
365 16 ▶ $verbose > 1 and print "OK, pruning";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 1 and print "OK, pruning" 0 16 16
366 } else {
367 # Otherwise, recurse into it
368 65 $recursor->( File::Spec->catdir($dir_long, $i) , $i);
369 }
370 } else {
371 0 ▶ $verbose > 1 and print "Skipping oddity $i_full\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 1 and print "Skipping oddity $i_full\n" 0 0 0
372 }
373 }
374 94 pop @$modname_bits;
375 94 return;
376 29 };;
377  
378 29 local $_;
379 29 $recursor->($startdir, '');
380  
381 29 undef $recursor; # allow it to be GC'd
382  
383 29 return;
384 }
385  
386  
387 #==========================================================================
388  
389 0 ▶sub run {
Subroutine run: not called CC=2 SCAR=17.9
Pod undocumented
390 # A function, useful in one-liners
391  
392 0 my $self = __PACKAGE__->new;
393 0 ▶ $self->limit_glob($ARGV[0]) if @ARGV;
Branch: 1 branch
BranchTrueFalseTotal
if @ARGV 0 0 0
394 0 ▶ $self->callback( sub {
Subroutine __ANON__: not called CC=10 SCAR=47.0
395 0 my($file, $name) = @_;
396 0 my $version = '';
397  
398 # Yes, I know we won't catch the version in like a File/Thing.pm
399 # if we see File/Thing.pod first. That's just the way the
400 # cookie crumbles. -- SMB
401  
402 0 ▶ if($file =~ m/\.pod$/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($file =~ /\.pod$/i) { } 0 0 0
elsif (not open(INPOD, $file)) { } 0 0 0
403 # Don't bother looking for $VERSION in .pod files
404 0 DEBUG and print "Not looking for \$VERSION in .pod $file\n";
405 } elsif( !open(INPOD, $file) ) {
406 0 DEBUG and print "Couldn't open $file: $!\n";
407 0 close(INPOD);
408 } else {
409 # Sane case: file is readable
410 0 my $lines = 0;
411 0 ▶ while(<INPOD>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline INPOD)) 0 0 0
412 0 ▶ last if $lines++ > $MAX_VERSION_WITHIN; # some degree of sanity
Branch: 1 branch
BranchTrueFalseTotal
if $lines++ > $Pod::Simple::Search::MAX_VERSION_WITHIN 0 0 0
413 0 ▶ if( s/^\s*\$VERSION\s*=\s*//s and m/\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\s*\$VERSION\s*=\s*//s and /\d/) 0 0 0
Condition0%0/3
s/^\s*\$VERSION\s*=\s*//s and /\d/
!ll&&!rl&&r
000
MC/DC0%0/2
s/^\s*\$VERSION\s*=\s*//s and /\d/
s/^\s*\$VERSION\s*=\s*//s /\d/
Truth table0%0/3
A and B
A= s/^\s*\$VERSION\s*=\s*//sB= /\d/
ABresult
0X0
100
111
414 0 DEBUG and print "Found version line (#$lines): $_";
415 0 s/\s*\#.*//s;
416 0 s/\;\s*$//s;
417 0 s/\s+$//s;
418 0 s/\t+/ /s; # nix tabs
419 # Optimize the most common cases:
420 0 ▶ $_ = "v$1"
Branch: 1 branch
BranchTrueFalseTotal
if /^v?["']?([0-9_]+(\.[0-9_]+)*)["']?$/s or /\$Revision:\s*([0-9_]+(?:\.[0-9_]+)*)\s*\$/s 0 0 0
Condition0%0/3
/^v?["']?([0-9_]+(\.[0-9_]+)*)["']?$/s or /\$Revision:\s*([0-9_]+(?:\.[0-9_]+)*)\s*\$/s
l!l&&r!l&&!r
000
MC/DC0%0/2
/^v?["']?([0-9_]+(\.[0-9_]+)*)["']?$/s or /\$Revision:\s*([0-9_]+(?:\.[0-9_]+)*)\s*\$/s
/^v?["']?([0-9_]+(\.[0-9_]+)*)["']?$/s /\$Revision:\s*([0-9_]+(?:\.[0-9_]+)*)\s*\$/s
Truth table0%0/3
A or B
A= /^v?["']?([0-9_]+(\.[0-9_]+)*)["']?$/sB= /\$Revision:\s*([0-9_]+(?:\.[0-9_]+)*)\s*\$/s
ABresult
1X1
011
000
421 if m{^v?["']?([0-9_]+(\.[0-9_]+)*)["']?$}s
422 # like in $VERSION = "3.14159";
423 or m{\$Revision:\s*([0-9_]+(?:\.[0-9_]+)*)\s*\$}s
424 # like in sprintf("%d.%02d", q$Revision: 4.13 $ =~ /(\d+)\.(\d+)/);
425 ;
426  
427 # Like in sprintf("%d.%s", map {s/_//g; $_} q$Name: release-0_55-public $ =~ /-(\d+)_([\d_]+)/)
428 $_ = sprintf("v%d.%s",
429 0 ▶ map {s/_//g; $_}
Branch: 1 branch
BranchTrueFalseTotal
if /\$Name:\s*([^\$]+)\$/s 0 0 0
430 $1 =~ m/-(\d+)_([\d_]+)/) # snare just the numeric part
431 if m{\$Name:\s*([^\$]+)\$}s
432 ;
433 0 $version = $_;
434 0 DEBUG and print "Noting $version as version\n";
435 0 last;
436 }
437 }
438 0 close(INPOD);
439 }
440 0 print "$name\t$version\t$file\n";
441 0 return;
442 # End of callback!
443 0 });
444  
445 0 $self->survey;
446 }
447  
448 #==========================================================================
449  
450 0 ▶sub simplify_name {
Subroutine simplify_name: not called CC=2 SCAR=17.9
Pod documented
451 0 my($self, $str) = @_;
452  
453 # Remove all path components
454 # XXX Why not just use basename()? -- SMB
455  
456 0 ▶ if ($^O eq 'MacOS') { $str =~ s{^.*:+}{}s }
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MacOS') { } 0 0 0
457 0 else { $str =~ s{^.*/+}{}s }
458  
459 0 $self->_simplify_base($str);
460 0 return $str;
461 }
462  
463 #==========================================================================
464  
465 167 ▶sub _simplify_base { # Internal method only
Subroutine _simplify_base: called CC=3 SCAR=11.4
466  
467 # strip Perl's own extensions
468 167 $_[1] =~ s/\.(pod|pm|plx?)\z//i;
469  
470 # strip meaningless extensions on Win32 and OS/2
471 167 ▶ $_[1] =~ s/\.(bat|exe|cmd)\z//i if $^O =~ /mswin|os2/i;
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /mswin|os2/i 0 167 167
472  
473 # strip meaningless extensions on VMS
474 167 ▶ $_[1] =~ s/\.(com)\z//i if $^O eq 'VMS';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "VMS" 0 167 167
475  
476 167 return;
477 }
478  
479 #==========================================================================
480  
481 15 ▶sub _expand_inc {
Subroutine _expand_inc: called CC=3 SCAR=20.6
482 15 my($self, $search_dirs) = @_;
483  
484 15 ▶ return unless $self->{'inc'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"inc"} 15 0 15
485 0 my %seen = map { File::Spec->rel2abs($_) => 1 } @{ $search_dirs };
486  
487 0 ▶ if ($^O eq 'MacOS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MacOS') { } 0 0 0
488 push @$search_dirs,
489 0 grep { !$seen{ File::Spec->rel2abs($_) }++ } $self->_mac_whammy(@INC);
490 # Any other OSs need custom handling here?
491 } else {
492 push @$search_dirs,
493 0 grep { !$seen{ File::Spec->rel2abs($_) }++ } @INC;
494 }
495  
496 0 $self->{'laborious'} = 0; # Since inc said to use INC
497 0 return;
498 }
499  
500 #==========================================================================
501  
502 0 ▶sub _mac_whammy { # Tolerate '.', './some_dir' and '(../)+some_dir' on Mac OS
Subroutine _mac_whammy: not called CC=4 SCAR=30.0
503 0 my @them;
504 0 (undef,@them) = @_;
505 0 for $_ (@them) {
506 0 ▶ if ( $_ eq '.' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq '.') { } 0 0 0
elsif ($_ =~ s[^((?:\.\./)+)][':' x (length($1) / 3);]e) { } 0 0 0
507 0 $_ = ':';
508 0 } elsif ( $_ =~ s|^((?:\.\./)+)|':' x (length($1)/3)|e ) {
509 0 $_ = ':'. $_;
510 } else {
511 0 $_ =~ s|^\./|:|;
512 }
513 }
514 0 return @them;
515 }
516  
517 #==========================================================================
518  
519 5 ▶sub _limit_glob_to_limit_re {
Subroutine _limit_glob_to_limit_re: called CC=6 SCAR=18.3
520 5 my $self = $_[0];
521 5 ▶ my $limit_glob = $self->{'limit_glob'} || return;
Condition50%1/2
$self->{'limit_glob'} || (return)
l!l
50
MC/DC0%0/1
$self->{'limit_glob'} || (return)
$self->{'limit_glob'}
Truth table50%1/2
A
A= $self->{'limit_glob'}
Aresult
11
00
522  
523 5 my $limit_re = '^' . quotemeta($limit_glob) . '$';
524 5 $limit_re =~ s/\\\?/./g; # glob "?" => "."
525 5 $limit_re =~ s/\\\*/.*?/g; # glob "*" => ".*?"
526 5 $limit_re =~ s/\.\*\?\$$//s; # final glob "*" => ".*?$" => ""
527  
528 5 ▶ $self->{'verbose'} and print "Turning limit_glob $limit_glob into re $limit_re\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"verbose"} and print "Turning limit_glob $limit_glob into re $limit_re\n" 0 5 5
529  
530 # A common optimization:
531 5 ▶ if(!exists($self->{'dir_prefix'})
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{"dir_prefix"} and $limit_glob =~ /^(?:\w+\:\:)+/s) 1 4 5
Condition66%2/3
not exists $self->{"dir_prefix"} and $limit_glob =~ /^(?:\w+\:\:)+/s
!ll&&!rl&&r
041
MC/DC50%1/2
not exists $self->{"dir_prefix"} and $limit_glob =~ /^(?:\w+\:\:)+/s
not exists $self->{"dir_prefix"} $limit_glob =~ /^(?:\w+\:\:)+/s
Truth table66%2/3
not(A) and B
A= not exists $self->{"dir_prefix"}B= $limit_glob =~ /^(?:\w+\:\:)+/s
ABresult
0X0
100
111
532 and $limit_glob =~ m/^(?:\w+\:\:)+/s # like "File::*" or "File::Thing*"
533 # Optimize for sane and common cases (but not things like "*::File")
534 ) {
535 1 $self->{'dir_prefix'} = join "::", $limit_glob =~ m/^(?:\w+::)+/sg;
536 1 ▶ $self->{'verbose'} and print " and setting dir_prefix to $self->{'dir_prefix'}\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"verbose"} and print qq[ and setting dir_prefix to $self->{"dir_prefix"}\n] 0 1 1
537 }
538  
539 5 return $limit_re;
540 }
541  
542 #==========================================================================
543  
544 # contribution mostly from Tim Jenness <t.jenness@jach.hawaii.edu>
545  
546 4 ▶sub _actual_filenames {
Subroutine _actual_filenames: called CC=2 SCAR=7.0
547 4 my $dir = shift;
548 4 my $fn = lc shift;
549 4 ▶ opendir my ($dh), $dir or return;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or return 4 0 4
550 2 return map { File::Spec->catdir($dir, $_) }
551 4 grep { lc $_ eq $fn } readdir $dh;
552 }
553  
554 1 ▶sub find {
Subroutine find: called CC=31 SCAR=50.6
Pod documented
555 1 my($self, $pod, @search_dirs) = @_;
556 1 ▶ $self = $self->new unless ref $self; # tolerate being a class method
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 1 1
557  
558 # Check usage
559 1 ▶ Carp::carp 'Usage: \$self->find($podname, ...)'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pod and length $pod 0 1 1
Condition33%1/3
defined $pod and length $pod
!ll&&!rl&&r
001
MC/DC0%0/2
defined $pod and length $pod
defined $pod length $pod
Truth table33%1/3
A and B
A= defined $podB= length $pod
ABresult
0X0
100
111
560 unless defined $pod and length $pod;
561  
562 1 my $verbose = $self->verbose;
563  
564 # Split on :: and then join the name together using File::Spec
565 1 my @parts = split /::/, $pod;
566 1 ▶ $verbose and print "Chomping {$pod} => {@parts}\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Chomping {$pod} => {@parts}\n" 0 1 1
567  
568 #@search_dirs = File::Spec->curdir unless @search_dirs;
569  
570 1 $self->_expand_inc(\@search_dirs);
571 # Add location of binaries such as pod2text:
572 1 ▶ push @search_dirs, $Config::Config{'scriptdir'} if $self->inc;
Branch: 1 branch
BranchTrueFalseTotal
if $self->inc 0 1 1
573  
574 1 my %seen_dir;
575 1 ▶ while (my $dir = shift @search_dirs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dir = shift @search_dirs) 3 0 3
576 3 ▶ next unless defined $dir and length $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dir and length $dir 0 3 3
Condition33%1/3
defined $dir and length $dir
!ll&&!rl&&r
003
MC/DC0%0/2
defined $dir and length $dir
defined $dir length $dir
Truth table33%1/3
A and B
A= defined $dirB= length $dir
ABresult
0X0
100
111
577 3 ▶ next if $seen_dir{$dir};
Branch: 1 branch
BranchTrueFalseTotal
if $seen_dir{$dir} 0 3 3
578 3 $seen_dir{$dir} = 1;
579 3 ▶ unless(-d $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 0 3 3
580 0 ▶ print "Directory $dir does not exist\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
581 }
582  
583 3 ▶ print "Looking in directory $dir\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 3 3
584 3 my $fullname = File::Spec->catfile( $dir, @parts );
585 3 ▶ print "Filename is now $fullname\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 3 3
586  
587 3 foreach my $ext ('', '.pod', '.pm', '.pl') { # possible extensions
588 10 my $fullext = $fullname . $ext;
589 10 ▶ if ( -f $fullext and $self->contains_pod($fullext) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $fullext and $self->contains_pod($fullext)) 1 9 10
Condition66%2/3
-f $fullext and $self->contains_pod($fullext)
!ll&&!rl&&r
901
MC/DC50%1/2
-f $fullext and $self->contains_pod($fullext)
-f $fullext $self->contains_pod($fullext)
Truth table66%2/3
A and B
A= -f $fullextB= $self->contains_pod($fullext)
ABresult
0X0
100
111
590 1 ▶ print "FOUND: $fullext\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 1 1
591 1 ▶ if (@parts > 1 && lc $parts[0] eq 'pod' && $self->is_case_insensitive() && $ext eq '.pod') {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts > 1 and lc $parts[0] eq "pod" and $self->is_case_insensitive and $ext eq ".pod") 0 1 1
Condition33%3/9
@parts > 1 and lc $parts[0] eq "pod" and $self->is_case_insensitive and $ext eq ".pod"
!ll&&!rl&&r
100
@parts > 1 and lc $parts[0] eq "pod" and $self->is_case_insensitive
!ll&&!rl&&r
100
@parts > 1 and lc $parts[0] eq "pod"
!ll&&!rl&&r
100
MC/DC0%0/4
@parts > 1 and lc $parts[0] eq "pod" and $self->is_case_insensitive and $ext eq ".pod"
@parts > 1 lc $parts[0] eq "pod" $self->is_case_insensitive $ext eq ".pod"
Truth table20%1/5
A and B and C and D
A= @parts > 1B= lc $parts[0] eq "pod"C= $self->is_case_insensitiveD= $ext eq ".pod"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
592 # Well, this file could be for a program (perldoc) but we actually
593 # want a module (Pod::Perldoc). So see if there is a .pm with the
594 # proper casing.
595 0 my $subdir = dirname $fullext;
596 0 ▶ unless (grep { $fullext eq $_ } _actual_filenames $subdir, "$parts[-1].pod") {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$fullext eq $_;} _actual_filenames($subdir, "$parts[-1].pod")) 0 0 0
597 0 ▶ print "# Looking for alternate spelling in $subdir\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
598 # Try the .pm file.
599 0 my $pm = $fullname . '.pm';
600 0 ▶ if ( -f $pm and $self->contains_pod($pm) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $pm and $self->contains_pod($pm)) 0 0 0
Condition0%0/3
-f $pm and $self->contains_pod($pm)
!ll&&!rl&&r
000
MC/DC0%0/2
-f $pm and $self->contains_pod($pm)
-f $pm $self->contains_pod($pm)
Truth table0%0/3
A and B
A= -f $pmB= $self->contains_pod($pm)
ABresult
0X0
100
111
601 # Prefer the .pm if its case matches.
602 0 ▶ if (grep { $pm eq $_ } _actual_filenames $subdir, "$parts[-1].pm") {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$pm eq $_;} _actual_filenames($subdir, "$parts[-1].pm")) 0 0 0
603 0 ▶ print "FOUND: $fullext\n" if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
604 0 return $pm;
605 }
606 }
607 }
608 }
609 1 return $fullext;
610 }
611 }
612  
613 # Case-insensitively Look for ./pod directories and slip them in.
614 2 for my $subdir ( _actual_filenames($dir, 'pods'), _actual_filenames($dir, 'pod') ) {
615 2 ▶ if (-d $subdir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $subdir) 2 0 2
616 2 ▶ $verbose and print "Noticing $subdir and looking there...\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print "Noticing $subdir and looking there...\n" 0 2 2
617 2 unshift @search_dirs, $subdir;
618 }
619 }
620 }
621  
622 0 return undef;
623 }
624  
625 #==========================================================================
626  
627 102 ▶sub contains_pod {
Subroutine contains_pod: called CC=10 SCAR=24.6
Pod documented
628 102 my($self, $file) = @_;
629 102 my $verbose = $self->{'verbose'};
630  
631 # check for one line of POD
632 102 ▶ $verbose > 1 and print " Scanning $file for pod...\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 1 and print " Scanning $file for pod...\n" 0 102 102
633 102 ▶ unless( open(MAYBEPOD,"<$file") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open MAYBEPOD, "<$file") 0 102 102
634 0 print "Error: $file is unreadable: $!\n";
635 0 return undef;
636 }
637  
638 102 ▶ sleep($SLEEPY - 1) if $SLEEPY;
Branch: 1 branch
BranchTrueFalseTotal
if $Pod::Simple::Search::SLEEPY 0 102 102
639 # avoid totally hogging the processor on OSs with poor process control
640  
641 102 local $_;
642 102 ▶ while( <MAYBEPOD> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline MAYBEPOD)) 214 6 220
643 214 ▶ if(m/^=(head\d|pod|over|item)\b/s) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^=(head\d|pod|over|item)\b/s) 96 118 214
644 96 ▶ close(MAYBEPOD) || die "Bizarre error closing $file: $!\nAborting";
Branch: 1 branch
BranchTrueFalseTotal
close MAYBEPOD or die "Bizarre error closing ${file}: $!\nAborting" 96 0 96
645 96 chomp;
646 96 ▶ $verbose > 1 and print " Found some pod ($_) in $file\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 1 and print " Found some pod ($_) in $file\n" 0 96 96
647 96 return 1;
648 }
649 }
650 6 ▶ close(MAYBEPOD) || die "Bizarre error closing $file: $!\nAborting";
Branch: 1 branch
BranchTrueFalseTotal
close MAYBEPOD or die "Bizarre error closing ${file}: $!\nAborting" 6 0 6
651 6 ▶ $verbose > 1 and print " No POD in $file, skipping.\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose > 1 and print " No POD in $file, skipping.\n" 0 6 6
652 6 return 0;
653 }
654  
655 #==========================================================================
656  
657 13 ▶sub _accessorize { # A simple-minded method-maker
Subroutine _accessorize: called CC=2 SCAR=7.0
658 13 shift;
659 13 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
660 13 foreach my $attrname (@_) {
661 182 ▶ *{caller() . '::' . $attrname} = sub {
Subroutine __ANON__: called CC=5 SCAR=16.6
662 13 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
663 710 ▶ $Carp::CarpLevel = 1, Carp::croak(
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 || @_ == 2 and ref $_[0] 0 710 710
Condition50%3/6
@_ == 1 || @_ == 2 and ref $_[0]
!ll&&!rl&&r
00710
@_ == 1 or @_ == 2
l!l&&r!l&&!r
5721380
MC/DC0%0/3
@_ == 1 || @_ == 2 and ref $_[0]
@_ == 1 @_ == 2 ref $_[0]
Truth table40%2/5
A or B and C
A= @_ == 1B= @_ == 2C= ref $_[0]
ABCresult
00X0
1X00
0100
1X11
0111
664 "Accessor usage: \$obj->$attrname() or \$obj->$attrname(\$new_value)"
665 ) unless (@_ == 1 or @_ == 2) and ref $_[0];
666  
667 # Read access:
668 710 ▶ return $_[0]->{$attrname} if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 572 138 710
669  
670 # Write access:
671 138 $_[0]->{$attrname} = $_[1];
672 138 return $_[0]; # RETURNS MYSELF!
673 182 };
674 }
675 # Ya know, they say accessories make the ensemble!
676 13 return;
677 }
678  
679 #==========================================================================
680 11 ▶sub _state_as_string {
Subroutine _state_as_string: called CC=3 SCAR=11.0
681 11 my $self = $_[0];
682 11 ▶ return '' unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 11 11
683 11 my @out = "{\n # State of $self ...\n";
684 11 foreach my $k (sort keys %$self) {
685 51 push @out, " ", _esc($k), " => ", _esc($self->{$k}), ",\n";
686 }
687 11 push @out, "}\n";
688 11 my $x = join '', @out;
689 11 $x =~ s/^/#/mg;
690 11 return $x;
691 }
692  
693 102 ▶sub _esc {
Subroutine _esc: called CC=2 SCAR=6.9
694 102 my $in = $_[0];
695 102 ▶ return 'undef' unless defined $in;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in 11 91 102
696 91 $in =~
697 s<([^\x20\x21\x23\x27-\x3F\x41-\x5B\x5D-\x7E])>
698 2 <'\\x'.(unpack("H2",$1))>eg;
699 91 return qq{"$in"};
700 }
701  
702 #==========================================================================
703  
704 13 ▶run() unless caller; # run if "perl whatever/Search.pm"
Branch: 1 branch
BranchTrueFalseTotal
unless caller 0 13 13
705  
706 13 1;
707  
708 #==========================================================================
709  
710 __END__
« Simple/RTF.pm ↑ Summary Simple/Debug.pm »