File Coverage

blib/lib/MyCPAN/App/DPAN/Indexer.pm
Criterion Covered Total %
statement 52 57 91.2
branch n/a
condition n/a
subroutine 18 20 90.0
pod 5 5 100.0
total 75 82 91.4


line stmt bran cond sub pod time code
1             package MyCPAN::App::DPAN::Indexer;
2 2     2   2434 use strict;
  2         5  
  2         90  
3 2     2   14 use warnings;
  2         4  
  2         79  
4              
5 2     2   961 use subs qw(get_caller_info);
  2         36  
  2         20  
6 2     2   90 use vars qw($VERSION $logger);
  2         7  
  2         124  
7              
8             # don't change the inheritance order
9             # this should be done with roles, but we don't quite have that yet
10             # it's a problem with who's cleanup() get called
11 2     2   12 use base qw(MyCPAN::App::BackPAN::Indexer MyCPAN::Indexer);
  2         4  
  2         2307  
12              
13 2     2   86030 use Cwd qw(cwd);
  2         5  
  2         203  
14 2     2   13 use File::Basename qw(dirname);
  2         5  
  2         248  
15 2     2   13 use File::Path qw(mkpath);
  2         4  
  2         82  
16 2     2   11 use File::Temp qw(tempdir);
  2         4  
  2         91  
17 2     2   15 use File::Spec::Functions qw(catfile rel2abs);
  2         2  
  2         123  
18              
19             $VERSION = '1.28';
20              
21             =head1 NAME
22              
23             MyCPAN::App::DPAN::Indexer - Create a D(ark)PAN out of the indexed distributions
24              
25             =head1 SYNOPSIS
26              
27             use MyCPAN::Indexer;
28              
29             =head1 DESCRIPTION
30              
31             This module implements the indexer_class and reporter_class components
32             to allow C to create a CPAN-like directory structure
33             with its associated index files. This application of MyCPAN::Indexer is
34             specifically aimed at creating a 02packages.details file, so it
35             strives to collect a minimum of information.
36              
37             It runs through the indexing and prints a report at the end of the run.
38              
39             =cut
40              
41 2     2   12 use Carp qw(croak);
  2         4  
  2         100  
42 2     2   11 use Cwd qw(cwd);
  2         3  
  2         65  
43              
44 2     2   17 use Log::Log4perl;
  2         4  
  2         62  
45              
46             BEGIN {
47 2     2   66 $logger = Log::Log4perl->get_logger( 'Indexer' );
48             }
49              
50             # Override the exit from the parent class so we can embed a run
51             # inside a bigger application. Applications should override this
52             # on their own to do any final processing they want.
53 0     0   0 sub _exit { 1 }
54              
55             __PACKAGE__->activate( @ARGV ) unless caller;
56              
57             =head2 Indexer class
58              
59             =over 4
60              
61             =item examine_dist_steps
62              
63             Returns the list of techniques that C should use
64             to index distributions. See the documentation in
65             C.
66              
67             For DPAN, unpack the dist, ensure you are in the dist directory,
68             the find the modules.
69              
70             =cut
71              
72             sub examine_dist_steps
73             {
74             (
75             # method error message fatal
76 1     1 1 2262 [ 'unpack_dist', "Could not unpack distribution!", 1 ],
77             [ 'find_dist_dir', "Did not find distro directory!", 1 ],
78             [ 'find_modules', "Could not find modules!", 1 ],
79             [ 'examine_modules', "Could not process modules!", 0 ],
80             );
81             }
82              
83             =item find_modules_techniques
84              
85             Returns the list of techniques that C should use
86             to look for Perl module files. See the documentation in
87             C.
88              
89             =cut
90              
91             sub find_module_techniques
92             {
93 1     1 1 12347 my( $self ) = @_;
94              
95             =pod
96              
97             Save this feature for another time
98              
99             my $config = $self->get_coordinator->get_config;
100            
101             if( my @techniques = $config->get( 'find_module_techniques' ) )
102             {
103             $logger->debug( "Using techniques [@techniques] to find modules" );
104            
105             @techniques = map {
106             my $can = $self->can( $_ );
107             $logger->warn( "The technique [$_] is unknown" )
108             unless $can;
109             $can ? [ $_, 'Technique $_ specified by config' ] : ();
110             } @techniques;
111            
112             return \@techniques;
113             }
114              
115             =cut
116              
117            
118             (
119 1         8 [ 'look_in_lib', "Guessed from looking in lib/" ],
120             [ 'look_in_cwd', "Guessed from looking in cwd" ],
121             [ 'look_in_meta_yml_provides', "Guessed from looking in META.yml" ],
122             [ 'look_for_pm', "Guessed from looking in cwd" ],
123             );
124             }
125              
126             =item get_module_info_tasks
127              
128             Returns the list of techniques that C should use
129             to extract data from Perl module files. See the documentation in
130             C.
131              
132             =cut
133              
134             sub get_module_info_tasks
135             {
136             (
137 1     1 1 5056 [ 'extract_module_namespaces', 'Extract the namespaces a file declares' ],
138             [ 'extract_module_version', 'Extract the version of the module' ],
139             )
140             }
141              
142             =item setup_run_info
143              
144             Like C in C, but it remembers fewer
145             things. The DarkPAN census really just cares about finding packages,
146             so the details about the run aren't as interesting.
147              
148             =cut
149              
150             sub setup_run_info
151             {
152             # TRACE( sub { get_caller_info } );
153              
154 1     1 1 12844 $_[0]->set_run_info( 'root_working_dir', cwd() );
155 1         144 $_[0]->set_run_info( 'run_start_time', time );
156 1         30 $_[0]->set_run_info( 'completed', 0 );
157 1         44 $_[0]->set_run_info( 'pid', $$ );
158 1         46 $_[0]->set_run_info( 'ppid', $_[0]->getppid );
159              
160 1         66 $_[0]->set_run_info( 'indexer', ref $_[0] );
161 1         45 $_[0]->set_run_info( 'indexer_versions', $_[0]->VERSION );
162              
163 1         1209 return 1;
164             }
165              
166              
167             =item setup_dist_info
168              
169             Like C in C, but it remembers fewer
170             things. The test census really just cares about statements in the test
171             files, so the details about the distribution aren't as interesting.
172              
173             =cut
174              
175             sub setup_dist_info
176             {
177             # TRACE( sub { get_caller_info } );
178              
179 0     0 1   my( $self, $dist ) = @_;
180              
181 0           $logger->debug( "Setting dist [$dist]\n" );
182 0           $self->set_dist_info( 'dist_file', $dist );
183              
184 0           return 1;
185             }
186              
187             =back
188              
189             =head1 SOURCE AVAILABILITY
190              
191             This code is in Github:
192              
193             git://github.com/briandfoy/mycpan-indexer.git
194             git://github.com/briandfoy/mycpan--app--dpan.git
195              
196             =head1 AUTHOR
197              
198             brian d foy, C<< >>
199              
200             =head1 COPYRIGHT AND LICENSE
201              
202             Copyright (c) 2008-2009, brian d foy, All Rights Reserved.
203              
204             You may redistribute this under the same terms as Perl itself.
205              
206             =cut