📄 api.pod
字号:
=head1 NAMEModule::Build::API - API Reference for Module Authors=head1 DESCRIPTIONI list here some of the most important methods in C<Module::Build>.Normally you won't need to deal with these methods unless you want tosubclass C<Module::Build>. But since one of the reasons I createdthis module in the first place was so that subclassing is possible(and easy), I will certainly write more docs as the interfacestabilizes.=head2 CONSTRUCTORS=over 4=item current()[version 0.20]This method returns a reasonable facsimile of the currently-executingC<Module::Build> object representing the current build. You can usethis object to query its L</notes()> method, inquire about installedmodules, and so on. This is a great way to share information betweendifferent parts of your build process. For instance, you can askthe user a question during C<perl Build.PL>, then use their answerduring 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 C<current()> method is currently implemented, there may beslight differences between the C<$build> object in Build.PL and theone in C<t/colortest.t>. It is our goal to minimize these differencesin future releases of Module::Build, so please report any anomaliesyou find.One important caveat: in its current implementation, C<current()> willB<NOT> work correctly if you have changed out of the directory thatC<Module::Build> was invoked from.=item new()[version 0.03]Creates a new Module::Build object. Arguments to the new() method arelisted below. Most arguments are optional, but you must provideeither the L</module_name> argument, or L</dist_name> and one ofL</dist_version> or L</dist_version_from>. In other words, you mustprovide enough information to determine both a distribution name andversion.=over 4=item add_to_cleanup[version 0.19]An array reference of files to be cleaned up when the C<clean> actionis performed. See also the L<add_to_cleanup()|/"add_to_cleanup(@files)">method.=item auto_features[version 0.26]This parameter supports the setting of features (seeL</feature($name)>) automatically based on a set of prerequisites. Forinstance, for a module that could optionally use either MySQL orPostgreSQL databases, you might use C<auto_features> like 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, andif there are no failures, the feature will be enabled (set to C<1>).Otherwise the failures will be displayed to the user and the featurewill be disabled (set to C<0>).See the documentation for L</requires> for the details of howrequirements can be specified.=item autosplit[version 0.04]An optional C<autosplit> argument specifies a file which should be runthrough the L<AutoSplit::autosplit()|AutoSplit/autosplit> function.If multiple files should be split, the argument may be given as anarray of the files to split.In general I don't consider autosplitting a great idea, because it'snot always clear that autosplitting achieves its intended performancebenefits. It may even harm performance in environments like mod_perl,where as much as possible of a module's code should be loaded duringstartup.=item build_class[version 0.28]The Module::Build class or subclass to use in the build script.Defaults to "Module::Build" or the class name passed to or created bya call to L</subclass()>. This property is useful if you'rewriting a custom Module::Build subclass and have a bootstrappingproblem--that is, your subclass requires modules that may not beinstalled when C<perl Build.PL> is executed, but you've listed inL</build_requires> so that they should be available when C<./Build> isexecuted.=item build_requires[version 0.07]Modules listed in this section are necessary to build and install thegiven module, but are not necessary for regular usage of it. This isactually an important distinction - it allows for tighter control overthe body of installed modules, and facilitates correct dependencychecking on binary/packaged distributions of the module.See the documentation for L<Module::Build::Authoring/"PREREQUISITES">for the details of how requirements can be specified.=item create_packlist[version 0.28]If true, this parameter tells Module::Build to create a F<.packlist>file during the C<install> action, just like ExtUtils::MakeMaker does.The file is created in a subdirectory of the C<arch> installationlocation. It is used by some other tools (CPAN, CPANPLUS, etc.) fordetermining what files are part of an install.The default value is true. This parameter was introduced inModule::Build version 0.2609; previously no packlists were evercreated by Module::Build.=item c_source[version 0.04]An optional C<c_source> argument specifies a directory which containsC source files that the rest of the build may depend on. Any C<.c>files in the directory will be compiled to object files. Thedirectory will be added to the search path during the compilation andlinking phases of any C or XS files.=item conflicts[version 0.07]Modules listed in this section conflict in some serious way with thegiven module. C<Module::Build> (or some higher-level tool) willrefuse to install the given module if the given module/version is alsoinstalled.See the documentation for L<Module::Build::Authoring/"PREREQUISITES">for the details of how requirements can be specified.=item create_makefile_pl[version 0.19]This parameter lets you use Module::Build::Compat during theC<distdir> (or C<dist>) action to automatically create a Makefile.PLfor compatibility with ExtUtils::MakeMaker. The parameter's valueshould be one of the styles named in the L<Module::Build::Compat>documentation.=item create_readme[version 0.22]This parameter tells Module::Build to automatically create a F<README>file at the top level of your distribution. Currently it will simplyuse C<Pod::Text> (or C<Pod::Readme> if it's installed) on the fileindicated by C<dist_version_from> and put the result in the F<README>file. This is by no means the only recommended style for writing aREADME, but it seems to be one common one used on the CPAN.If you generate a F<README> in this way, it's probably a good idea tocreate a separate F<INSTALL> file if that information isn't in thegenerated F<README>.=item dist_abstract[version 0.20]This should be a short description of the distribution. This is usedwhen generating metadata for F<META.yml> and PPD files. If it is notgiven then C<Module::Build> looks in the POD of the module from whichit gets the distribution's version. It looks for the first linematching C<$package\s-\s(.+)>, and uses the captured text as theabstract.=item dist_author[version 0.20]This should be something like "John Doe <jdoe@example.com>", or ifthere are multiple authors, an anonymous array of strings may bespecified. This is used when generating metadata for F<META.yml> andPPD files. If this is not specified, then C<Module::Build> looks atthe module from which it gets the distribution's version. If it findsa POD section marked "=head1 AUTHOR", then it uses the contents ofthis section.=item dist_name[version 0.11]Specifies the name for this distribution. Most authors won't need toset this directly, they can use C<module_name> to set C<dist_name> toa reasonable default. However, some agglomerative distributions likeC<libwww-perl> or C<bioperl> have names that don't correspond directlyto a module name, so C<dist_name> can be set independently.=item dist_version[version 0.11]Specifies a version number for the distribution. See L</module_name>or L</dist_version_from> for ways to have this set automatically from aC<$VERSION> variable in a module. One way or another, a versionnumber needs to be set.=item dist_version_from[version 0.11]Specifies a file to look for the distribution version in. Mostauthors won't need to set this directly, they can use L</module_name>to set it to a reasonable default.The version is extracted from the specified file according to the samerules as L<ExtUtils::MakeMaker> and C<CPAN.pm>. It involves findingthe first line that matches the regular expression /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/eval()-ing that line, then checking the value of the C<$VERSION>variable. Quite ugly, really, but all the modules on CPAN depend onthis process, so there's no real opportunity to change to somethingbetter.=item dynamic_config[version 0.07]A boolean flag indicating whether the F<Build.PL> file must beexecuted, or whether this module can be built, tested and installedsolely from consulting its metadata file. The main reason to set thisto a true value is that your module performs some dynamicconfiguration as part of its build/install process. If the flag isomitted, the F<META.yml> spec says that installation tools shouldtreat it as 1 (true), because this is a safer way to behave.Currently C<Module::Build> doesn't actually do anything with this flag- it's up to higher-level tools like C<CPAN.pm> to do something usefulwith it. It can potentially bring lots of security, packaging, andconvenience improvements.=item extra_compiler_flags=item extra_linker_flags[version 0.19]These parameters can contain array references (or strings, in whichcase they will be split into arrays) to pass through to the compilerand linker phases when compiling/linking C code. For example, to tellthe 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`, );=item get_options[version 0.26]You can pass arbitrary command line options to F<Build.PL> orF<Build>, and they will be stored in the Module::Build object and canbe accessed via the L</args()> method. However, sometimes you wantmore flexibility out of your argument processing than this allows. Insuch cases, use the C<get_options> parameter to pass in a hashreference of argument specifications, and the list of arguments toF<Build.PL> or F<Build> will be processed according to thosespecifications before they're passed on to C<Module::Build>'s ownargument processing.The supported option specification hash keys are:=over 4=item typeThe type of option. The types are those supported by Getopt::Long; consultits documentation for a complete list. Typical types are C<=s> for strings,C<+> for additive options, and C<!> for negatable options. If thetype is not specified, it will be considered a boolean, i.e. noargument is taken and a value of 1 will be assigned when the option isencountered.=item storeA 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 thehash returned by the C<args()> method.=item defaultA default value for the option. If no default value is specified and no optionis passed, then the option key will not exist in the hash returned byC<args()>.=backYou can combine references to your own variables or subroutines withunreferenced specifications, for which the result will also be stored in thehash returned by C<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 --quantityB<WARNING:> Any option specifications that conflict with Module::Build's ownoptions (defined by its properties) will throw an exception.Consult the Getopt::Long documentation for details on its usage.=item include_dirs[version 0.24]Specifies any additional directories in which to search for C headerfiles. May be given as a string indicating a single directory, or asa list reference indicating multiple directories.=item install_path[version 0.19]You can set paths for individual installable elements by using theC<install_path> parameter: my $build = Module::Build->new ( ...other stuff here... install_path => { lib => '/foo/lib', arch => '/foo/lib/arch', } );=item installdirs[version 0.19]Determines where files are installed within the normal perl hierarchyas determined by F<Config.pm>. Valid values are: C<core>, C<site>,C<vendor>. The default is C<site>. SeeL<Module::Build/"INSTALL PATHS">=item license[version 0.07]Specifies the licensing terms of your distribution. Valid options include:=over 4=item apacheThe distribution is licensed under the Apache Software License(L<http://opensource.org/licenses/apachepl.php>).=item artistic
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -