Distribution::Guess::BuildSystem - Guess what this distribution uses to build itself
use Distribution::Guess::BuildSystem; chdir $dist_dir; my $guesser = Distribution::Guess::BuildSystem->new( dist_dir => $dir ); my $build_files = $guesser->build_files; # Hash ref my $build_pl = $guesser->has_build_pl; my $makefile_pl = $guesser->has_makefile_pl; my $both = $guesser->has_build_and_makefile; my $build_command = $guesser->build_commands; # Hash ref if( $guesser->uses_module_install ) { my $version = $guesser->module_install_version; my $pita = $guesser->uses_auto_install; } if( $guesser->uses_makemaker ) { my $version = $guesser->makemaker_version; my $make = $guesser->make_command; }
There are three major build system for Perl distributions:
ExtUtils::MakeMaker
Uses Makefile.PL and make.
make
Module::Build
Uses Build.PL and perl, although it might have a Makefile.PL that is a wrapper.
perl
Module::Install
Uses Makefile.PL and calls to an embedded Module::Install. It might use auto_install to call CPAN.pm at build time.
auto_install
CPAN.pm
The trick is to figure out which one you are supposed to use. This module has several methods to look at a distribution and guess what its build system is. The main object is simply some settings. Every time you want to ask a question about the distribution, the object looks at the distribution. That is, it doesn't capture the information when you create the object.
Creates a new guesser object. You can set:
dist_dir - the distribution directory (where the build file is) perl_binary - the path to the perl you want to use prefer_module_build - some methods will return the preferred builder prefer_makemaker - some methods will return the preferred builder
If you prefer The defaults are:
dist_dir - current working directory perl_binary - $^X (may be relative and no longer in path!) prefer_module_build - true prefer_makemaker - false
Returns or sets the distribution directory.
Returns or sets the perl binary path. This is either the one that you set or the value of $^X. There's no check to verify that this is actually a perl binary.
$^X
Returns or sets the Module::Build preference. If this is true, some of the methods preferentially return answers for Module::Build over MakeMaker when a distribution can use both systems. If both prefer_makemaker and prefer_module_build are true, then MakeMaker wins.
prefer_makemaker
prefer_module_build
Returns an hash reference of build files found in the distribution. The keys are the filenames of the build files. The values
Returns the build file that you should use, even if there is more than one. Right now this is simple:
1. In the single build file distributions, return that build file
2. If you've specified a preference with prefer_module_build or prefer_makemaker, use that.
3. If there is no preference (both are false), prefer Module::Build.
4. If no of those work, return nothing.
Returns the build command that you should use. This uses the logic of preferred_build_file. It returns the result of either perl_command or make_command.
preferred_build_file
perl_command
make_command
Returns an anonymous hash to the paths to the build files, based on the dist_dir argument to new and the return value of build_files. The keys are the file names and the values are the paths.
new
build_files
Has the file name returned by build_pl.
build_pl
Has the file name returned by makefile_pl.
makefile_pl
Has both the files returned by makefile_pl and build_pl.
Looks in %Config to see what perl discovered when someone built it if you can use a make variant to build the distribution.
Returns ./Build, the script that Build.PL should have created, if the distribution has a Build.PL. Otherwise it returns nothing.
./Build
Returns the perl currently running. This is the perl that you would use to run the Makefile.PL or Build.PL.
Returns a hash reference of the commands you can use to build the distribution. The keys are the commands, such as make or perl Build.PL.
perl Build.PL
Returns true if the distro uses ExtUtils::Makemaker.
ExtUtils::Makemaker
Returns true if MakeMaker is the only build system. Knowing that can cut down on the logic quite a bit since you don't have to choose between possibilities or preferences.
Returns the version of Makemaker installed for the perl running this code.
Returns true if this distribution uses Module::Build. This means that it has a Build.PL and that the Build.PL actually uses Module::Build.
Returns true if Module::Build is the only build system. Knowing that can cut down on the logic quite a bit since you don't have to choose between possibilities or preferences.
Returns the version of Module::Build install for perl running this code.
Returns true if this distribution uses Module::Install.
Returns true if this distribution uses Module::Install and will use the auto_install feature.
This is a very simple test right now. If it finds the string auto_install in the build file, it returns true.
Returns the version of Module::Install.
Returns true if this distribution uses Module::Install::Compat and will use the create_makefile_pl feature.
Module::Install::Compat
create_makefile_pl
This is a very simple test right now. If it finds the string create_makefile_pl in the build file, it returns true.
Returns true if Build.PL is a wrapper around Makefile.PL.
Build.PL
Makefile.PL
You may want to override or extend these, so they are methods.
Returns the string used for the Makefile.PL filename. Seems stupid until you want to change it in a subclass, which you can do now that it's a method. :)
Returns the string used for the Build.PL filename. Seems stupid until you want to change it in a subclass, which you can do now that it's a method. :)
Returns the module name of Makemaker, which is ExtUtils::MakeMaker.
Return the string representing the name for Module::Build.
Return the string representing the name for Module::Install. By default this is inc::Module::Install.
inc::Module::Install
Returns the directory that contains Module::Install. This is the distribution directory because the module name is actually inc::Module::Install.
The name of the module that can get a list of used modules from a Perl file. By default this is Module::Extract::Use.
This source is in Github:
https://github.com/briandfoy/distribution-guess-buildsystem.git
brian d foy, <briandfoy@pobox.com>
<briandfoy@pobox.com>
Copyright © 2008-2024, brian d foy <briandfoy@pobox.com>. All rights reserved.
You may redistribute this under the terms of the Artistic License 2.0.
To install Distribution::Guess::BuildSystem, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Distribution::Guess::BuildSystem
CPAN shell
perl -MCPAN -e shell install Distribution::Guess::BuildSystem
For more information on module installation, please visit the detailed CPAN module installation guide.