MyCPAN::Indexer - Index a Perl distribution
use MyCPAN::Indexer;
A stand in for run_components later on.
Takes a list of distributions and indexes them.
Given a distribution, unpack it, look at it, and report the findings. It does everything except the looking right now, so it merely croaks. Most of this needs to move out of run and into this method.
Return a list of 3-element anonymous arrays that tell examine_dists what to do. The elements of each anonymous array are:
examine_dists
1) the method to call (must be in indexing class or its parent classes) 2) a text description of the method 3) if a failure in that step should stop the exam: true or false
Clear anything recorded about the run.
Given a distribution path, record various data about it, such as its size, mtime, and so on.
Sets these items in dist_info: dist_file dist_size dist_basename dist_basename dist_author
Set something to record about the run. This should only be information specific to the run. See set_dist_info to record dist info.
set_dist_info
Fetch some run info.
Clear anything recorded about the distribution.
Some indexers might want to stop if the dist size is 0 (or some other value). In particular, you can't unpack zero byte dists, so if you are expecting to look at the dist files, a 0 sized dist is a problem.
Set something to record about the distribution. This should only be information specific to the distribution. See set_run_info to record run info.
set_run_info
Fetch some distribution info.
Given a distribution path, this determines the archive type, unpacks it into a temporary directory, and records what it did.
Sets these items in dist_info:
dist_archive_type dist_extract_path
Sets these items in run_info, when appropriate:
unpack_dist_archive_zip_error extraction_error
This method returns false if any of these steps fail:
The distribution file is not there
The distribution file does not uncompress
The archive does not unpack
The archive unpacks, but there are no files in the extraction directory
Get a directory where you can unpack the archive.
unpack_dir
Looks at dist_info's unpack_dir and guesses where the module distribution is. This accounts for odd archiving people may have used, like putting all the good stuff in a subdirectory.
Sets these items in dist_info: dist_dir
Returns as an array reference the list of files in MANIFEST.
Sets these items in dist_info: manifest
unless( -e 'MANIFEST' or -e 'MANIFEST.SKIP' ) { $logger->error( "No Makefile.PL or Build.PL" ); $_[0]->set_dist_info( 'manifest', [] ); return; }
Collect various meta-information about a file and store it in a hash. Returns the hash reference.
Returns as an array reference the list of files in blib. You need to call something like run_build_file first.
run_build_file
Sets these items in dist_info: blib
Look in the lib/ directory for .pm files.
Look for .pm files in the current workign directory (and not in sub-directories). This is more common in older Perl modules.
This is instantly deprecated. It's glue until I can figure out a better solution.
As an almost-last-ditch effort, decide to beleive META.yml if it has a provides entry. There's no reason to trust that the module author has told the truth since he is only interested in advertising the parts he wants you to use.
This is a last ditch effort to find modules by looking everywhere, starting in the current working directory.
Parses the META.yml and returns the YAML object.
Sets these items in dist_info: META.yml
Returns a list of 2-element anonymous arrays that lists method names and string descriptions of the way that the find_modules should look for module files.
find_modules
If you don't like the techniques, such as run_build_file, you can overload this and return a different set of techniques.
Find the module files. First, look in blib/. If there are no files in blib/, look in lib/. If there are still none, look in the current working directory.
blib/
lib/
Find the test files. Look for test.pl or .t files under t/.
test.pl
.t
t/
This method is one stop shopping for calls to choose_build_file, setup_build, run_build.
choose_build_file
setup_build
run_build
Guess what the build file for the distribution is, using Distribution::Guess::BuildSystem.
Distribution::Guess::BuildSystem
build_file - the build file to use build_system_guess - the Distribution::Guess::BuildSystem object
Runs the build setup file (Build.PL, Makefile.PL) to prepare for the build. You need to run choose_build_file first.
build_file_output
Run the build file (Build.PL, Makefile). Run setup_build first.
build_output
# Why is this here and how is it different from what I just did?
my( $runner ) = grep { -e } qw( ./Build Makefile ); $logger->debug( "runner is [$runner]" ); $_[0]->run_something( $runner, 'build_modules_output' ) if $runner;
Run the build file (Build.PL, Makefile) to create the META.yml file. Run setup_build first.
Sets these items in dist_info: build_meta_output make_meta_file_output
Run the shell command and record the output in the dist_info for KEY. This merges the outputs into stdout and closes stdin by redirecting /dev/null into COMMAND.
Returns a list of anonymous arrays that tell get_module_info what to do. Each anonymous array holds:
get_module_info
0. method to call 1. description of technique
The default list includes extract_module_namespaces, extract_module_version, and extract_module_dependencies. If you don't like that list, you can prune or expand it in a subclass.
extract_module_namespaces
extract_module_version
extract_module_dependencies
Collect meta informantion and package information about a module file. It starts by calling get_file_info, then adds more to the hash, including the version and package information.
get_file_info
Collect meta informantion and package information about a test file. It starts by calling get_file_info, then adds more to the hash, including the version and package information.
Counts the lines in a file and categorizes them as code, comment, documentation, or blank.
This returns a hash:
{ total => ..., code => ..., comment => ..., documentation => ..., blank => ..., }
Guesses and returns the MIME type for the file, using File::MMagic if it's available. If that module is not available, it returns nothing.
These functions aren't related to examining a distribution directly.
Removes the unpack_dir. You probably don't need this if File::Temp cleans up its own files.
File::Temp
Write a nice report. This isn't anything useful yet. From your program, take the object and dump it in some way.
This method is mostly for the $logger->trace method in Log4perl. It figures out which information to report in the log message, acconting for all the levels or magic in between.
Get the parent process ID. This is a method because I have to do special things for Windows. For Windows, just return -1 for now.
This code is in Github:
git://github.com/briandfoy/mycpan-indexer.git
brian d foy, <bdfoy@cpan.org>
<bdfoy@cpan.org>
Copyright © 2008-2018, brian d foy <bdfoy@cpan.org>. All rights reserved.
You may redistribute this under the terms of the Artistic License 2.0.
To install MyCPAN::Indexer, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MyCPAN::Indexer
CPAN shell
perl -MCPAN -e shell install MyCPAN::Indexer
For more information on module installation, please visit the detailed CPAN module installation guide.