NAME

Distribution::Guess::BuildSystem - Guess what this distribution uses to build itself

SYNOPSIS

        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;
                }

DESCRIPTION

There are three major build system for Perl distributions:

  • ExtUtils::MakeMaker

    Uses Makefile.PL and make.

  • Module::Build

    Uses Build.PL and perl, although it might have a Makefile.PL that is a wrapper.

  • Module::Install

    Uses Makefile.PL and calls to an embedded Module::Install. It might use auto_install to call CPAN.pm at build time.

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.

Methods

new

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
dist_dir( [ DIR ] )

Returns or sets the distribution directory.

perl_binary( [PERL] )

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.

prefer_makemaker( [TRUE|FALSE] )

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_module_build( [TRUE|FALSE] )

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.

Questions about the distribution

build_files

Returns an hash reference of build files found in the distribution. The keys are the filenames of the build files. The values

preferred_build_file

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.

preferred_build_command

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.

build_file_paths

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.

makefile_pl_path
build_pl_path
has_build_pl

Has the file name returned by build_pl.

has_makefile_pl

Has the file name returned by makefile_pl.

has_build_and_makefile

Has both the files returned by makefile_pl and build_pl.

make_command

Looks in %Config to see what perl discovered when someone built it if you can use a make variant to build the distribution.

build_command

Returns ./Build, the script that Build.PL should have created, if the distribution has a Build.PL. Otherwise it returns nothing.

perl_command

Returns the perl currently running. This is the perl that you would use to run the Makefile.PL or Build.PL.

build_commands

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.

uses_makemaker

Returns true if the distro uses ExtUtils::Makemaker.

uses_makemaker_only

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.

makemaker_version

Returns the version of Makemaker installed for the perl running this code.

uses_module_build

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.

uses_module_build_only

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.

module_build_version

Returns the version of Module::Build install for perl running this code.

uses_module_install

Returns true if this distribution uses Module::Install.

uses_auto_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.

module_install_version

Returns the version of Module::Install.

uses_module_build_compat

Returns true if this distribution uses Module::Install::Compat and will use the create_makefile_pl feature.

This is a very simple test right now. If it finds the string create_makefile_pl in the build file, it returns true.

build_pl_wraps_makefile_pl

Returns true if Build.PL is a wrapper around Makefile.PL.

just_give_me_a_hash

Methods for strings

You may want to override or extend these, so they are methods.

makefile_pl

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. :)

build_pl

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. :)

makemaker_name

Returns the module name of Makemaker, which is ExtUtils::MakeMaker.

module_build_name

Return the string representing the name for Module::Build.

module_install_name

Return the string representing the name for Module::Install. By default this is inc::Module::Install.

module_install_dir

Returns the directory that contains Module::Install. This is the distribution directory because the module name is actually inc::Module::Install.

module_extractor_class

The name of the module that can get a list of used modules from a Perl file. By default this is Module::Extract::Use.

TO DO

SEE ALSO

SOURCE AVAILABILITY

This source is in Github:

        https://github.com/briandfoy/distribution-guess-buildsystem.git

AUTHOR

brian d foy, <briandfoy@pobox.com>

COPYRIGHT AND LICENSE

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.