I list here some of the most important methods in Module::Build
. Normally you won't need to deal with these methods unless you want to subclass Module::Build
. But since one of the reasons I created this module in the first place was so that subclassing is possible (and easy), I will certainly write more docs as the interface stabilizes.
[version 0.26]
Adds a new type of entry to the build process. Accepts a single string specifying its type-name. There must also be a method defined to process things of that type, e.g. if you add a build element called 'foo'
, then you must also define a method called process_foo_files()
.
See also "Adding new file types to the build process" in Module::Build::Cookbook.
[version 0.03]
You may call $self->add_to_cleanup(@patterns)
to tell Module::Build
that certain files should be removed when the user performs the Build clean
action. The arguments to the method are patterns suitable for passing to Perl's glob()
function, specified in either Unix format or the current machine's native format. It's usually convenient to use Unix format when you hard-code the filenames (e.g. in Build.PL) and the native format when the names are programmatically generated (e.g. in a testing script).
I decided to provide a dynamic method of the $build
object, rather than just use a static list of files named in the Build.PL, because these static lists can get difficult to manage. I usually prefer to keep the responsibility for registering temporary files close to the code that creates them.
[version 0.26]
my $args_href = $build->args;
my %args = $build->args;
my $arg_value = $build->args($key);
$build->args($key, $value);
This method is the preferred interface for retrieving the arguments passed via command line options to Build.PL or Build, minus the Module-Build specific options.
When called in in a scalar context with no arguments, this method returns a reference to the hash storing all of the arguments; in an array context, it returns the hash itself. When passed a single argument, it returns the value stored in the args hash for that option key. When called with two arguments, the second argument is assigned to the args hash under the key passed as the first argument.
[version 0.28]
Invokes the AutoSplit module on the $from
file, sending the output to the lib/auto
directory inside $to
. $to
is typically the blib/
directory.
[version 0.14]
Returns a string containing the root-level directory of this build, i.e. where the Build.PL
script and the lib
directory can be found. This is usually the same as the current working directory, because the Build
script will chdir()
into this directory as soon as it begins execution.
[version 0.21]
Returns a hash reference indicating the build_requires
prerequisites that were passed to the new()
method.
Returns a reference to the method that defines $action
, or false otherwise. This is handy for actions defined (or maybe not!) in subclasses.
[version 0.32_xx]
[version 0.2809]
Returns the internal ExtUtils::CBuilder object that can be used for compiling & linking C code. If no such object is available (e.g. if the system has no compiler installed) an exception will be thrown.
[version 0.11]
This method returns a hash reference indicating whether a version dependency on a certain module is satisfied. The $module
argument is given as a string like "Data::Dumper"
or "perl"
, and the $version
argument can take any of the forms described in "requires" above. This allows very fine-grained version checking.
The returned hash reference has the following structure:
{
ok => $whether_the_dependency_is_satisfied,
have => $version_already_installed,
need => $version_requested, # Same as incoming $version argument
message => $informative_error_message,
}
If no version of $module
is currently installed, the have
value will be the string "<none>"
. Otherwise the have
value will simply be the version of the installed module. Note that this means that if $module
is installed but doesn't define a version number, the have
value will be undef
- this is why we don't use undef
for the case when $module
isn't installed at all.
This method may be called either as an object method ($build->check_installed_status($module, $version)
) or as a class method (Module::Build->check_installed_status($module, $version)
).
[version 0.05]
Like check_installed_status(), but simply returns true or false depending on whether module $module
satisfies the dependency $version
.
If the check succeeds, the return value is the actual version of $module
installed on the system. This allows you to do the following:
my $installed = $build->check_installed_version('DBI', '1.15');
if ($installed) {
print "Congratulations, version $installed of DBI is installed.\n";
} else {
die "Sorry, you must install DBI.\n";
}
If the check fails, we return false and set $@
to an informative error message.
If $version
is any non-true value (notably zero) and any version of $module
is installed, we return true. In this case, if $module
doesn't define a version, or if its version is zero, we return the special value "0 but true", which is numerically zero, but logically true.
In general you might prefer to use check_installed_status
if you need detailed information, or this method if you just need a yes/no answer.
[version 0.28]
Compares two module versions $v1
and $v2
using the operator $op
, which should be one of Perl's numeric operators like !=
or >=
or the like. We do at least a halfway-decent job of handling versions that aren't strictly numeric, like 0.27_02
, but exotic stuff will likely cause problems.
In the future, the guts of this method might be replaced with a call out to version.pm
.
[version 0.22]
With a single argument $key
, returns the value associated with that key in the Config.pm
hash, including any changes the author or user has specified.
With $key
and $value
arguments, sets the value for future callers of config($key)
.
With no arguments, returns a hash reference containing all such key-value pairs. This usage is deprecated, though, because it's a resource hog and violates encapsulation.
[version 0.26]
With a single argument, returns the value of the configuration variable $name
. With two arguments, sets the given configuration variable to the given value. The value may be any Perl scalar that's serializable with Data::Dumper
. For instance, if you write a module that can use a MySQL or PostgreSQL back-end, you might create configuration variables called mysql_connect
and postgres_connect
, and set each to an array of connection parameters for DBI->connect()
.
Configuration values set in this way using the Module::Build object will be available for querying during the build/test process and after installation via the generated ...::ConfigData
module, as ...::ConfigData->config($name)
.
The feature() and config_data()
methods represent Module::Build's main support for configuration of installed modules. See also "SAVING CONFIGURATION INFORMATION" in Module::Build::Authoring.
[version 0.21]
Returns a hash reference indicating the conflicts
prerequisites that were passed to the new()
method.
[version 0.20]
[Deprecated] Please see Module::Build::ModuleInfo instead.
Returns true if the given file appears to contain POD documentation. Currently this checks whether the file has a line beginning with '=pod', '=head', or '=item', but the exact semantics may change in the future.
[version 0.19]
Takes the file in the from
parameter and copies it to the file in the to
parameter, or the directory in the to_dir
parameter, if the file has changed since it was last copied (or if it doesn't exist in the new location). By default the entire directory structure of from
will be copied into to_dir
; an optional flatten
parameter will copy into to_dir
without doing so.
Returns the path to the destination file, or undef
if nothing needed to be copied.
Any directories that need to be created in order to perform the copying will be automatically created.
The destination file is set to read-only. If the source file has the executable bit set, then the destination file will be made executable.
[version 0.05]
Creates an executable script called Build
in the current directory that will be used to execute further user actions. This script is roughly analogous (in function, not in form) to the Makefile created by ExtUtils::MakeMaker
. This method also creates some temporary data in a directory called _build/
. Both of these will be removed when the realclean
action is performed.
Among the files created in _build/
is a _build/prereqs file containing the set of prerequisites for this distribution, as a hash of hashes. This file may be eval()
-ed to obtain the authoritative set of prerequisites, which might be different from the contents of META.yml (because Build.PL might have set them dynamically). But fancy developers take heed: do not put any fancy custom runtime code in the _build/prereqs file, leave it as a static declaration containing only strings and numbers. Similarly, do not alter the structure of the internal $self->{properties}{requires}
(etc.) data members, because that's where this data comes from.
[version 0.28]
Returns the name of the currently-running action, such as "build" or "test". This action is not necessarily the action that was originally invoked by the user. For example, if the user invoked the "test" action, current_action() would initially return "test". However, action "test" depends on action "code", so current_action() will return "code" while that dependency is being executed. Once that action has completed, current_action() will again return "test".
If you need to know the name of the original action invoked by the user, see "invoked_action()" below.
[version 0.28]
Invokes the named action or list of actions in sequence. Using this method is preferred to calling the action explicitly because it performs some internal record-keeping, and it ensures that the same action is not invoked multiple times (note: in future versions of Module::Build it's conceivable that this run-only-once mechanism will be changed to something more intelligent).
Note that the name of this method is something of a misnomer; it should really be called something like invoke_actions_unless_already_invoked()
or something, but for better or worse (perhaps better!) we were still thinking in make
-like dependency terms when we created this method.
See also dispatch(). The main distinction between the two is that depends_on()
is meant to call an action from inside another action, whereas dispatch()
is meant to set the very top action in motion.
[version 0.28]
Returns true if the first directory logically contains the second directory. This is just a convenience function because File::Spec
doesn't really provide an easy way to figure this out (but Path::Class
does...).
[version 0.03]
Invokes the build action $action
. Optionally, a list of options and their values can be passed in. This is equivalent to invoking an action at the command line, passing in a list of options.
Custom options that have not been registered must be passed in as a hash reference in a key named "args":
$build->dispatch('foo', verbose => 1, args => { my_option => 'value' });
This method is intended to be used to programmatically invoke build actions, e.g. by applications controlling Module::Build-based builds rather than by subclasses.
See also depends_on(). The main distinction between the two is that depends_on()
is meant to call an action from inside another action, whereas dispatch()
is meant to set the very top action in motion.
[version 0.28]
Returns the name of the directory that will be created during the dist
action. The name is derived from the dist_name
and dist_version
properties.
[version 0.21]
Returns the name of the current distribution, as passed to the new()
method in a dist_name
or modified module_name
parameter.
[version 0.21]
Returns the version of the current distribution, as determined by the new()
method from a dist_version
, dist_version_from
, or module_name
parameter.
[version 0.21]
This is a fairly simple wrapper around Perl's system()
built-in command. Given a command and an array of optional arguments, this method will print the command to STDOUT
, and then execute it using Perl's system()
. It returns true or false to indicate success or failure (the opposite of how system()
works, but more intuitive).
Note that if you supply a single argument to do_system()
, it will/may be processed by the system's shell, and any special characters will do their special things. If you supply multiple arguments, no shell will get involved and the command will be executed directly.
[version 0.26]
With a single argument, returns true if the given feature is set. With two arguments, sets the given feature to the given boolean value. In this context, a "feature" is any optional functionality of an installed module. For instance, if you write a module that could optionally support a MySQL or PostgreSQL backend, you might create features called mysql_support
and postgres_support
, and set them to true/false depending on whether the user has the proper databases installed and configured.
Features set in this way using the Module::Build object will be available for querying during the build/test process and after installation via the generated ...::ConfigData
module, as ...::ConfigData->feature($name)
.
The feature()
and config_data()
methods represent Module::Build's main support for configuration of installed modules. See also "SAVING CONFIGURATION INFORMATION" in Module::Build::Authoring.
[version 0.??]
Modify any "shebang" line in the specified files to use the path to the perl executable being used for the current build. Files are modified in-place. The existing shebang line must have a command that contains "perl
"; arguments to the command do not count. In particular, this means that the use of #!/usr/bin/env perl
will not be changed.
For an explanation of shebang lines, see http://en.wikipedia.org/wiki/Shebang_%28Unix%29.
[version 0.21]
Returns true if the current system seems to have a working C compiler. We currently determine this by attempting to compile a simple C source file and reporting whether the attempt was successful.
[version 0.28]
Set or retrieve the relative paths that are appended to install_base
for any installable element. This is useful if you want to set the relative install path for custom build elements.
With no argument, it returns a reference to a hash containing all elements and their respective values. This hash should not be modified directly; use the multiple argument below form to change values.
The single argument form returns the value associated with the element $type
.
The multiple argument form allows you to set the paths for element types. $value
must be a relative path using Unix-like paths. (A series of directories separated by slashes, e.g. foo/bar
.) The return value is a localized path based on $value
.
Assigning the value undef
to an element causes it to be removed.
[version 0.28]
Returns the directory in which items of type $type
(e.g. lib
, arch
, bin
, or anything else returned by the "install_types()" method) will be installed during the install
action. Any settings for install_path
, install_base
, and prefix
are taken into account when determining the return value.
[version 0.28]
Set or retrieve paths for specific installable elements. This is useful when you want to examine any explicit install paths specified by the user on the command line, or if you want to set the install path for a specific installable element based on another attribute like install_base()
.
With no argument, it returns a reference to a hash containing all elements and their respective values. This hash should not be modified directly; use the multiple argument below form to change values.
The single argument form returns the value associated with the element $type
.
The multiple argument form allows you to set the paths for element types. The supplied $path
should be an absolute path to install elements of $type
. The return value is $path
.
Assigning the value undef
to an element causes it to be removed.
[version 0.28]
Returns a list of installable types that this build knows about. These types each correspond to the name of a directory in blib/, and the list usually includes items such as lib
, arch
, bin
, script
, libdoc
, bindoc
, and if HTML documentation is to be built, libhtml
and binhtml
. Other user-defined types may also exist.
[version 0.28]
This is the name of the original action invoked by the user. This value is set when the user invokes Build.PL, the Build script, or programmatically through the dispatch() method. It does not change as sub-actions are executed as dependencies are evaluated.
To get the name of the currently executing dependency, see "current_action()" above.
[version 0.20]
The notes()
value allows you to store your own persistent information about the build, and to share that information among different entities involved in the build. See the example in the current()
method.
The notes()
method is essentially a glorified hash access. With no arguments, notes()
returns the entire hash of notes. With one argument, notes($key)
returns the value associated with the given key. With two arguments, notes($key, $value)
sets the value associated with the given key to $value
and returns the new value.
The lifetime of the notes
data is for "a build" - that is, the notes
hash is created when perl Build.PL
is run (or when the new()
method is run, if the Module::Build Perl API is being used instead of called from a shell), and lasts until perl Build.PL
is run again or the clean
action is run.
[version 0.28]
Returns a string containing the working directory that was in effect before the Build script chdir()-ed into the base_dir
. This might be useful for writing wrapper tools that might need to chdir() back out.
[version 0.04]
If you're subclassing Module::Build and some code needs to alter its behavior based on the current platform, you may only need to know whether you're running on Windows, Unix, MacOS, VMS, etc., and not the fine-grained value of Perl's $^O
variable. The os_type()
method will return a string like Windows
, Unix
, MacOS
, VMS
, or whatever is appropriate. If you're running on an unknown platform, it will return undef
- there shouldn't be many unknown platforms though.
Convenience functions that return a boolean value indicating whether this platform behaves respectively like VMS, Windows, or Unix. For arbitrary reasons other platforms don't get their own such functions, at least not yet.
[version 0.28]
Set or retrieve the relative paths that are appended to prefix
for any installable element. This is useful if you want to set the relative install path for custom build elements.
With no argument, it returns a reference to a hash containing all elements and their respective values as defined by the current installdirs
setting.
With a single argument, it returns a reference to a hash containing all elements and their respective values as defined by $installdirs
.
The hash returned by the above calls should not be modified directly; use the three-argument below form to change values.
The two argument form returns the value associated with the element $type
.
The multiple argument form allows you to set the paths for element types. $value
must be a relative path using Unix-like paths. (A series of directories separated by slashes, e.g. foo/bar
.) The return value is a localized path based on $value
.
Assigning the value undef
to an element causes it to be removed.
[version 0.36]
This method returns a hash reference of metadata that can be used to create a YAML datastream. It is provided for authors to override or customize the fields of META.yml. E.g.
package My::Builder;
use base 'Module::Build';
sub get_metadata {
my $self, @args = @_;
my $data = $self->SUPER::get_metadata(@args);
$data->{custom_field} = 'foo';
return $data;
}
Valid arguments include:
fatal
-- indicates whether missing required metadata fields should be a fatal error or not. For META creation, it generally should, but for MYMETA creation for end-users, it should not be fatal.
auto
-- indicates whether any necessary configure_requires should be automatically added. This is used in META creation.
This method is a wrapper around the old prepare_metadata API now that we no longer use YAML::Node to hold metadata.
[version 0.36]
[Deprecated] As of 0.36, authors should use get_metadata
instead. This method is preserved for backwards compatibility only.
It takes three positional arguments: a hashref (to which metadata will be added), an optional arrayref (to which metadata keys will be added in order if the arrayref exists), and a hashref of arguments (as provided to get_metadata). The latter argument is new as of 0.36. Earlier versions are always fatal on errors.
Prior to version 0.36, this method took a YAML::Node as an argument to hold assembled metadata.
[version 0.11]
Returns a data structure containing information about any failed prerequisites (of any of the types described above), or undef
if all prerequisites are met.
The data structure returned is a hash reference. The top level keys are the type of prerequisite failed, one of "requires", "build_requires", "conflicts", or "recommends". The associated values are hash references whose keys are the names of required (or conflicting) modules. The associated values of those are hash references indicating some information about the failure. For example:
{
have => '0.42',
need => '0.59',
message => 'Version 0.42 is installed, but we need version 0.59',
}
or
{
have => '<none>',
need => '0.59',
message => 'Prerequisite Foo isn't installed',
}
This hash has the same structure as the hash returned by the check_installed_status()
method, except that in the case of "conflicts" dependencies we change the "need" key to "conflicts" and construct a proper message.
Examples:
# Check a required dependency on Foo::Bar
if ( $build->prereq_failures->{requires}{Foo::Bar} ) { ...
# Check whether there were any failures
if ( $build->prereq_failures ) { ...
# Show messages for all failures
my $failures = $build->prereq_failures;
while (my ($type, $list) = each %$failures) {
while (my ($name, $hash) = each %$list) {
print "Failure for $name: $hash->{message}\n";
}
}
[version 0.32]
Returns a reference to a hash describing all prerequisites. The keys of the hash will be the various prerequisite types ('requires', 'build_requires', 'configure_requires', 'recommends', or 'conflicts') and the values will be references to hashes of module names and version numbers. Only prerequisites types that are defined will be included. The prereq_data
action is just a thin wrapper around the prereq_data()
method and dumps the hash as a string that can be loaded using eval()
.
[version 0.28]
Returns a human-readable (table-form) string showing all prerequisites, the versions required, and the versions actually installed. This can be useful for reviewing the configuration of your system prior to a build, or when compiling data to send for a bug report. The prereq_report
action is just a thin wrapper around the prereq_report()
method.
[version 0.12]
Asks the user a question and returns their response as a string. The first argument specifies the message to display to the user (for example, "Where do you keep your money?"
). The second argument, which is optional, specifies a default answer (for example, "wallet"
). The user will be asked the question once.
If prompt()
detects that it is not running interactively and there is nothing on STDIN or if the PERL_MM_USE_DEFAULT environment variable is set to true, the $default will be used without prompting.
To prevent automated processes from blocking, the user must either set PERL_MM_USE_DEFAULT or attach something to STDIN (this can be a pipe/file containing a scripted set of answers or /dev/null.)
If no $default is provided an empty string will be used instead. In non-interactive mode, the absence of $default is an error (though explicitly passing undef()
as the default is valid as of 0.27.)
This method may be called as a class or object method.
[version 0.21]
Returns a hash reference indicating the recommends
prerequisites that were passed to the new()
method.
[version 0.21]
Returns a hash reference indicating the requires
prerequisites that were passed to the new()
method.
[version 0.28]
Uses File::Find
to traverse the directory $dir
, returning a reference to an array of entries matching $pattern
. $pattern
may either be a regular expression (using qr//
or just a plain string), or a reference to a subroutine that will return true for wanted entries. If $pattern
is not given, all entries will be returned.
Examples:
# All the *.pm files in lib/
$m->rscan_dir('lib', qr/\.pm$/)
# All the files in blib/ that aren't *.html files
$m->rscan_dir('blib', sub {-f $_ and not /\.html$/});
# All the files in t/
$m->rscan_dir('t');
[version 0.28]
The runtime_params()
method stores the values passed on the command line for valid properties (that is, any command line options for which valid_property()
returns a true value). The value on the command line may override the default value for a property, as well as any value specified in a call to new()
. This allows you to programmatically tell if perl Build.PL
or any execution of ./Build
had command line options specified that override valid properties.
The runtime_params()
method is essentially a glorified read-only hash. With no arguments, runtime_params()
returns the entire hash of properties specified on the command line. With one argument, runtime_params($key)
returns the value associated with the given key.
The lifetime of the runtime_params
data is for "a build" - that is, the runtime_params
hash is created when perl Build.PL
is run (or when the new()
method is called, if the Module::Build Perl API is being used instead of called from a shell), and lasts until perl Build.PL
is run again or the clean
action is run.
[version 0.18]
Returns a hash reference whose keys are the perl script files to be installed, if any. This corresponds to the script_files
parameter to the new()
method. With an optional argument, this parameter may be set dynamically.
For backward compatibility, the scripts()
method does exactly the same thing as script_files()
. scripts()
is deprecated, but it will stay around for several versions to give people time to transition.
[version 0.20]
This method can be used to compare a set of source files to a set of derived files. If any of the source files are newer than any of the derived files, it returns false. Additionally, if any of the derived files do not exist, it returns false. Otherwise it returns true.
The arguments may be either a scalar or an array reference of file names.
[version 0.12]
Asks the user a yes/no question using prompt()
and returns true or false accordingly. The user will be asked the question repeatedly until they give an answer that looks like "yes" or "no".
The first argument specifies the message to display to the user (for example, "Shall I invest your money for you?"
), and the second argument specifies the default answer (for example, "y"
).
Note that the default is specified as a string like "y"
or "n"
, and the return value is a Perl boolean value like 1 or 0. I thought about this for a while and this seemed like the most useful way to do it.
This method may be called as a class or object method.
In addition to the aforementioned methods, there are also some get/set accessor methods for the following properties:
If you would like to add other useful metadata, Module::Build
supports this with the meta_add
and meta_merge
arguments to "new()". The authoritative list of supported metadata can be found at CPAN::META::Spec but for convenience - here are a few of the more useful ones:
Copyright (c) 2001-2006 Ken Williams. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4