File Coverage

blib/lib/App/Pods2Site/PodFinder.pm
Criterion Covered Total %
statement 62 64 96.8
branch 4 8 50.0
condition n/a
subroutine 10 10 100.0
pod 0 3 0.0
total 76 85 89.4


line stmt bran cond sub pod time code
1             package App::Pods2Site::PodFinder;
2            
3 2     2   11 use strict;
  2         4  
  2         51  
4 2     2   10 use warnings;
  2         4  
  2         104  
5            
6             our $VERSION = '1.003';
7             my $version = $VERSION;
8             $VERSION = eval $VERSION;
9            
10 2     2   11 use App::Pods2Site::Util qw(createSpinner);
  2         3  
  2         96  
11            
12 2     2   11 use Pod::Simple::Search;
  2         2  
  2         41  
13 2     2   8 use Grep::Query qw(qgrep);
  2         4  
  2         1083  
14            
15             # CTOR
16             #
17             sub new
18             {
19 3     3 0 16 my $class = shift;
20 3         5 my $args = shift;
21            
22 3         9 my $self = bless( {}, $class);
23 3         14 $self->__scan($args);
24            
25 3         67 return $self;
26             }
27            
28             sub getCounts
29             {
30 3     3 0 8 my $self = shift;
31            
32 3         8 my $sum = 0;
33 3         13 my %partCounts;
34 3         8 foreach my $group (@{$self->{groups}})
  3         21  
35             {
36 6         17 my $name = $group->{name};
37 6         11 my $count = scalar(@{$group->{pods}});
  6         13  
38 6         34 $partCounts{$name} = $count;
39 6         19 $sum += $count;
40             }
41            
42 3         21 return ($sum, \%partCounts);
43             }
44            
45             sub getGroups
46             {
47 3     3 0 7 my $self = shift;
48            
49 3         7 return $self->{groups};
50             }
51            
52             sub __scan
53             {
54 3     3   6 my $self = shift;
55 3         7 my $args = shift;
56            
57             # set up some progress feedback
58             #
59 3         11 my $spinner = createSpinner($args);
60             my $cb = sub
61             {
62 15     15   45401 my $p = shift;
63 15         43 my $n = shift;
64            
65 15 50       149 if ($args->isVerboseLevel(3))
66             {
67 0         0 print "Scanning '$n' => '$p'...\n";
68             }
69             else
70             {
71 15         89 $spinner->();
72             }
73 3         31 };
74            
75             # the search can be verbose, but we typically don't want it
76             #
77 3         10 my $verbosity = 0;
78 3 50       10 $verbosity++ if $args->isVerboseLevel(4);
79 3 50       8 $verbosity++ if $args->isVerboseLevel(5);
80            
81             # array to use for queries later, holds hash records
82             #
83 3         5 my @podRecords;
84            
85             # get all script pods - be 'laborious' since they typically don't fit '.pm' or '.pod' naming
86             #
87 3         40 my $binSearch = Pod::Simple::Search->new()->inc(0)->laborious(1)->callback($cb)->verbose($verbosity)->is_case_insensitive(0);
88 3         245 $binSearch->survey($args->getBinDirs());
89 3         253 my $bin_n2p = $binSearch->name2path;
90 3         57 foreach my $name (keys(%$bin_n2p))
91             {
92 6         108 push(@podRecords, { type => 'bin', name => $name, path => $bin_n2p->{$name} });
93             }
94            
95             # get all other pods - specifically turn off automatic 'inc', since that's part of
96             # our own setup
97             #
98 3         35 my $libSearch = Pod::Simple::Search->new()->inc(0)->callback($cb)->verbose($verbosity)->is_case_insensitive(0);
99 3         302 $libSearch->survey($args->getLibDirs());
100 3         223 my $lib_n2p = $libSearch->name2path();
101 3         44 foreach my $name (keys(%$lib_n2p))
102             {
103 9 50       57 if ($name =~ /^(?:pods::)?(perl.+)/)
104             {
105             # if we see a perlxxx pod in namespace 'pods::', we put it in root level
106             # as links go to 'perlxxx' rather than 'pods::perlxxx'
107             #
108 0         0 push(@podRecords, { type => 'corepod', name => $1, path => $lib_n2p->{$name} });
109             }
110             else
111             {
112 9         81 push(@podRecords, { type => 'lib', name => $name, path => $lib_n2p->{$name} });
113             }
114             }
115            
116             # use the group queries to separate them
117             #
118 3         10 my @groups;
119 3         10 foreach my $groupDef (@{$args->getGroupDefs()})
  3         37  
120             {
121             # remember to pass a file accessor since queries use fields (at least they should!)
122             # but we can pass in undef to get the query to manufacture one for us as it's simple hash values
123             #
124 6         74 my @pods = $groupDef->{query}->qgrep(undef, @podRecords);
125 6         3649 push(@groups, { name => $groupDef->{name}, pods => \@pods });
126             }
127 3         276 $self->{groups} = \@groups;
128             }
129            
130             1;