File Coverage

blib/lib/Sman/Man/Find.pm
Criterion Covered Total %
statement 9 19 47.3
branch 0 4 0.0
condition 0 17 0.0
subroutine 3 5 60.0
pod 0 1 0.0
total 12 46 26.0


line stmt bran cond sub pod time code
1             package Sman::Man::Find;
2             #$Id: Find.pm,v 1.12 2008/06/03 15:38:48 joshr Exp $
3              
4 1     1   781 use File::Find;
  1         3  
  1         69  
5 1     1   6 use strict;
  1         2  
  1         34  
6 1     1   6 use warnings;
  1         1  
  1         251  
7              
8             # to be called like "my @files = Sman::Man::Find::FindManFiles()"
9             sub FindManFiles { # get manfiles in MANPATH
10 0     0 0   my ($manpath, $matchregex) = @_;
11 0           my @files;
12 0   0       chomp($manpath ||= $ENV{MANPATH} || `manpath` || '/usr/share/man');
      0        
13              
14             #$matchregex = 'man/man.*\.' unless defined $matchregex;
15              
16 0           my @dirs = split(/:/, $manpath);
17 0           for my $dir (@dirs) {
18 0 0 0       next unless ($dir && -e $dir && (-d $dir || -l $dir)); # skip non-existent dirs
      0        
      0        
19             File::Find::find( sub {
20 0     0     my $n = $File::Find::name;
21 0 0 0       push @files, $n
22             if -f $n && $n =~ m!man/man.*\.!
23 0           }, $dir );
24             }
25 0           return @files;
26             }
27              
28             1;
29              
30             =head1 NAME
31              
32             Sman::Man::Find - Find manpage files for indexing by sman-update
33              
34             =head1 SYNOPSIS
35              
36             my @manfiles = Sman::Man::Find::FindManFiles();
37            
38             =head1 DESCRIPTION
39              
40             Provides a single function, FindManFiles(), which looks for man-like files
41             along the passed manpath, or the env var MANPATH, or the output of manpath,
42             whichever is defined first. If none is defined, /usr/share/man is used as the
43             manpath.
44              
45             =head1 AUTHOR
46              
47             Josh Rabinowitz
48              
49             =head1 SEE ALSO
50              
51             L, L, L
52              
53             =cut