Module...d::API(3pm)
π NAME π
Module::Build::API(3pm) β API Reference for Module Authors, from the User Contributed Perl Documentation.
β¨ DESCRIPTION β¨
okay so bestie, Iβm listing 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. π
β¨
π οΈ CONSTRUCTORS π οΈ
π« current() π«
[version 0.20]
This method returns a reasonable facsimile of the currently-executing Module::Build object representing the current build. You can use this object to query its notes() method, inquire about installed modules, and so on. This is a great way to share information between different parts of your build process. For instance, you can ask the user a question during perl Build.PL, then use their answer during a regression test:
# In Build.PL:
my $color = $build->prompt("What is your favorite color?");
$build->notes(color => $color);
# In t/colortest.t:
use Module::Build;
my $build = Module::Build->current;
my $color = $build->notes('color');
...
The way the current() method is currently implemented, there may be slight differences between the $build object in Build.PL and the one in t/colortest.t. It is our goal to minimize these differences in future releases of Module::Build, so please report any anomalies you find. π
One important caveat: in its current implementation, current() will NOT work correctly if you have changed out of the directory that Module::Build was invoked from. π¨
π new() π
[version 0.03]
Creates a new Module::Build object. Arguments to the new() method are listed below. Most arguments are optional, but you must provide either the module_name argument, or dist_name and one of dist_version or dist_version_from. In other words, you must provide enough information to determine both a distribution name and version. π§ π
add_to_cleanupβ[version 0.19]An array reference of files to be cleaned up when thecleanaction is performed. See also theadd_to_cleanup()method.allow_pureperlβ[version 0.4005]A bool indicating the module is still functional without its xs parts. When an XS module is build with--pureperl_only, it will otherwise fail.auto_configure_requiresβ[version 0.34]This parameter determines whether Module::Build will add itself automatically to configure_requires (and build_requires) if Module::Build is not already there. The required version will be the last βmajorβ release, as defined by the decimal version truncated to two decimal places (e.g. 0.34, instead of 0.3402). The default value is true.auto_featuresβ[version 0.26]This parameter supports the setting of features (seefeature($name)) automatically based on a set of prerequisites. For instance, for a module that could optionally use either MySQL or PostgreSQL databases, you might useauto_featureslike this:
my $build = Module::Build->new
(
...other stuff here...
auto_features => {
pg_support => {
description => "Interface with Postgres databases",
requires => { 'DBD::Pg' => 23.3,
'DateTime::Format::Pg' => 0 },
},
mysql_support => {
description => "Interface with MySQL databases",
requires => { 'DBD::mysql' => 17.9,
'DateTime::Format::MySQL' => 0 },
},
}
);
For each feature named, the required prerequisites will be checked, and if there are no failures, the feature will be enabled (set to 1). Otherwise the failures will be displayed to the user and the feature will be disabled (set to 0). π₯
See the documentation for requires for the details of how requirements can be specified.
autosplitβ[version 0.04]An optionalautosplitargument specifies a file which should be run through theAutoSplit::autosplit()function. If multiple files should be split, the argument may be given as an array of the files to split.
In general I donβt consider autosplitting a great idea, because itβs not always clear that autosplitting achieves its intended performance benefits. It may even harm performance in environments like mod_perl, where as much as possible of a moduleβs code should be loaded during startup. π«
build_classβ[version 0.28]The Module::Build class or subclass to use in the build script. Defaults toModule::Buildor the class name passed to or created by a call tosubclass(). This property is useful if youβre writing a custom Module::Build subclass and have a bootstrapping problem--that is, your subclass requires modules that may not be installed whenperl Build.PLis executed, but youβve listed inbuild_requiresso that they should be available when./Buildis executed.build_requiresβ[version 0.07]Modules listed in this section are necessary to build and install the given module, but are not necessary for regular usage of it. This is actually an important distinction - it allows for tighter control over the body of installed modules, and facilitates correct dependency checking on binary/packaged distributions of the module.
See the documentation for PREREQUISITES in Module::Build::Authoring for the details of how requirements can be specified.
configure_requiresβ[version 0.30]Modules listed in this section must be installed before configuring this distribution (i.e. before running the Build.PL script). This might be a specific minimum version ofModule::Buildor any other module the Build.PL needs in order to do its stuff. Clients likeCPAN.pmorCPANPLUSwill be expected to pickconfigure_requiresout of the META.yml file and install these items before running theBuild.PL.
Module::Build may automatically add itself to configure_requires. See auto_configure_requires for details.
See the documentation for PREREQUISITES in Module::Build::Authoring for the details of how requirements can be specified.
test_requiresβ[version 0.4004]Modules listed in this section must be installed before testing the distribution.
See the documentation for PREREQUISITES in Module::Build::Authoring for the details of how requirements can be specified.
create_packlistβ[version 0.28]If true, this parameter tells Module::Build to create a .packlist file during theinstallaction, just likeExtUtils::MakeMakerdoes. The file is created in a subdirectory of thearchinstallation location. It is used by some other tools (CPAN, CPANPLUS, etc.) for determining what files are part of an install.
The default value is true. This parameter was introduced in Module::Build version 0.2609; previously no packlists were ever created by Module::Build. π
c_sourceβ[version 0.04]An optionalc_sourceargument specifies a directory or a reference to array of directories which contain C source files that the rest of the build may depend on. Any.cfiles in the directory will be compiled to object files. The directory will be added to the search path during the compilation and linking phases of any C or XS files.
[version 0.3604] A list of directories can be supplied using an anonymous array reference of strings.
conflictsβ[version 0.07]Modules listed in this section conflict in some serious way with the given module.Module::Build(or some higher-level tool) will refuse to install the given module if the given module/version is also installed.
See the documentation for PREREQUISITES in Module::Build::Authoring for the details of how requirements can be specified.
create_licenseβ[version 0.31]This parameter tells Module::Build to automatically create a LICENSE file at the top level of your distribution, containing the full text of the authorβs chosen license. This requiresSoftware::Licenseon the authorβs machine, and further requires that thelicenseparameter specifies a license that it knows about.create_makefile_plβ[version 0.19]This parameter lets you useModule::Build::Compatduring thedistdir(ordist) action to automatically create a Makefile.PL for compatibility withExtUtils::MakeMaker. The parameterβs value should be one of the styles named in the Module::Build::Compat documentation.
Use of this parameter is discouraged. π
create_readmeβ[version 0.22]This parameter tells Module::Build to automatically create a README file at the top level of your distribution. Currently it will simply usePod::Text(orPod::Readmeif itβs installed) on the file indicated bydist_version_fromand put the result in the README file. This is by no means the only recommended style for writing a README, but it seems to be one common one used on the CPAN.
If you generate a README in this way, itβs probably a good idea to create a separate INSTALL file if that information isnβt in the generated README. πΈ
dist_abstractβ[version 0.20]
This should be, like, a short description of the distribution β a lil one-liner vibe check. It gets used when generating metadata for META.yml and PPD files. If you don't give it, Module::Build goes digging in the POD of the module it got the distribution's version from. And if it finds a POD section marked =head1 NAME, it hunts for the first line matching \s+-\s+(.+) and uses the captured bit as your abstract. Cute, right? β¨
dist_author [version 0.20]
Okay so this one should be something like John Doe <jdoe@example.com>, or β plot twist β if there are multiple authors, you can pass an anonymous array of strings instead. π
It's used when generating metadata for META.yml and PPD files. If you don't specify it, Module::Build peeks at the module it's pulling the distribution's version from, and if it finds a POD section marked =head1 AUTHOR, it just uses the whole contents of that section.
dist_name [version 0.11]
Specifies the name for this distribution. Most authors won't need to set this directly β they can use module_name to set dist_name to a reasonable default and call it a day. But some agglomerative distributions like libwww-perl or bioperl have names that don't correspond directly to a module name, so dist_name can be set independently. main character energy, honestly π
dist_suffix [version 0.37]
Specifies an optional suffix to include after the version number in the distribution directory (and tarball) name. The only suffix currently recognized by PAUSE is 'TRIAL', which indicates that the distribution should not be indexed. For example:
Foo-Bar-1.23-TRIAL.tar.gz
This will automatically do the "right thing" depending on dist_version and release_status. When dist_version does not have an underscore and release_status is not 'stable', then dist_suffix will default to 'TRIAL'. Otherwise it will default to the empty string, disabling the suffix.
In general, authors should only set this if they must override the default behavior for some particular purpose. Like, don't touch it unless you have to, bestie π«Ά
dist_version [version 0.11]
Specifies a version number for the distribution. See module_name or dist_version_from for ways to have this set automatically from a $VERSION variable in a module. One way or another, a version number needs to be set β no version, no slay. π
dist_version_from [version 0.11]
Specifies a file to look for the distribution version in. Most authors won't need to set this directly β they can use module_name to set it to a reasonable default.
The version is extracted from the specified file according to the same rules as ExtUtils::MakeMaker and CPAN.pm. It involves finding the first line that matches the regular expression
/([\$*])(([\w\:\']*)\bVERSION)\b.*\=/
then eval()-ing that line, then checking the value of the $VERSION variable. Quite ugly, really, but all the modules on CPAN depend on this process, so there's no real opportunity to change to something better. π It's giving legacy code, but we respect the elders.
If the target file of dist_version_from contains more than one package declaration, the version returned will be the one matching the configured module_name.
dynamic_config [version 0.07]
A boolean flag indicating whether the Build.PL file must be executed to determine prerequisites, or whether they can be determined solely from consulting its metadata file. The main reason to set this to a true value is that your module adds or removes prerequisites dynamically in Build.PL. If the flag is omitted, it will be treated as 1 (true), because this is a safer way to behave. Safety first, always π
Currently Module::Build doesn't actually do anything with this flag β it's up to higher-level tools like CPAN.pm to do something useful with it. It can also be very helpful for static analysis. See "dynamic_config" in CPAN::Meta::Spec for details on the metadata field.
extra_compiler_flags ### extra_linker_flags [version 0.19]
These parameters can contain array references (or strings, in which case they will be split into arrays) to pass through to the compiler and linker phases when compiling/linking C code. For example, to tell the compiler that your code is C++, you might do:
my $build = Module::Build->new
(
module_name => 'Foo::Bar',
extra_compiler_flags => ['-x', 'c++'],
);
To link your XS code against glib you might write something like:
my $build = Module::Build->new
(
module_name => 'Foo::Bar',
dynamic_config => 1,
extra_compiler_flags => scalar `glib-config --cflags`,
extra_linker_flags => scalar `glib-config --libs`,
);
Look at those backticks living their best life π₯
extra_manify_args [version 0.4006]
Any extra arguments to pass to Pod::Man->new() when building man pages. One common choice might be utf8 => 1 to get Unicode support. Yes bestie, we love Unicode in our man pages π
get_options [version 0.26]
You can pass arbitrary command line options to Build.PL or Build, and they will be stored in the Module::Build object and can be accessed via the args() method. However, sometimes you want more flexibility out of your argument processing than this allows. In such cases, use the get_options parameter to pass in a hash reference of argument specifications, and the list of arguments to Build.PL or Build will be processed according to those specifications before they're passed on to Module::Build's own argument processing.
The supported option specification hash keys are:
type
The type of option. The types are those supported by Getopt::Long; consult its documentation for a complete list. Typical types are =s for strings, + for additive options, and ! for negatable options. If the type is not specified, it will be considered a boolean, i.e. no argument is taken and a value of 1 will be assigned when the option is encountered.
store
A reference to a scalar in which to store the value passed to the option. If not specified, the value will be stored under the option name in the hash returned by the args() method.
default
A default value for the option. If no default value is specified and no option is passed, then the option key will not exist in the hash returned by args().
You can combine references to your own variables or subroutines with unreferenced specifications, for which the result will also be stored in the hash returned by args(). For example:
my $loud = 0;
my $build = Module::Build->new
(
module_name => 'Foo::Bar',
get_options => {
Loud => { store => \$loud },
Dbd => { type => '=s' },
Quantity => { type => '+' },
}
);
print STDERR "HEY, ARE YOU LISTENING??\n" if $loud;
print "We'll use the ", $build->args('Dbd'), " DBI driver\n";
print "Are you sure you want that many?\n"
if $build->args('Quantity') > 2;
The arguments for such a specification can be called like so:
perl Build.PL --Loud --Dbd=DBD::pg --Quantity --Quantity --Quantity
WARNING: Any option specifications that conflict with Module::Build's own options (defined by its properties) will throw an exception. Use capitalized option names to avoid unintended conflicts with future Module::Build options. π¨ Not me warning you twice, it's fr fr important.
Consult the Getopt::Long documentation for details on its usage.
include_dirs [version 0.24]
Specifies any additional directories in which to search for C header files. May be given as a string indicating a single directory, or as a list reference indicating multiple directories. Easy peasy π¦
install_path [version 0.19]
You can set paths for individual installable elements by using the install_path parameter:
my $build = Module::Build->new
(
...other stuff here...
install_path => {
lib => '/foo/lib',
arch => '/foo/lib/arch',
}
);
installdirs [version 0.19]
Determines where files are installed within the normal perl hierarchy as determined by Config.pm. Valid values are: "core", "site", "vendor". The default is "site". See "INSTALL PATHS" in Module::Build β¨
license [version 0.07]
Specifies the licensing terms of your distribution. Legal era π
As of Module::Build version 0.36_14, you may use a Software::License subclass name (e.g. 'Apache_2_0') instead of one of the keys below.
The legacy list of valid license values include:
apacheβ The distribution is licensed under the Apache License, Version 2.0 (http://apache.org/licenses/LICENSE-2.0).apache_1_1β The distribution is licensed under the Apache Software License, Version 1.1 (http://apache.org/licenses/LICENSE-1.1).artisticβ The distribution is licensed under the Artistic License, as specified by the Artistic file in the standard Perl distribution.artistic_2β The distribution is licensed under the Artistic 2.0 License (http://opensource.org/licenses/artistic-license-2.0.php).bsdβ The distribution is licensed under the BSD License (http://www.opensource.org/licenses/bsd-license.php).gplβ the distro ships under the GNU General Public License (http://www.opensource.org/licenses/gpl-license.php). π§lgplβ the distro ships under the GNU Lesser General Public License (http://www.opensource.org/licenses/lgpl-license.php). π§mitβ the distro ships under the MIT License (http://opensource.org/licenses/mit-license.php). short and sweet, iconic of it honestly β¨mozillaβ the distro ships under the Mozilla Public License. (http://opensource.org/licenses/mozilla1.0.phporhttp://opensource.org/licenses/mozilla1.1.php) π¦open_sourceβ the distro ships under some other license that the Open Source Initiative has approved, listed over athttp://www.opensource.org/licenses/. πperlβ the distro can be copied and redistributed under the same terms as Perl itself (ngl this is by far the most common licensing option for modules on CPAN). bestie it's a dual license β the user gets to pick between the GPL or the Artistic license. πrestrictiveβ the distro may not be redistributed without special permission from the author and/or the copyright holder. π«unrestrictedβ the distro is under a license thatwww.opensource.orgdoes not approve of, but which still allows distribution with no restrictions. π¦
heads up, bestie π you still have to actually include the terms of your license in your code and your documentation β this field only sets the info that goes into distribution metadata so automated tools can figure out your licensing restrictions. Humans still need something to read, yk? And if you do choose to provide this field, make sure you keep it in sync with your written docs if you ever change your licensing terms. no cap.
You can also use a license type of "unknown" if you don't feel like spelling out your terms in the metadata. π
Also see the create_license parameter. π
π«Ά meta_add
[version 0.28]
A hash of key/value pairs that get added into the META.yml file during the distmeta action. Any existing entries with the same names will be overridden. β¨
See the "MODULE METADATA" section for details. π
πΈ meta_merge
[version 0.28]
A hash of key/value pairs that get merged into the META.yml file during the distmeta action. Any existing entries with the same names will be overridden. π¦
The only difference between meta_add and meta_merge is how they behave on hash-valued and array-valued entries: meta_add will completely blow away the existing hash or array value (π gone, reduced to atoms), but meta_merge will merge the supplied data into the existing hash or array value. π«Ά
See the "MODULE METADATA" section for details. π
π module_name
[version 0.03]
module_name is a shortcut for setting default values of dist_name and dist_version_from, which just reflects the fact that most CPAN distributions are centered around one "main" module. For instance, if you set module_name to Foo::Bar, then dist_name will default to Foo-Bar and dist_version_from will default to lib/Foo/Bar.pm. And dist_version_from will in turn be used to set dist_version. it's giving chain reaction β¨
Setting module_name won't override a dist_* parameter you specify explicitly. so like, your call wins, periodt π
π₯ needs_compiler
[version 0.36]
The needs_compiler parameter tells you whether a compiler is required to build the distribution. Default is false β unless XS files are found or the c_source parameter is set, in which case it's true. If it's true, ExtUtils::CBuilder is automatically added to build_requires if needed. π οΈ
For a distribution where a compiler is optional, e.g. a dual XS/pure-Perl distribution, needs_compiler should explicitly be set to a false value. fr fr, be explicit about it. π
π PL_files
[version 0.06]
An optional parameter specifying a set of .PL files in your distribution. These get run as Perl scripts before the rest of the files in your distribution are processed, with the name of the file they're generating passed in as an argument. They're usually used as templates for creating other files dynamically, so a file like lib/Foo/Bar.pm.PL might create the file lib/Foo/Bar.pm. π§
The files are specified with the .PL files as hash keys, and the file(s) they generate as hash values, like so:
my $build = Module::Build->new
(
module_name => 'Foo::Bar',
...
PL_files => { 'lib/Foo/Bar.pm.PL' => 'lib/Foo/Bar.pm' },
);
Note that the path specifications are always given in Unix-like format, not in the style of the local system. no exceptions bestie π
If your .PL scripts don't create any files, or if they create files with unexpected names, or even if they create multiple files, you can indicate that so Module::Build can properly handle these created files:
PL_files => {
'lib/Foo/Bar.pm.PL' => 'lib/Foo/Bar.pm',
'lib/something.PL' => ['/lib/something', '/lib/else'],
'lib/funny.PL' => [],
}
Here's an example of a simple PL file. π
my $output_file = shift;
open my $fh, ">", $output_file or die "Can't open $output_file: $!";
print $fh <<'END';
#!/usr/bin/perl
print "Hello, world!\n";
END
PL files are not installed by default, so it's safe to put them in lib/ and bin/. π«Ά
π pm_files
[version 0.19]
An optional parameter specifying the set of .pm files in this distribution, given as a hash reference whose keys are the files' locations in the distribution, and whose values are their logical locations based on their package name β i.e. where they would be found in a "normal" Module::Build-style distribution. This parameter is mainly intended to support alternative layouts of files. β¨
For instance, if you have an old-style MakeMaker distribution for a module called Foo::Bar and a Bar.pm file sitting at the top level of the distribution, you could specify your layout in your Build.PL like this:
my $build = Module::Build->new
(
module_name => 'Foo::Bar',
...
pm_files => { 'Bar.pm' => 'lib/Foo/Bar.pm' },
);
Note that the values should include lib/, because that's where they'd be found in a "normal" Module::Build-style distribution. π
Note also that the path specifications are always given in Unix-like format, not in the style of the local system. π
π¦ pod_files
[version 0.19]
Just like pm_files, but used for specifying the set of .pod files in your distribution. same energy, different extension π
π recommends
[version 0.08]
This is just like the requires argument, except modules listed here aren't essential β they're just a good idea. We'll just print a friendly warning if one of these modules isn't found, and keep on running. π«Ά
If a module is recommended but not required, all tests should still pass if it isn't installed. This may mean some tests get skipped when recommended dependencies aren't present. π
Automated tools like CPAN.pm should inform the user when recommended modules aren't installed, and they should offer to install them if they want to be helpful. π
See the docs for "PREREQUISITES" in Module::Build::Authoring for the details of how requirements can be specified. β
πΈ recursive_test_files
[version 0.28]
Normally, Module::Build does not search subdirectories when it's looking for tests to run. When this option is set, it'll search recursively in all subdirectories of the standard t test directory. go get those tests bestie π
π release_status
[version 0.37]
CPAN Meta Spec version 2 added release_status so authors can say how a distribution should be indexed. Consistent with the spec, this parameter can only have one of three values: 'stable', 'testing' or 'unstable'. π
Unless the author sets it explicitly, release_status defaults to 'stable' β unless dist_version contains an underscore, in which case it defaults to 'testing'. π¦
it is an error to specify arelease_statusof'stable'whendist_versioncontains an underscore character. π
π₯ requires
[version 0.07]
An optional requires argument specifies any module prerequisites that the current module depends on. π
One note: currently Module::Build doesn't actually require the user to have dependencies installed β it just strongly urges. In the future we may require it. There's also a recommends section for things that aren't absolutely required. π«Ά
Automated tools like CPAN.pm should refuse to install a module if one of its dependencies isn't satisfied, unless the user gives a force command. And if the tools are feeling helpful, they should also offer to install the dependencies. β¨
A synonym for requires is prereq, to help succour people transitioning from ExtUtils::MakeMaker. The requires term is preferred, but the prereq term will remain valid in future distributions. iykyk π
See the docs for "PREREQUISITES" in Module::Build::Authoring for the details of how requirements can be specified. β
π script_files
[version 0.18]
okay this one's about to get its own whole moment β coming right up π
share_dir[version 0.36] β an optional param where you point at directories of static data files that get installed as read-only files for use withFile::ShareDir. Bestie, theshare_dirproperty is flexible β it handles both distribution-level and module-level share files. π
The simplest way to use it is to set it to a directory name (or an arrayref of directory names) holding the files you want dropped into the distribution-level share directory:
share_dir => 'share'
Or, if share_dir is a hashref, it can have dist or module keys, which gives you full flexibility in defining exactly how share directories get installed:
share_dir => {
dist => [ 'examples', 'more_examples' ],
module => {
Foo::Templates => ['share/html', 'share/text'],
Foo::Config => 'share/config',
}
}
And lowkey important: if share_dir is set, then File::ShareDir gets automatically added to the requires hash. Slay, it handles itself. β¨
sign[version 0.16] β if you give this parameter a true value,Module::Signaturegets used (via the'distsign'action) to create aSIGNATUREfile for your distribution during the'distdir'action, and to add theSIGNATUREfile to theMANIFEST. So do NOT add it yourself, bestie. π
The default value is false. In the future, the default may change to true if you have Module::Signature installed on your system. iykyk, watch this space. π
tap_harness_args[version 0.2808_03] β an optional parameter specifying parameters to pass toTAP::Harnesswhen running tests. Must be given as a hash reference of parameters; peep theTAP::Harnessdocumentation for the details. Heads up though: specifying this parameter will implicitly setuse_tap_harnessto a true value. So you must therefore be sure to addTAP::Harnessas a requirement for your module inbuild_requires. No skipping that step, fr. πtest_files[version 0.23] β an optional parameter specifying a set of files to use asTest::Harness-style regression tests, run during thetestaction. You can give it an array reference of the files, or a hash reference whose keys are the files (and whose values will currently be ignored β they're just vibing π¦). If the argument is given as a single string (not in an array reference), that string gets treated as aglob()pattern specifying the files to use.
The default is to look for a test.pl script in the top-level directory of the distribution, plus any files matching the glob pattern *.t in the t/ subdirectory. And if the recursive_test_files property is true, then the t/ directory gets scanned recursively for *.t files. iconic. π₯
use_tap_harness[version 0.2808_03] β an optional parameter saying whether or not to useTAP::Harnessfor testing instead ofTest::Harness. Defaults to false. If you set it to true, you must therefore be sure to addTAP::Harnessas a requirement for your module inbuild_requires. It's implicitly set to a true value iftap_harness_argsis specified. the way that one flag drags the other along πxs_files[version 0.19] β just likepm_files, but used for specifying the set of.xsfiles in your distribution. same energy, different file extension π
πΈ new_from_context(%args) πΈ
[version 0.28]
When it's called from a directory containing a Build.PL script β in other words, the base directory of a distribution β this method runs the Build.PL and calls resume() to hand the resulting Module::Build object back to the caller. π«Ά
Any key-value arguments you give to new_from_context() are essentially like command line arguments given to the Build.PL script. So for example you could pass verbose => 1 to this method to turn on verbosity. easy. β
π resume() π
[version 0.03]
You'll probably never call this method directly β it's only called from the auto-generated Build script (and the new_from_context method). π
Here's the lore: the new() method is only called once, when the user runs perl Build.PL. After that, whenever the user runs Build test or another action, the Module::Build object gets created using the resume() method, re-instantiating it with the settings given earlier to new(). It's giving "we remember everything so you don't have to." β¨
π¦ subclass() π¦
[version 0.06]
This creates a new Module::Build subclass on the fly, as described in the "SUBCLASSING" in Module::Build::Authoring section. The caller has to provide either a class or code parameter, or both. π
- The
classparameter indicates the name to use for the new subclass, and defaults toMyModuleBuilder. - The
codeparameter specifies Perl code to use as the body of the subclass.
main character energy for real. π
π add_property π
[version 0.31]
package 'My::Build';
use base 'Module::Build';
__PACKAGE__->add_property( 'pedantic' );
__PACKAGE__->add_property( answer => 42 );
__PACKAGE__->add_property(
'epoch',
default => sub { time },
check => sub {
return 1 if /^\d+$/;
shift->property_error( "'$_' is not an epoch time" );
return 0;
},
);
Adds a property to a Module::Build class. Properties are those attributes of a Module::Build object that can be passed to the constructor and that have accessors to get and set them. All of the core properties β think module_name and license β are defined using this class method. so they're literally built different, same way. π§
The first argument to add_property() is always the name of the property. The second argument can be either a default value for the property, or a list of key/value pairs. The supported keys are:
"default"β the default value. It may optionally be specified as a code reference, in which case the return value from executing that code reference will be used. And if you need the default to be a code reference, just use a code reference to return it, like:
default => sub { sub { ... } },
yes, code-ception. it's giving inception but make it Perl. π
"check"β a code reference that checks whether a value specified for the property is valid. During the execution of that code reference, the new value will be included in the$_variable. If the value is correct, the"check"code reference should return true. If the value is not correct, it sends an error message toproperty_error()and returns false. vibe check, but make it code. β
When this method is called, a new property gets installed in the Module::Build class, and an accessor gets built so you can get or set the property on the build object:
print $build->pedantic, $/;
$build->pedantic(0);
And bestie, if the default value is a hash reference, this generates a special-case accessor method, wherein individual key/value pairs may be set or fetched:
print "stuff{foo} is: ", $build->stuff( 'foo' ), $/;
$build->stuff( foo => 'bar' );
print $build->stuff( 'foo' ), $/; # Outputs "bar"
Of course, you can still set the entire hash reference at once too, no cap:
$build->stuff( { foo => 'bar', baz => 'yo' } );
In either case, if a "check" has been specified for the property, it gets applied to the entire hash. So the check code reference should look something like:
check => sub {
return 1 if defined $_ && exists $_->{foo};
shift->property_error(qq{Property "stuff" needs "foo"});
return 0;
},
π property_error π
[version 0.31]
That's it. That's the whole entry. π The manpage drops the name, the version, and dips β no description, no explanation, nothing. Respect the mystery. π΅οΈ
β¨ METHODS β¨
okay we're in the methods section now, buckle up bestie, this is where the actual doing-stuff lives π
π₯ add_build_element($type) π₯
[version 0.26]
Adds a new type of entry to the build process. Accepts a single string specifying its type-name. π―
But listen β there must also be a method defined to process things of that type. So if you add a build element called 'foo', then you must also define a method called process_foo_files(). no element without its handler, them's the rules. π
See also "Adding new file types to the build process" in Module::Build::Cookbook. π
πΈ add_to_cleanup(@files) πΈ
[version 0.03]
You can 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 (like in Build.PL) and the native format when the names are programmatically generated (like in a testing script). π¦
And here's the little author's note: 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 those 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. honestly? iconic design philosophy. π«Ά
β args() β
[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, obviously. all killer, no filler. π
- In scalar context with no arguments, it hands you back a reference to the hash that's storing, like, all the arguments.
- In array context with no arguments, you get the hash itself.
- Pass one argument β you get the value stored in the args hash for that option key.
- Pass two arguments β the second one is assigned to the args hash under the key you passed first. cute, efficient, slay.
autosplit_file($from, $to) β¨
[version 0.28]
Calls in the AutoSplit module on the $from file and ships the output over to the lib/auto directory inside $to. And $to is typically your blib/ directory, k? π«Ά
base_dir() πΈ
[version 0.14]
Gives you a string with the root-level directory of this build β as in, where the Build.PL script and the lib directory live. Ngl this is usually the exact same as the current working directory, because the Build script literally chdir()s into this directory the moment it starts executing. main character behaviour π
build_requires() π
[version 0.21]
Returns a hash reference showing off the build_requires prerequisites that got passed to the new() method. that's it, that's the vibe check.
can_action($action) π
Returns a reference to the method that defines $action, or false otherwise. Super handy for actions that are defined (or maybe not! π) in subclasses.
[version 0.32_xx]
cbuilder() π₯
[version 0.2809]
Returns the internal ExtUtils::CBuilder object β the one that's used for compiling & linking C code. But if no such object is available (say, your system has no compiler installed), an exception gets thrown. so like, brace yourself π
check_installed_status($module, $version) π
[version 0.11]
This one returns a hash reference telling you whether a version dependency on a certain module is satisfied. You pass $module as a string, like "Data::Dumper" or "perl", and $version can take any of the forms described in "requires" above. Which is, like, very fine-grained version checking β obsessed.
The returned hash reference has this exact structure:
{
ok => $whether_the_dependency_is_satisfied,
have => $version_already_installed,
need => $version_requested, # Same as incoming $version argument
message => $informative_error_message,
}
If literally no version of $module is currently installed, the "have" value will be the string "<none>". Otherwise the "have" value is just the version of the installed module. But wait β heads up, bestie β this means if $module is installed but doesn't define a version number, the "have" value will be undef. Which is exactly why we don't use undef for the case when $module isn't installed at all. no cap, that distinction is doing work π§
You can call this as an object method ("$build->check_installed_status($module, $version)") or as a class method ("Module::Build->check_installed_status($module, $version)"). flexible icon π
check_installed_version($module, $version) β
[version 0.05]
Like check_installed_status(), except it just gives you a yes or no on whether module $module satisfies the dependency $version. lowkey simpler.
If the check succeeds, the return value is the actual version of $module installed on the system. Which lets you 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. π
And if $version is any non-true value (notably zero) and any version of $module is installed, we return true. In that 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. yes, it's giving mind-bendy, that's the point π
Generally you might prefer "check_installed_status" if you need detailed info, or this method if you just need a yes/no answer.
compare_versions($v1, $op, $v2) π¦
[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. π you've been warned.
In the future, the guts of this method might get replaced with a call out to "version.pm". watch this space, i guess.
config($key) / config($key, $value) / config() [deprecated] π
[version 0.22]
- With a single argument
$key, it returns the value associated with that key in the"Config.pm"hash, including any changes the author or user has specified. - With
$keyand$valuearguments, it sets the value for future callers ofconfig($key). - With no arguments, it returns a hash reference containing all such key-value pairs. But that usage is deprecated, though, because it's a resource hog and violates encapsulation. π periodt.
config_data($name) / config_data($name => $value) π
[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 can 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 config variables called "mysql_connect" and "postgres_connect", and set each one to an array of connection parameters for "DBI->connect()". chef's kiss π€
Configuration values set 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)". iconic.
The feature() and config_data() methods are Module::Build's main support for configuration of installed modules. See also "SAVING CONFIGURATION INFORMATION" in Module::Build::Authoring. π
conflicts() π
[version 0.21]
Returns a hash reference indicating the "conflicts" prerequisites that were passed to the new() method.
contains_pod($file) [deprecated] πΈ
[version 0.20]
[Deprecated] Please see Module::Metadata 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. so like, don't build your whole personality on it.
copy_if_modified(%parameters) π
[version 0.19]
Takes the file in the "from" parameter and copies it to the file in the "to" parameter β or to the directory in the "to_dir" parameter β but only 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" gets copied into "to_dir"; an optional "flatten" parameter copies into "to_dir" without doing that. no unnecessary work, we respect that β¨
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 get created automatically. it just handles it, king behaviour π
The destination file is set to read-only. And if the source file has the executable bit set, then the destination file will be made executable too. matching energy.
create_build_script() π₯
[version 0.05]
Creates an executable script called "Build" in the current directory, which 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 those get 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. fr fr, don't touch π€
current_action() β
[version 0.28]
Returns the name of the currently-running action, like "build" or "test". And heads up: this action isn't necessarily the one the user originally invoked. Example time β if the user invoked the "test" action, current_action() would initially return "test". But 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() goes back to returning "test". see, it's a whole journey π«
If you need to know the name of the original action invoked by the user, see "invoked_action()" below.
depends_on(@actions) π
[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 the same action isn't invoked multiple times. (Note: in future versions of Module::Build it's conceivable that this run-only-once mechanism will get changed to something more intelligent. π)
Also, 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. iykyk.
dir_contains($first_dir, $second_dir) π¦
[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 give you an easy way to figure this out (but "Path::Class" does...). π
dispatch($action, %args) π
[version 0.03]
(the deets on this one live in the next chunk, bestie β we're just getting the name card out π)
okay so this one fires off the build action $action π and yep, you can slide in a list of options and their values right after it β it's literally the same thing as calling an action from the command line and passing a list of options along with it.
Custom options that haven't been registered? those cannot just vibe in there, they have to be passed as a hash reference tucked under a key named "args":
$build->dispatch('foo', verbose => 1, args => { my_option => 'value' });
This method is intended to programmatically invoke build actions β think applications that control Module::Build-based builds π β and not for subclasses, ok?
Also go peep depends_on(). the one big distinction between the two: depends_on() is meant to call an action from inside another action, whereas dispatch() is the one that sets the very top action in motion. top action stays the main character, periodt π
β¨ dist_dir()
[version 0.28]
Returns the name of the directory that's gonna get created during the "dist" action π¦ the name is derived from the "dist_name" and "dist_version" properties.
πΈ dist_name()
[version 0.21]
Returns the name of the current distribution, exactly as it was passed to the new() method in a "dist_name" or modified "module_name" parameter.
β dist_version()
[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.
π₯ do_system($cmd, @args)
[version 0.21]
This is a fairly simple wrapper around Perl's system() built-in command β ngl it's very much giving "simple little helper" π hand it a command plus an array of optional arguments, and it prints the command to "STDOUT", then executes it using Perl's system(). It returns true or false to indicate success or failure (which is the opposite of how system() works, but lowkey way more intuitive).
Heads up bestie: if you supply a single argument to do_system(), it will/may be processed by the system's shell, and any special characters are gonna do their special character things π If you supply multiple arguments, no shell gets involved at all and the command is executed directly. no middleman.
π«Ά extra_compiler_flags()
π«Ά extra_compiler_flags(@flags)
[version 0.25]
Set or retrieve the extra compiler flags. Returns an arrayref of flags.
π«Ά extra_linker_flags()
π«Ά extra_linker_flags(@flags)
[version 0.25]
Set or retrieve the extra linker flags. Returns an arrayref of flags.
π
feature($name)
π
feature($name => $value)
[version 0.26]
One argument? returns true if the given feature is set. Two arguments? sets the given feature to the given boolean value π in this context, a "feature" is any optional functionality of an installed module. Like, say 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. iconic, honestly.
Features set 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 are basically Module::Build's whole main support system for configuration of installed modules. See also "SAVING CONFIGURATION INFORMATION" in Module::Build::Authoring.
π§ fix_shebang_line(@files)
[version 0.??]
Modifies any "shebang" line in the specified files so it uses 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 don't count. In particular, this means 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>.
π have_c_compiler()
[version 0.21]
Returns true if the current system seems to have a working C compiler. How do we even know? we currently determine this by attempting to compile a simple C source file and reporting whether the attempt was successful. vibe check via actual compilation, no cap π₯
π install_base_relpaths()
π install_base_relpaths($type)
π install_base_relpaths($type => $path)
[version 0.28]
Set or retrieve the relative paths that get appended to "install_base" for any installable element. This is useful if you wanna set the relative install path for custom build elements β¨
No argument? it returns a reference to a hash containing all the elements and their respective values. This hash should not be modified directly β use the multiple argument form below to change values, ok? π«Ά
The single argument form returns the value associated with the element $type.
The multiple argument form lets you 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. bye bestie π
π install_destination($type)
[version 0.28]
Returns the directory where items of type $type (e.g. "lib", "arch", "bin", or literally 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 all taken into account when determining the return value β everybody gets a vote π
π install_path()
π install_path($type)
π install_path($type => $path)
[version 0.28]
Set or retrieve paths for specific installable elements. Useful when you wanna examine any explicit install paths the user specified on the command line, or if you wanna set the install path for a specific installable element based on another attribute like install_base() πΈ
No argument? returns a reference to a hash containing all the elements and their respective values. This hash should not be modified directly β use the multiple argument form below, iykyk.
The single argument form returns the value associated with the element $type.
The multiple argument form lets you 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 π¦
π install_types()
[version 0.28]
Returns a list of installable types that this build knows about. Each of these types corresponds 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, because people love customizing.
β invoked_action()
[version 0.28]
This is the name of the original action invoked by the user. This value gets 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 while dependencies are evaluated π
Wanna know the name of the currently executing dependency? go see "current_action()" above.
π¦ notes()
π¦ notes($key)
π¦ notes($key => $value)
[version 0.20]
The notes() value lets you store your own persistent information about the build, and share that info among the different entities involved in the build π see the example in the current() method.
The notes() method is essentially a glorified hash access. No arguments β notes() returns the entire hash of notes. One argument β notes($key) returns the value associated with the given key. 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 being called from a shell), and it lasts until perl Build.PL is run again or the "clean" action is run. so it's got a whole lifespan, very main character π
πΈ orig_dir()
[version 0.28]
Returns a string containing the working directory that was in effect before the Build script chdir()-ed into the "base_dir". Handy for writing wrapper tools that might need to chdir() back out π«Ά go home, king.
π os_type()
[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 returns "undef" β though there shouldn't be many unknown platforms out there.
π§ is_vmsish()
π§ is_windowsish()
π§ is_unixish()
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 π sorry babes.
π₯ prefix_relpaths()
π₯ prefix_relpaths($installdirs)
π₯ prefix_relpaths($installdirs, $type)
π₯ prefix_relpaths($installdirs, $type => $path)
[version 0.28]
Set or retrieve the relative paths that get appended to "prefix" for any installable element β¨ useful if you wanna set the relative install path for custom build elements.
No argument? returns a reference to a hash containing all the elements and their respective values as defined by the current "installdirs" setting.
One argument? returns a reference to a hash containing all the 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 form below to change values, ok bestie? π«Ά
The two argument form returns the value associated with the element $type.
The multiple argument form lets you 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 π
π get_metadata()
[version 0.36]
Okay so this one hands you back a hashref of metadata you can use to build a YAML datastream, and it exists purely so you, the author, can override or customize the fields of META.yml. Like β it's your metadata, customize away π
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"β says whether missing required metadata fields should be a fatal error or not. ForMETAcreation it generally should be fatal, but forMYMETAcreation for end-users it should not be fatal. Different vibes for different files, y'know?"auto"β says whether any necessaryconfigure_requiresshould be automatically added. This one's used inMETAcreation.
This method is basically a wrapper around the old prepare_metadata API, now that we no longer use YAML::Node to hold metadata. Glow-up moment β¨
πΈ prepare_metadata() [deprecated] πΈ
[version 0.36]
Deprecated alert!! As of0.36, authors should use"get_metadata"instead. This method is preserved for backwards compatibility only β it's giving retirement-era icon, still around, still doing its thing, but pls use the new one π«Ά
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). That last argument is new as of 0.36. Earlier versions are always fatal on errors β no chill, no grace, just fatal π
Prior to version 0.36, this method took a YAML::Node as an argument to hold assembled metadata. Ancient history, bestie.
π¦ prereq_failures() π¦
[version 0.11]
Returns a data structure containing info about any failed prerequisites (of any of the types described above), or "undef" if all your prereqs are met. Undef = clean, no notes, we love to see it π
The data structure you get back is a hash reference. The top level keys are the type of prerequisite that 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. And those associated values are hash references holding info about the failure. Like so:
{
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 β with one twist: in the case of "conflicts" dependencies we change the "need" key to "conflicts" and construct a proper message. Little rebrand, same energy β¨
Examples, because iykyk:
# 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";
}
}
π prereq_data() π
[version 0.32]
Returns a reference to a hash describing all the prerequisites. The keys are the various prerequisite types β 'requires', 'build_requires', 'test_requires', 'configure_requires', 'recommends', or 'conflicts' β and the values are references to hashes of module names and version numbers. Only the prereq types that are actually defined get included, so no ghost keys π»
The "prereq_data" action is just a thin wrapper around the prereq_data() method, and it dumps the hash as a string that can be loaded using eval(). Iconic little one-liner-adjacent behaviour, honestly.
π prereq_report() π
[version 0.28]
Returns a human-readable (table-form) string showing all the prerequisites, the versions required, and the versions actually installed. So useful β perfect for reviewing your system's configuration before a build, or when you're compiling data to send in for a bug report. Receipts, basically π§Ύ
The "prereq_report" action is just a thin wrapper around the prereq_report() method. Short king.
π prompt($message, $default) π
[version 0.12]
Asks the user a question and returns their response as a string. The first argument is the message you show the user (for example, "Where do you keep your money?"). The second argument is optional and specifies a default answer (for example, "wallet"). The user gets asked the question once. One shot, no follow-ups π
If prompt() detects that it's not running interactively and there's nothing on STDIN, or if the PERL_MM_USE_DEFAULT environment variable is set to true, then $default gets used without prompting. No human required, slay.
Heads up bestie: to stop automated processes from blocking forever, the user must either setPERL_MM_USE_DEFAULTor attach something toSTDINβ that can be a pipe/file containing a scripted set of answers, or/dev/null.
If no $default is provided, an empty string gets used instead. BUT β in non-interactive mode, the absence of $default is an error. (Though explicitly passing undef() as the default is valid as of 0.27.) Nuance!! π
This method may be called as a class or object method. Flexible like that π
π recommends() π
[version 0.21]
Returns a hash reference indicating the "recommends" prerequisites that were passed to the new() method. That's it, that's the whole thing. Short and sweet.
β requires() β
[version 0.21]
Returns a hash reference indicating the "requires" prerequisites that were passed to the new() method. Same deal as recommends() but for the compulsory ones β the main characters of your dependency list π
π§ rscan_dir($dir, $pattern) π§
[version 0.28]
Uses "File::Find" to traverse the directory $dir, returning a reference to an array of entries matching $pattern. Now β $pattern can be a regular expression (using "qr//" or just a plain string), or a reference to a subroutine that returns true for wanted entries. And if $pattern isn't given at all, every entry gets returned. No filter, just vibes πΈ
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');
Look at that sub-ref pattern go. We love a callback π«Ά
π runtime_params() / runtime_params($key) π
[version 0.28]
The runtime_params() method stores the values passed on the command line for valid properties β meaning any command line options for which valid_property() returns a true value. The value on the command line may override a property's default value, as well as any value specified in a call to new(). So this lets you programmatically clock whether "perl Build.PL" or any execution of "./Build" had command line options specified that override valid properties. Detective mode π
Honestly, runtime_params() 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 that given key.
The lifetime of the "runtime_params" data is for "a build" β meaning the "runtime_params" hash is created when "perl Build.PL" is run (or when the new() method is called, if you're using the Module::Build Perl API instead of calling from a shell), and it lasts until "perl Build.PL" is run again or the "clean" action is run. Limited edition, expires fast β³
πΈ script_files() πΈ
[version 0.18]
Returns a hash reference whose keys are the perl script files to be installed (if there are any). This corresponds to the "script_files" parameter to the new() method. And with an optional argument, this parameter can be set dynamically β get and set, multitasking icon β¨
For backward compatibility, the scripts() method does exactly the same thing as script_files(). scripts() is deprecated, but it'll stay around for several versions to give people time to transition. Respectful exit, no drama π
π up_to_date($source_file, $derived_file) / up_to_date(\@source_files, \@derived_files) π
[version 0.20]
This method compares 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. Also, if any of the derived files don't even exist, it returns false. Otherwise? It returns true. Simple little truth machine π
The arguments may be either a scalar or an array reference of file names β your choice, both valid, no wrong answers.
π¦ y_n($message, $default) π¦
[version 0.12]
Asks the user a yes/no question using prompt() and returns true or false accordingly. And it keeps asking β repeatedly β until they give an answer that looks like "yes" or "no". It will not let go. Persistent queen π
The first argument is the message you show the user (for example, "Shall I invest your money for you?"), and the second argument specifies the default answer (for example, "y").
Important detail: the default is specified as a string like"y"or"n", and the return value is a Perl boolean value like1or0. The docs literally say the author thought about this for a while and this seemed like the most useful way to do it. Honestly? Fair. Valid reasoning, no notes π
This method may be called as a class or object method. Same as prompt() β flexible fr fr.
π Autogenerated Accessors π
In addition to all the methods we just talked about, there are also some get/set accessor methods for the following properties:
- **
PL_files() allow_mb_mismatch()allow_pureperl()auto_configure_requires()autosplit()base_dir()bindoc_dirs()blib()build_bat()build_class()build_elements()build_requires()build_script()bundle_inc()bundle_inc_preload()c_source()config_dir()configure_requires()conflicts()cover()cpan_client()create_license()create_makefile_pl()create_packlist()create_readme()debug()debugger()destdir()dynamic_config()extra_manify_args()get_options()html_css()include_dirs()install_base()installdirs()libdoc_dirs()license()magic_number()mb_version()meta_add()meta_merge()metafile()metafile2()module_name()mymetafile()mymetafile2()needs_compiler()orig_dir()perl()pm_files()pod_files()pollute()prefix()prereq_action_types()program_name()pureperl_only()quiet()recommends()recurse_into()recursive_test_files()requires()scripts()sign()tap_harness_args()test_file_exts()test_requires()use_rcfile()use_tap_harness()verbose()xs_files()
okay that's the whole roster, every last one of them, nothing skipped, nothing merged π you're welcome bestie.
β¨ MODULE METADATA β¨
so if you're feeling extra and wanna add other useful metadata, Module::Build is literally so here for that β it supports it via the meta_add and meta_merge arguments to new(). π«Ά
the authoritative list of supported metadata lives over at CPAN::Meta::Spec, but as a lil convenience, here are a few of the more useful ones (iykyk):
keywords
for describing the distribution using keyword (or "tags") so that CPAN.org indexing and search is more efficient and useful. πβ¨
resources
a list of additional resources available for users of the distribution. this can include links to a homepage on the web, a bug tracker, the repository location, and even a subscription page for the distribution mailing list. π
πΈ AUTHOR πΈ
Ken Williams <kwilliams@cpan.org> π
π COPYRIGHT π
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. π
π¦ SEE ALSO π¦
perl(1)Module::Build(3)Module::Build::Authoring(3)Module::Build::Cookbook(3)ExtUtils::MakeMaker(3)
META.yml Specification: CPAN::Meta::Spec β
and that's the whole thing, bestie β every single line, no cap. this lil masterpiece is perl v5.42.0, dated 2023-04-29, and it's giving documentation royalty fr fr. go build something iconic with it π
β¨π·
π¦ where this page comes from
- opensuse-leap 16.0: perl-Module-Build 0.423400-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms