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   28 use strict;
  2         6  
  2         65  
4 2     2   11 use warnings;
  2         10  
  2         121  
5            
6             our $VERSION = '1.001';
7             my $version = $VERSION;
8             $VERSION = eval $VERSION;
9            
10 2     2   12 use App::Pods2Site::Util qw(createSpinner);
  2         4  
  2         102  
11            
12 2     2   13 use Pod::Simple::Search;
  2         3  
  2         65  
13 2     2   15 use Grep::Query qw(qgrep);
  2         4  
  2         1261  
14            
15             # CTOR
16             #
17             sub new
18             {
19 3     3 0 17 my $class = shift;
20 3         8 my $args = shift;
21            
22 3         11 my $self = bless( {}, $class);
23 3         16 $self->__scan($args);
24            
25 3         42 return $self;
26             }
27            
28             sub getCounts
29             {
30 3     3 0 14 my $self = shift;
31            
32 3         14 my $sum = 0;
33 3         16 my %partCounts;
34 3         16 foreach my $group (@{$self->{groups}})
  3         28  
35             {
36 6         22 my $name = $group->{name};
37 6         12 my $count = scalar(@{$group->{pods}});
  6         12  
38 6         45 $partCounts{$name} = $count;
39 6         18 $sum += $count;
40             }
41            
42 3         24 return ($sum, \%partCounts);
43             }
44            
45             sub getGroups
46             {
47 3     3 0 8 my $self = shift;
48            
49 3         10 return $self->{groups};
50             }
51            
52             sub __scan
53             {
54 3     3   6 my $self = shift;
55 3         6 my $args = shift;
56            
57             # set up some progress feedback
58             #
59 3         15 my $spinner = createSpinner($args);
60             my $cb = sub
61             {
62 15     15   33191 my $p = shift;
63 15         43 my $n = shift;
64            
65 15 50       141 if ($args->isVerboseLevel(3))
66             {
67 0         0 print "Scanning '$n' => '$p'...\n";
68             }
69             else
70             {
71 15         52 $spinner->();
72             }
73 3         39 };
74            
75             # the search can be verbose, but we typically don't want it
76             #
77 3         12 my $verbosity = 0;
78 3 50       23 $verbosity++ if $args->isVerboseLevel(4);
79 3 50       12 $verbosity++ if $args->isVerboseLevel(5);
80            
81             # array to use for queries later, holds hash records
82             #
83 3         7 my @podRecords;
84            
85             # get all script pods - be 'laborious' since they typically don't fit '.pm' or '.pod' naming
86             #
87 3         32 my $binSearch = Pod::Simple::Search->new()->inc(0)->laborious(1)->callback($cb)->verbose($verbosity);
88 3         229 $binSearch->survey($args->getBinDirs());
89 3         288 my $bin_n2p = $binSearch->name2path;
90 3         49 foreach my $name (keys(%$bin_n2p))
91             {
92 6         96 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         39 my $libSearch = Pod::Simple::Search->new()->inc(0)->callback($cb)->verbose($verbosity);
99 3         316 $libSearch->survey($args->getLibDirs());
100 3         247 my $lib_n2p = $libSearch->name2path();
101 3         70 foreach my $name (keys(%$lib_n2p))
102             {
103 9 50       56 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         106 push(@podRecords, { type => 'lib', name => $name, path => $lib_n2p->{$name} });
113             }
114             }
115            
116             # use the group queries to separate them
117             #
118 3         13 my @groups;
119 3         8 foreach my $groupDef (@{$args->getGroupDefs()})
  3         41  
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         93 my @pods = $groupDef->{query}->qgrep(undef, @podRecords);
125 6         3897 push(@groups, { name => $groupDef->{name}, pods => \@pods });
126             }
127 3         286 $self->{groups} = \@groups;
128             }
129            
130             1;