Graham Ollis ✈✈
and 1 contributors


Alien::Base::ModuleBuild::API - API Reference for Alien:: Authors


NOTE: Please consider for new development of Aliens that you use Alien::Build and alienfile instead. Like Alien::Base::ModuleBUild they work with Alien::Base. Unlike Alien::Base::Module::Build they are more easily customized and handle a number of corner cases better. For a good place to start, please see Alien::Build::Manual::AlienAuthor. Although the Alien-Base / Alien-Build team will continue to maintain this module, (we will continue to fix bugs where appropriate), we aren't adding any new features to this module.

A list of extra properties and methods provided by Alien::Base::ModuleBuild beyond those contained in Module::Build::API. Note that all property and method names are prefixed with alien_ to prevent future collisions Module::Build builtins.


Alien::Base::ModuleBuild adds several parameters to the new constructor in Module::Build. Unless otherwise specified all of the parameters listed in Module::Build::API are available and behave identically to the description contained therein.


[version 0.019]

Install module into an architecture specific directory. This is off by default, unless $ENV{ALIEN_ARCH} is true. Most Alien distributions will be installing binary code. If you are an integrator where the @INC path is shared by multiple Perls in a non-homogeneous environment you can set $ENV{ALIEN_ARCH} to 1 and Alien modules will be installed in architecture specific directories.


[version 0.005]

Add --with-pic option to autoconf style configure script when called. This is the default, and normally a good practice. Normally autoconf will ignore this and any other options that it does not recognize, but some non-autoconf configure scripts may complain.


[version 0.006]

Hash reference of modules (keys) and versions (values) that specifies Alien modules that provide binary tools that are required to build. Any Alien::Base module that includes binaries should work. Also supported are Alien::MSYS, Alien::CMake, Alien::TinyCC and Alien::Autotools.

[version 0.007]

These only become required for building if Alien::Base::ModuleBuild determines that a source code build is required.


[version 0.001]

An arrayref of commands used to build the library in the directory specified in alien_temp_dir. Each command is first passed through the command interpolation engine, so those variables may be used. The default is tailored to the GNU toolchain, i.e. AutoConf and Make; it is [ '%c --prefix=%s', 'make' ].

[version 0.009]

Each command may be either a string or an array reference. If the array reference form is used then the multiple argument form of system is used. Prior to version 0.009, only the string form was supported.


[version 0.027]

Environment overrides. Allows you to set environment variables as a hash reference that will override environment variables. You can use the same interpolated escape sequences and helpers that commands use. Set to undef to remove the variable.

   alien_env => {
     PERL => '%X',     # sets the environment variable PERL to the location
                       # of the Perl interpreter.
     PERCENT => '%%',  # evaluates to '%'
     REMOVE => undef,  # remove the environment variable if it is defined

Please keep in mind that frequently users have a good reason to have set environment variables, and you should not override them without a good reason. An example of a good justification would be if a project has a Makefile that interacts badly with common environment variables. This can sometimes be a problem since Makefile variables can be overridden with environment variables.

A useful pattern is to use a helper to only override an environment variable if it is not already set.

   alien_helper => {
     foo => '$ENV{FOO}||"my preferred value if not already set"'
   alien_env => {
     FOO => '%{foo}',

A common pitfall with environment variables is that setting one to the empty string ('') is not portable. On Unix it works fine as you would expect, but in Windows it actually unsets the environment variable, which may not be what you intend.

   alien_env => {
     # is allowed, but may not do what you intend
     # on some platforms!
     FOO => '',

[version 0.030]

Append extra values to the file when using autoconf.

When <autoconf> is detected, a file is created with values appropriate for building software that can link against the Perl that you are building with. This is important on some platforms, for example 64 bit systems where the compilers generate 32 bit code by default. You can also add values to the file using this directive.

For values that are already provided by Alien::Base::ModuleBuild, your value will be appended after the existing value. For values that aren't provided, it will simply use your value by itself.

For example if you needed to add a define to a CFLAGS, you might do something like this:

   alien_extra_site_config => {
     # CFLAGS is usually specified by A::B::MB
     CFLAGS => '-DFOO=1',
     # BAR usually is not.
     BAR => 'baz',

And the actual value for CFLAGS in the might have values like this:

 CFLAGS=-O3 -g -DFOO=1

[version 0.007]

The name of the shared library for use with FFI. Provided for situations where the shared library name cannot be determined from the pkg-config name specified with alien_name. For example libxml2 has a pkg-config of libxml-2.0, but a shared library name of xml2. By default alien_name is used with any lib prefix removed. For example libarchive to be translated into archive which is what you want for that package.


[version 0.020]

Provide helpers to generate commands or arguments at build or install time. This property is a hash reference. The keys are the helper names and the values are strings containing Perl code that will be evaluated and interpolated into the command before execution. Because helpers are only needed when building a package from the source code, any dependency may be specified as an alien_bin_requires. For example:

   alien_bin_requires => {
     'Alien::foo' => 0,
   alien_helper => {
     'foocommand'  => 'Alien::foo->some_command',
     'fooargument' => 'Alien::foo->some_argument',
   alien_build_commands => [
     '%{foocommand} %{fooargument}',

[version 0.022]

One helper that you get for free is %{pkg_config} which will be the pkg-config implementation chosen by Alien::Base::ModuleBuild. This will either be the real pkg-config provided by the operating system (preferred) or PkgConfig, the pure perl implementation found on CPAN.


[version 0.006]

Array reference containing the list of header files to be used automatically by Inline::C and Inline::CPP.


[version 0.001]

An arrayref of commands used to install it to the share directory specified by interpolation var %s. Each command is first passed through the command interpolation engine, so those variables may be used. The default is tailored to the GNU toolchain, i.e. AutoConf and Make; it is [ 'make install' ].

[version 0.009]

Each command may be either a string or an array reference. If the array reference form is used then the multiple argument form of system is used. Prior to version 0.009, only the string form was supported.


[version 0.005]

If set to true, then dynamic libraries will be moved from the lib directory to a separate dynamic directory. This makes them available for FFI modules (see FFI::Platypus, or FFI::Raw), while preferring static libraries when creating XS extensions.


[version 0.006]

On windows wrap build and install commands in an MSYS environment using Alien::MSYS. This option will automatically add Alien::MSYS as a build requirement when building on Windows.


[version 0.001]

The name of the primary library which will be provided. This should be in the form to be passed to pkg-config. This name is available in the command interpolation as %n.


[version 0.001]

These parameters, if specified, augment the information found by pkg-config. If no package config data is found, these are used to generate the necessary information. In that case, if these are not specified, they are attempted to be created from found shared-object files and header files. They both are empty by default.


[version 0.001]

A hashref or arrayref of hashrefs defining the repositories used to find and fetch library tarballs (or zipballs etc.). These attributes are used to create Alien::Base::ModuleBuild::Repository objects (or more likely, subclasses thereof). Which class is created is governed by the protocol attribute and the alien_repository_class property below. Available attributes are:


One of ftp or http or local. The first two are obvious, local allows packaging a tarball with the Alien:: module.


Defines the protocol handler class. Defaults to 'Net::FTP' or 'HTTP::Tiny' as appropriate.


This is either the root server address for the FTP and HTTP classes (i.e.


This key is protocol specific. For FTP this contains the name of the folder to search. For HTTP this is the page to be searched for links; this is specified as a path relative to the host. For a local file, this specifies the folder containing the tarball relative to the base_dir.


This is a qr regex matching acceptable files found in the location. If the pattern contains a capture group, the captured string is interpreted as the version number. N.B. if no versions are found, the files are sorted by filename using version semantics, this mechanism is not likely to be as accurate as specifying a capture group.


This key may be specified in place of pattern when the filename of the tarball is known, in which case such a file is downloaded from the given host and location. Note that, in general, specifying a pattern gives more flexibility, but there may be cases when you find more convenient to use exact_filename.


This key may be specified with the exact_filename key when the version of the tarball is known.


This attribute is a string telling the repository validator which platform the repository serves. This may be the string src (the default) for platform-independent source files, or a string which matches the Module::Build method os_type (e.g. "Windows", "Unix", "MacOS", "VMS").


If true (the default), then a C compiler is required to build from source.


[version 0.001]

As the repositories in alien_repository are converted to objects, this hash controls the type of object that is created. The keys are the relevant protocol. This allows for easy subclassing any or all protocol classes. The defaults are as follows.

 http    => 'Alien::Base::ModuleBuild::Repository::HTTP',
 ftp     => 'Alien::Base::ModuleBuild::Repository::FTP',
 local   => 'Alien::Base::ModuleBuild::Repository::Local',
 default => 'Alien::Base::ModuleBuild::Repository',

Unlike most Module::Build parameters, authors may specify only those keys which are to be overridden. If any of the above keys are not specified, the above defaults will be used.


[version 0.001]

This property is a shortcut for specifying multiple repositories with similar attributes. If a repository attribute is not defined in its alien_repository hashref, but that attribute is defined here, then this value will be used. This hashref is empty by default.


[not yet implemented]

This is intended to choose the mechanism for selecting one file from many. The default name is newest.


[version 0.001]

The name of the folder which will both serve a stub share directory via Module::Build's share_dir/dist_dir parameter. This directory is added in a smart manner which attempts not to interfere with other author-defined share_dirs. The default name is _share. This folder will hold a README file which is then installed to the target installed share location. It is THAT location that the library will be installed to.


[version 0.016]

Alien packages are installed directly into the blib directory by the `./Build' command rather than to the final location during the `./Build install` step.

[version 0.017]

As of 0.017 this is the default.


[version 0.001]

The name of the temporary folder which will house the library when it is downloaded and built. The default name is _alien.


[version 0.001]

An arrayref of commands used to test the library. Each command is first passed through the command interpolation engine, so those variables may be used. The default is to do no tests. The most common command used by the GNU toolchain is [ 'make check' ], but beware that is not supported by all packages.

[version 0.009]

Each command may be either a string or an array reference. If the array reference form is used, then the multiple argument form of system is used.


[version 0.001]

A command to run to check the version of the library installed on the system. The default is pkg-config --modversion %n.


A few global variables are used to set gross behavior. For each pair of variables, if both are set, the environment variable takes precedence.


[version 0.017]

Setting this changes the default for alien_arch above. If the module specifies its own alien_arch in its Build.PL file then it will override this setting. Typically installing into an architecture specific directory is what you want to do, since most Alien::Base based distributions provide architecture specific binary code, so you should consider carefully before installing modules with this environment variable set to 0. This may be useful for integrators creating a single non-architecture specific RPM, .dep or similar package. In this case the integrator should ensure that the Alien package be installed with a system install_type and use the system package.


Setting this to true indicates that you don't intend to actually install your Alien::Base subclass, but rather use it from the built blib directory. This behavior is mostly to support automated testing from CPANtesters and should be automagically determined. If by chance you happen to trip the behavior accidentally, setting this environment variable to false (0) before building should prevent problems.


Setting either to a true value will cause the builder to ignore a system-wide installation and build a local version of the library. This is the equivalent to setting $ENV{ALIEN_INSTALL_TYPE} to 'share'. $ENV{ALIEN_INSTALL_TYPE} takes precedence.


Setting to share will ignore a system-wide installation and build a local version of the library. Setting to system will only use a system-wide installation and die if it cannot be found.


Setting the either to a true value will output a little more info from within the module itself. At this point Alien::Base is going to be fairly verbose without this enabled.


The Alien::Base system needs to store some data to be used in other phases of the build and eventual use. This is done via the mechanism provided by Module::Build::ConfigData. During the build-phase this information is mutable and is available through the Module::Build::config_data method. As the build-phase ends the data is serialized and stored as Alien::MyModule::ConfigData (assuming you are authoring Alien::MyModule). Then during the use-phase, the Alien::MyModule::ConfigData::config method (via the Alien::MyModule::config wrapper) is used to query the information. This data is not strictly immutable, but it changing it involves file permissions and is best left alone.

Config keys of interest are:


Holder for alien_name as needed by pkg-config.


Remembers if the library was found system-wide (value: system) or was installed during build (value: share).


A hashref of Alien::Base::PkgConfig objects created from .pc files found in working_directory. One extra object (whose key is _manual is created from the alien_provides_* information.


The version number installed or available.


Holder for the full path to the extracted source of the library. This is used to munge the pkg-config data later on.


Before Alien::Base::ModuleBuild executes system commands, it replaces a few special escape sequences with useful data. This is needed especially for referencing the full path to the alien_share_dir before this path is known. The availble sequences are:


[version 0.020]

Call the given helper, either provided by the alien_helper or alien_bin_requires property. See Alien::Base#alien_helper.


Platform independent incantation for running autoconf configure script. On *nix systems this is ./configure, on Windows this is sh configure. On windows Alien::MSYS is injected as a dependency and all commands are executed in an MSYS environment.


Shortcut for the name stored in alien_name

 pkg-config --modversion %n


Platform independent "local command prefix". On *nix systems this is ./, on Windows it is an empty string.


Please note that this only works to run scripts on Unix, and does not work on Windows. It is thus, not fit for purpose and should not be used. As an alternative:

autoconf "configure"

If you are trying to invoke the autoconf configure script, use %c instead. This will use the correct incantation on either Unix like systems and on Windows.

Some other script

Invoke the interpreter directly. For example, if you have a python script use "python", if you have a Perl script use "%X", if you have an sh script use "sh". These are all portable. For sh, be sure to set the alien_msys property so that it will work on Windows.


The full path to the final installed location of the share directory (builder method alien_library_destination). This is where the library should install itself; for autoconf style installs this will look like


Captured version of the original archive.


The current Perl interpreter (aka $^X)


[version 0.027]

The current Perl interpreter using the Unix style path separator / instead of the native Windows \.


A literal %.


Original author: Joel Berger, <>

Current maintainer: Graham Ollis <> and the Alien::Base team



Copyright (C) 2012-2017 by Joel Berger

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.