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