Anton Berezin says that on FreeBSD we're wrong to be using -lc_r, and
[p5sagit/p5-mst-13.2.git] / lib / Module / Build / Authoring.pod
CommitLineData
bb4e9162 1=head1 NAME
2
3Module::Build::Authoring - Authoring Module::Build modules
4
5
6=head1 DESCRIPTION
7
8When creating a C<Build.PL> script for a module, something like the
9following code will typically be used:
10
11 use Module::Build;
12 my $build = Module::Build->new
13 (
14 module_name => 'Foo::Bar',
15 license => 'perl',
16 requires => {
17 'perl' => '5.6.1',
18 'Some::Module' => '1.23',
19 'Other::Module' => '>= 1.2, != 1.5, < 2.0',
20 },
21 );
22 $build->create_build_script;
23
24A simple module could get away with something as short as this for its
25C<Build.PL> script:
26
27 use Module::Build;
28 Module::Build->new(
29 module_name => 'Foo::Bar',
30 license => 'perl',
31 )->create_build_script;
32
33The model used by C<Module::Build> is a lot like the C<MakeMaker>
34metaphor, with the following correspondences:
35
36 In Module::Build In ExtUtils::MakeMaker
37 --------------------------- ------------------------
38 Build.PL (initial script) Makefile.PL (initial script)
39 Build (a short perl script) Makefile (a long Makefile)
40 _build/ (saved state info) various config text in the Makefile
41
42Any customization can be done simply by subclassing C<Module::Build>
43and adding a method called (for example) C<ACTION_test>, overriding
44the default 'test' action. You could also add a method called
45C<ACTION_whatever>, and then you could perform the action C<Build
46whatever>.
47
48For information on providing compatibility with
49C<ExtUtils::MakeMaker>, see L<Module::Build::Compat> and
50L<http://www.makemaker.org/wiki/index.cgi?ModuleBuildConversionGuide>.
51
52
53=head1 API
54
55I list here some of the most important methods in C<Module::Build>.
56Normally you won't need to deal with these methods unless you want to
57subclass C<Module::Build>. But since one of the reasons I created
58this module in the first place was so that subclassing is possible
59(and easy), I will certainly write more docs as the interface
60stabilizes.
61
62
63=head2 CONSTRUCTORS
64
65
66=over 4
67
68=item current()
69
a314697d 70[version 0.20]
71
bb4e9162 72This method returns a reasonable facsimile of the currently-executing
73C<Module::Build> object representing the current build. You can use
74this object to query its C<notes()> method, inquire about installed
75modules, and so on. This is a great way to share information between
76different parts of your build process. For instance, you can ask
77the user a question during C<perl Build.PL>, then use their answer
78during a regression test:
79
80 # In Build.PL:
81 my $color = $build->prompt("What is your favorite color?");
82 $build->notes(color => $color);
83
84 # In t/colortest.t:
85 use Module::Build;
86 my $build = Module::Build->current;
87 my $color = $build->notes('color');
88 ...
89
90The way the C<current()> method is currently implemented, there may be
91slight differences between the C<$build> object in Build.PL and the
92one in C<t/colortest.t>. It is our goal to minimize these differences
93in future releases of Module::Build, so please report any anomalies
94you find.
95
96One important caveat: in its current implementation, C<current()> will
97B<NOT> work correctly if you have changed out of the directory that
98C<Module::Build> was invoked from.
99
100=item new()
101
a314697d 102[version 0.03]
103
bb4e9162 104Creates a new Module::Build object. Arguments to the new() method are
105listed below. Most arguments are optional, but you must provide
106either the C<module_name> argument, or C<dist_name> and one of
107C<dist_version> or C<dist_version_from>. In other words, you must
108provide enough information to determine both a distribution name and
109version.
110
111
112=over 4
113
114=item add_to_cleanup
115
a314697d 116[version 0.19]
117
bb4e9162 118An array reference of files to be cleaned up when the C<clean> action
119is performed. See also the add_to_cleanup() method.
120
121=item auto_features
122
a314697d 123[version 0.26]
124
bb4e9162 125This parameter supports the setting of features (see
126L<feature($name)>) automatically based on a set of prerequisites. For
127instance, for a module that could optionally use either MySQL or
128PostgreSQL databases, you might use C<auto_features> like this:
129
130 my $build = Module::Build->new
131 (
132 ...other stuff here...
133 auto_features => {
134 pg_support => {
135 description => "Interface with Postgres databases",
136 requires => { 'DBD::Pg' => 23.3,
137 'DateTime::Format::Pg' => 0 },
138 },
139 mysql_support => {
140 description => "Interface with MySQL databases",
141 requires => { 'DBD::mysql' => 17.9,
142 'DateTime::Format::MySQL' => 0 },
143 },
144 }
145 );
146
147For each feature named, the required prerequisites will be checked, and
148if there are no failures, the feature will be enabled (set to C<1>).
149Otherwise the failures will be displayed to the user and the feature
150will be disabled (set to C<0>).
151
152See the documentation for L<requires> for the details of how
153requirements can be specified.
154
155=item autosplit
156
a314697d 157[version 0.04]
158
bb4e9162 159An optional C<autosplit> argument specifies a file which should be run
160through the C<Autosplit::autosplit()> function. If multiple files
161should be split, the argument may be given as an array of the files to
162split.
163
164In general I don't consider autosplitting a great idea, because it's
165not always clear that autosplitting achieves its intended performance
166benefits. It may even harm performance in environments like mod_perl,
167where as much as possible of a module's code should be loaded during
168startup.
169
170=item build_class
171
a314697d 172[version 0.28]
173
bb4e9162 174The Module::Build class or subclass to use in the build
175script. Defaults to "Module::Build" or the class name passed to or
176created by a call to C<subclass()>. This property is useful if you're
177writing a custom Module::Build subclass and have a bootstrapping
178problem--that is, your subclass requires modules that may not be
179installed when C<perl Build.PL> is executed, but you've listed in
180C<build_requires> so that they should be available when C<./Build> is
181executed.
182
183=item build_requires
184
a314697d 185[version 0.07]
186
bb4e9162 187Modules listed in this section are necessary to build and install the
188given module, but are not necessary for regular usage of it. This is
189actually an important distinction - it allows for tighter control over
190the body of installed modules, and facilitates correct dependency
191checking on binary/packaged distributions of the module.
192
193See the documentation for L<"PREREQUISITES"> for the details of how
194requirements can be specified.
195
a314697d 196=item create_packlist
197
198If true, this parameter tells Module::Build to create a F<.packlist>
199file during the C<install> action, just like ExtUtils::MakeMaker does.
200The file is created in a subdirectory of the C<arch> installation
201location. It is used by some other tools (CPAN, CPANPLUS, etc.) for
202determining what files are part of an install.
203
204The default value is true. This parameter was introduced in
205Module::Build version 0.2609; previously no packlists were ever
206created by Module::Build.
207
bb4e9162 208=item c_source
209
a314697d 210[version 0.04]
211
bb4e9162 212An optional C<c_source> argument specifies a directory which contains
213C source files that the rest of the build may depend on. Any C<.c>
214files in the directory will be compiled to object files. The
215directory will be added to the search path during the compilation and
216linking phases of any C or XS files.
217
218=item conflicts
219
a314697d 220[version 0.07]
221
bb4e9162 222Modules listed in this section conflict in some serious way with the
223given module. C<Module::Build> (or some higher-level tool) will
224refuse to install the given module if the given module/version is also
225installed.
226
227See the documentation for L<"PREREQUISITES"> for the details of how
228requirements can be specified.
229
230=item create_makefile_pl
231
a314697d 232[version 0.19]
233
bb4e9162 234This parameter lets you use Module::Build::Compat during the
235C<distdir> (or C<dist>) action to automatically create a Makefile.PL
236for compatibility with ExtUtils::MakeMaker. The parameter's value
237should be one of the styles named in the Module::Build::Compat
238documentation.
239
240=item create_readme
241
a314697d 242[version 0.22]
243
bb4e9162 244This parameter tells Module::Build to automatically create a F<README>
245file at the top level of your distribution. Currently it will simply
246use C<Pod::Text> (or C<Pod::Readme> if it's installed) on the file
247indicated by C<dist_version_from> and put the result in the F<README>
248file. This is by no means the only recommended style for writing a
249README, but it seems to be one common one used on the CPAN.
250
251If you generate a F<README> in this way, it's probably a good idea to
252create a separate F<INSTALL> file if that information isn't in the
253generated F<README>.
254
255=item dist_abstract
256
a314697d 257[version 0.20]
258
bb4e9162 259This should be a short description of the distribution. This is used
260when generating metadata for F<META.yml> and PPD files. If it is not
261given then C<Module::Build> looks in the POD of the module from which
262it gets the distribution's version. It looks for the first line
263matching C<$package\s-\s(.+)>, and uses the captured text as the
264abstract.
265
266=item dist_author
267
a314697d 268[version 0.20]
269
bb4e9162 270This should be something like "John Doe <jdoe@example.com>", or if
271there are multiple authors, an anonymous array of strings may be
272specified. This is used when generating metadata for F<META.yml> and
273PPD files. If this is not specified, then C<Module::Build> looks at
274the module from which it gets the distribution's version. If it finds
275a POD section marked "=head1 AUTHOR", then it uses the contents of
276this section.
277
278=item dist_name
279
a314697d 280[version 0.11]
281
bb4e9162 282Specifies the name for this distribution. Most authors won't need to
283set this directly, they can use C<module_name> to set C<dist_name> to
284a reasonable default. However, some agglomerative distributions like
285C<libwww-perl> or C<bioperl> have names that don't correspond directly
286to a module name, so C<dist_name> can be set independently.
287
288=item dist_version
289
a314697d 290[version 0.11]
291
bb4e9162 292Specifies a version number for the distribution. See C<module_name>
293or C<dist_version_from> for ways to have this set automatically from a
294C<$VERSION> variable in a module. One way or another, a version
295number needs to be set.
296
297=item dist_version_from
298
a314697d 299[version 0.11]
300
bb4e9162 301Specifies a file to look for the distribution version in. Most
302authors won't need to set this directly, they can use C<module_name>
303to set it to a reasonable default.
304
305The version is extracted from the specified file according to the same
306rules as C<ExtUtils::MakeMaker> and C<CPAN.pm>. It involves finding
307the first line that matches the regular expression
308
309 /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/
310
311eval()-ing that line, then checking the value of the C<$VERSION>
312variable. Quite ugly, really, but all the modules on CPAN depend on
313this process, so there's no real opportunity to change to something
314better.
315
316=item dynamic_config
317
a314697d 318[version 0.07]
319
bb4e9162 320A boolean flag indicating whether the F<Build.PL> file must be
321executed, or whether this module can be built, tested and installed
322solely from consulting its metadata file. The main reason to set this
323to a true value is that your module performs some dynamic
324configuration as part of its build/install process. If the flag is
325omitted, the F<META.yml> spec says that installation tools should
326treat it as 1 (true), because this is a safer way to behave.
327
328Currently C<Module::Build> doesn't actually do anything with this flag
329- it's up to higher-level tools like C<CPAN.pm> to do
330something useful with it. It can potentially bring lots of security,
331packaging, and convenience improvements.
332
333=item extra_compiler_flags
334
335=item extra_linker_flags
336
a314697d 337[version 0.19]
338
bb4e9162 339These parameters can contain array references (or strings, in which
340case they will be split into arrays) to pass through to the compiler
341and linker phases when compiling/linking C code. For example, to tell
342the compiler that your code is C++, you might do:
343
344 my $build = Module::Build->new
345 (
346 module_name => 'Foo::Bar',
347 extra_compiler_flags => ['-x', 'c++'],
348 );
349
350To link your XS code against glib you might write something like:
351
352 my $build = Module::Build->new
353 (
354 module_name => 'Foo::Bar',
355 dynamic_config => 1,
356 extra_compiler_flags => scalar `glib-config --cflags`,
357 extra_linker_flags => scalar `glib-config --libs`,
358 );
359
360=item get_options
361
a314697d 362[version 0.26]
363
bb4e9162 364You can pass arbitrary command line options to F<Build.PL> or
365F<Build>, and they will be stored in the Module::Build object and can
366be accessed via the C<args()> method. However, sometimes you want
367more flexibility out of your argument processing than this allows. In
368such cases, use the C<get_options> parameter to pass in a hash
369reference of argument specifications, and the list of arguments to
370F<Build.PL> or F<Build> will be processed according to those
371specifications before they're passed on to C<Module::Build>'s own
372argument processing.
373
374The supported option specification hash keys are:
375
376
377=over 4
378
379=item type
380
381The type of option. The types are those supported by Getopt::Long; consult
382its documentation for a complete list. Typical types are C<=s> for strings,
383C<+> for additive options, and C<!> for negatable options. If the
384type is not specified, it will be considered a boolean, i.e. no
385argument is taken and a value of 1 will be assigned when the option is
386encountered.
387
388=item store
389
390A reference to a scalar in which to store the value passed to the option.
391If not specified, the value will be stored under the option name in the
392hash returned by the C<args()> method.
393
394=item default
395
396A default value for the option. If no default value is specified and no option
397is passed, then the option key will not exist in the hash returned by
398C<args()>.
399
400=back
401
402
403You can combine references to your own variables or subroutines with
404unreferenced specifications, for which the result will also be stored in the
405hash returned by C<args()>. For example:
406
407 my $loud = 0;
408 my $build = Module::Build->new
409 (
410 module_name => 'Foo::Bar',
411 get_options => {
412 loud => { store => \$loud },
413 dbd => { type => '=s' },
414 quantity => { type => '+' },
415 }
416 );
417
418 print STDERR "HEY, ARE YOU LISTENING??\n" if $loud;
419 print "We'll use the ", $build->args('dbd'), " DBI driver\n";
420 print "Are you sure you want that many?\n"
421 if $build->args('quantity') > 2;
422
423The arguments for such a specification can be called like so:
424
425 perl Build.PL --loud --dbd=DBD::pg --quantity --quantity --quantity
426
427B<WARNING:> Any option specifications that conflict with Module::Build's own
428options (defined by its properties) will throw an exception.
429
430Consult the Getopt::Long documentation for details on its usage.
431
432=item include_dirs
433
a314697d 434[version 0.24]
435
bb4e9162 436Specifies any additional directories in which to search for C header
437files. May be given as a string indicating a single directory, or as
438a list reference indicating multiple directories.
439
440=item install_path
441
a314697d 442[version 0.19]
443
bb4e9162 444You can set paths for individual installable elements by using the
445C<install_path> parameter:
446
447 my $build = Module::Build->new
448 (
449 ...other stuff here...
450 install_path => {
451 lib => '/foo/lib',
452 arch => '/foo/lib/arch',
453 }
454 );
455
456=item installdirs
457
a314697d 458[version 0.19]
459
bb4e9162 460Determines where files are installed within the normal perl hierarchy
461as determined by F<Config.pm>. Valid values are: C<core>, C<site>,
462C<vendor>. The default is C<site>. See
463L<Module::Build/"INSTALL PATHS">
464
465=item license
466
a314697d 467[version 0.07]
468
bb4e9162 469Specifies the licensing terms of your distribution. Valid options include:
470
471
472=over 4
473
474=item apache
475
476The distribution is licensed under the Apache Software License
477(http://opensource.org/licenses/apachepl.php).
478
479=item artistic
480
481The distribution is licensed under the Artistic License, as specified
482by the F<Artistic> file in the standard perl distribution.
483
484=item bsd
485
486The distribution is licensed under the BSD License
487(http://www.opensource.org/licenses/bsd-license.php).
488
489=item gpl
490
491The distribution is licensed under the terms of the Gnu General
492Public License (http://www.opensource.org/licenses/gpl-license.php).
493
494=item lgpl
495
496The distribution is licensed under the terms of the Gnu Lesser
497General Public License
498(http://www.opensource.org/licenses/lgpl-license.php).
499
500=item mit
501
502The distribution is licensed under the MIT License
503(http://opensource.org/licenses/mit-license.php).
504
505=item mozilla
506
507The distribution is licensed under the Mozilla Public
508License. (http://opensource.org/licenses/mozilla1.0.php or
509http://opensource.org/licenses/mozilla1.1.php)
510
511=item open_source
512
513The distribution is licensed under some other Open Source
514Initiative-approved license listed at
515http://www.opensource.org/licenses/ .
516
517=item perl
518
519The distribution may be copied and redistributed under the same terms
520as perl itself (this is by far the most common licensing option for
521modules on CPAN). This is a dual license, in which the user may
522choose between either the GPL or the Artistic license.
523
524=item restrictive
525
526The distribution may not be redistributed without special permission
527from the author and/or copyright holder.
528
529=item unrestricted
530
531The distribution is licensed under a license that is B<not> approved
532by www.opensource.org but that allows distribution without
533restrictions.
534
535=back
536
537
538Note that you must still include the terms of your license in your
539documentation - this field only lets automated tools figure out your
540licensing restrictions. Humans still need something to read. If you
541choose to provide this field, you should make sure that you keep it in
542sync with your written documentation if you ever change your licensing
543terms.
544
545It is a fatal error to use a license other than the ones mentioned
546above. This is not because I wish to impose licensing terms on you -
547please let me know if you would like another license option to be
548added to the list. You may also use a license type of C<unknown> if
549you don't wish to specify your terms (but this is usually not a good
550idea for you to do!).
551
552I just started out with a small set of licenses to keep things simple,
553figuring I'd let people with actual working knowledge in this area
554tell me what to do. So if that's you, drop me a line.
555
556=item meta_add
557
a314697d 558[version 0.28]
559
bb4e9162 560A hash of key/value pairs that should be added to the F<META.yml> file
561during the C<distmeta> action. Any existing entries with the same
562names will be overridden.
563
564=item meta_merge
565
a314697d 566[version 0.28]
567
bb4e9162 568A hash of key/value pairs that should be merged into the F<META.yml>
569file during the C<distmeta> action. Any existing entries with the
570same names will be overridden.
571
572The only difference between C<meta_add> and C<meta_merge> is their
573behavior on hash-valued and array-valued entries: C<meta_add> will
574completely blow away the existing hash or array value, but
575C<meta_merge> will merge the supplied data into the existing hash or
576array value.
577
578=item module_name
579
a314697d 580[version 0.03]
581
bb4e9162 582The C<module_name> is a shortcut for setting default values of
583C<dist_name> and C<dist_version_from>, reflecting the fact that the
584majority of CPAN distributions are centered around one "main" module.
585For instance, if you set C<module_name> to C<Foo::Bar>, then
586C<dist_name> will default to C<Foo-Bar> and C<dist_version_from> will
587default to C<lib/Foo/Bar.pm>. C<dist_version_from> will in turn be
588used to set C<dist_version>.
589
590Setting C<module_name> won't override a C<dist_*> parameter you
591specify explicitly.
592
593=item PL_files
594
a314697d 595[version 0.06]
596
bb4e9162 597An optional parameter specifying a set of C<.PL> files in your
598distribution. These will be run as Perl scripts prior to processing
599the rest of the files in your distribution. They are usually used as
600templates for creating other files dynamically, so that a file like
601C<lib/Foo/Bar.pm.PL> might create the file C<lib/Foo/Bar.pm>.
602
603The files are specified with the C<.PL> files as hash keys, and the
604file(s) they generate as hash values, like so:
605
606 my $build = Module::Build->new
607 (
608 module_name => 'Foo::Bar',
609 ...
610 PL_files => { 'lib/Foo/Bar.pm.PL' => 'lib/Foo/Bar.pm' },
611 );
612
613Note that the path specifications are I<always> given in Unix-like
614format, not in the style of the local system.
615
616If your C<.PL> scripts don't create any files, or if they create files
617with unexpected names, or even if they create multiple files, you can
618indicate that so that Module::Build can properly handle these created
619files:
620
621 PL_files => {
622 'lib/Foo/Bar.pm.PL' => 'lib/Foo/Bar.pm',
623 'lib/something.PL' => ['/lib/something', '/lib/else'],
624 'lib/funny.PL' => [],
625 }
626
627=item pm_files
628
a314697d 629[version 0.19]
630
bb4e9162 631An optional parameter specifying the set of C<.pm> files in this
632distribution, specified as a hash reference whose keys are the files'
633locations in the distributions, and whose values are their logical
634locations based on their package name, i.e. where they would be found
635in a "normal" Module::Build-style distribution. This parameter is
636mainly intended to support alternative layouts of files.
637
638For instance, if you have an old-style MakeMaker distribution for a
639module called C<Foo::Bar> and a F<Bar.pm> file at the top level of the
640distribution, you could specify your layout in your C<Build.PL> like
641this:
642
643 my $build = Module::Build->new
644 (
645 module_name => 'Foo::Bar',
646 ...
647 pm_files => { 'Bar.pm' => 'lib/Foo/Bar.pm' },
648 );
649
650Note that the values should include C<lib/>, because this is where
651they would be found in a "normal" Module::Build-style distribution.
652
653Note also that the path specifications are I<always> given in
654Unix-like format, not in the style of the local system.
655
656=item pod_files
657
a314697d 658[version 0.19]
659
bb4e9162 660Just like C<pm_files>, but used for specifying the set of C<.pod>
661files in your distribution.
662
663=item recommends
664
a314697d 665[version 0.08]
666
bb4e9162 667This is just like the C<requires> argument, except that modules listed
668in this section aren't essential, just a good idea. We'll just print
669a friendly warning if one of these modules aren't found, but we'll
670continue running.
671
672If a module is recommended but not required, all tests should still
673pass if the module isn't installed. This may mean that some tests
674may be skipped if recommended dependencies aren't present.
675
676Automated tools like CPAN.pm should inform the user when recommended
677modules aren't installed, and it should offer to install them if it
678wants to be helpful.
679
680See the documentation for L<"PREREQUISITES"> for the details of how
681requirements can be specified.
682
a314697d 683=item recursive_test_files
684
685[version 0.28]
686
687Normally, C<Module::Build> does not search subdirectories when looking
688for tests to run. When this options is set it will search recursively
689in all subdirectories of the standard 't' test directory.
690
bb4e9162 691=item requires
692
a314697d 693[version 0.07]
694
bb4e9162 695An optional C<requires> argument specifies any module prerequisites
696that the current module depends on.
697
698One note: currently C<Module::Build> doesn't actually I<require> the
699user to have dependencies installed, it just strongly urges. In the
700future we may require it. There's also a C<recommends> section for
701things that aren't absolutely required.
702
703Automated tools like CPAN.pm should refuse to install a module if one
704of its dependencies isn't satisfied, unless a "force" command is given
705by the user. If the tools are helpful, they should also offer to
706install the dependencies.
707
708A synonym for C<requires> is C<prereq>, to help succour people
709transitioning from C<ExtUtils::MakeMaker>. The C<requires> term is
710preferred, but the C<prereq> term will remain valid in future
711distributions.
712
713See the documentation for L<"PREREQUISITES"> for the details of how
714requirements can be specified.
715
716=item script_files
717
a314697d 718[version 0.18]
719
bb4e9162 720An optional parameter specifying a set of files that should be
721installed as executable perl scripts when the module is installed.
722May be given as an array reference of the files, or as a hash
723reference whose keys are the files (and whose values will currently be
724ignored).
725
726The default is to install no script files - in other words, there is
727no default location where Module::Build will look for script files to
728install.
729
730For backward compatibility, you may use the parameter C<scripts>
731instead of C<script_files>. Please consider this usage deprecated,
732though it will continue to exist for several version releases.
733
734=item sign
735
a314697d 736[version 0.16]
737
bb4e9162 738If a true value is specified for this parameter, C<Module::Signature>
739will be used (via the 'distsign' action) to create a SIGNATURE file
740for your distribution during the 'distdir' action, and to add the
741SIGNATURE file to the MANIFEST (therefore, don't add it yourself).
742
743The default value is false. In the future, the default may change to
744true if you have C<Module::Signature> installed on your system.
745
746=item test_files
747
a314697d 748[version 0.23]
749
bb4e9162 750An optional parameter specifying a set of files that should be used as
751C<Test::Harness>-style regression tests to be run during the C<test>
752action. May be given as an array reference of the files, or as a hash
753reference whose keys are the files (and whose values will currently be
754ignored). If the argument is given as a single string (not in an
755array reference), that string will be treated as a C<glob()> pattern
756specifying the files to use.
757
758The default is to look for a F<test.pl> script in the top-level
759directory of the distribution, and any files matching the glob pattern
760C<*.t> in the F<t/> subdirectory. If the C<recursive_test_files>
761property is true, then the C<t/> directory will be scanned recursively
762for C<*.t> files.
763
764=item xs_files
765
a314697d 766[version 0.19]
767
bb4e9162 768Just like C<pm_files>, but used for specifying the set of C<.xs>
769files in your distribution.
770
771=back
772
773
774=item new_from_context(%args)
775
a314697d 776[version 0.28]
777
bb4e9162 778When called from a directory containing a F<Build.PL> script and a
779F<META.yml> file (in other words, the base directory of a
780distribution), this method will run the F<Build.PL> and return the
781resulting C<Module::Build> object to the caller. Any key-value
782arguments given to C<new_from_context()> are essentially like
783command line arguments given to the F<Build.PL> script, so for example
784you could pass C<< verbose => 1 >> to this method to turn on
785verbosity.
786
787=item resume()
788
a314697d 789[version 0.03]
790
bb4e9162 791You'll probably never call this method directly, it's only called from
792the auto-generated C<Build> script. The C<new()> method is only
793called once, when the user runs C<perl Build.PL>. Thereafter, when
794the user runs C<Build test> or another action, the C<Module::Build>
795object is created using the C<resume()> method to re-instantiate with
796the settings given earlier to C<new()>.
797
798=item subclass()
799
a314697d 800[version 0.06]
801
bb4e9162 802This creates a new C<Module::Build> subclass on the fly, as described
803in the L<"SUBCLASSING"> section. The caller must provide either a
804C<class> or C<code> parameter, or both. The C<class> parameter
805indicates the name to use for the new subclass, and defaults to
806C<MyModuleBuilder>. The C<code> parameter specifies Perl code to use
807as the body of the subclass.
808
809=back
810
811
812=head2 METHODS
813
814
815=over 4
816
817=item add_build_element($type)
818
a314697d 819[version 0.26]
820
bb4e9162 821Adds a new type of entry to the build process. Accepts a single
822string specifying its type-name. There must also be a method defined
823to process things of that type, e.g. if you add a build element called
824C<'foo'>, then you must also define a method called
825C<process_foo_files()>.
826
827See also L<Module::Build::Cookbook/"Adding new file types to the build process">.
828
829=item add_to_cleanup(@files)
830
a314697d 831[version 0.03]
832
bb4e9162 833You may call C<< $self->add_to_cleanup(@patterns) >> to tell
834C<Module::Build> that certain files should be removed when the user
835performs the C<Build clean> action. The arguments to the method are
836patterns suitable for passing to Perl's C<glob()> function, specified
837in either Unix format or the current machine's native format. It's
838usually convenient to use Unix format when you hard-code the filenames
839(e.g. in F<Build.PL>) and the native format when the names are
840programmatically generated (e.g. in a testing script).
841
842I decided to provide a dynamic method of the C<$build> object, rather
843than just use a static list of files named in the F<Build.PL>, because
844these static lists can get difficult to manage. I usually prefer to
845keep the responsibility for registering temporary files close to the
846code that creates them.
847
848=item args()
849
a314697d 850[version 0.26]
851
bb4e9162 852 my $args_href = $build->args;
853 my %args = $build->args;
854 my $arg_value = $build->args($key);
855 $build->args($key, $value);
856
857This method is the preferred interface for retrieving the arguments passed via
858command line options to F<Build.PL> or F<Build>, minus the Module-Build
859specific options.
860
861When called in in a scalar context with no arguments, this method returns a
862reference to the hash storing all of the arguments; in an array context, it
863returns the hash itself. When passed a single argument, it returns the value
864stored in the args hash for that option key. When called with two arguments,
865the second argument is assigned to the args hash under the key passed as the
866first argument.
867
868=item autosplit_file($from, $to)
869
a314697d 870[version 0.28]
871
bb4e9162 872Invokes the C<AutoSplit> module on the C<$from> file, sending the
873output to the C<lib/auto> directory inside C<$to>. C<$to> is
874typically the C<blib/> directory.
875
876=item base_dir()
877
a314697d 878[version 0.14]
879
bb4e9162 880Returns a string containing the root-level directory of this build,
881i.e. where the C<Build.PL> script and the C<lib> directory can be
882found. This is usually the same as the current working directory,
883because the C<Build> script will C<chdir()> into this directory as
884soon as it begins execution.
885
886=item build_requires()
887
a314697d 888[version 0.21]
889
bb4e9162 890Returns a hash reference indicating the C<build_requires>
891prerequisites that were passed to the C<new()> method.
892
893=item check_installed_status($module, $version)
894
a314697d 895[version 0.11]
896
bb4e9162 897This method returns a hash reference indicating whether a version
898dependency on a certain module is satisfied. The C<$module> argument
899is given as a string like C<"Data::Dumper"> or C<"perl">, and the
900C<$version> argument can take any of the forms described in L<requires>
901above. This allows very fine-grained version checking.
902
903The returned hash reference has the following structure:
904
905 {
906 ok => $whether_the_dependency_is_satisfied,
907 have => $version_already_installed,
908 need => $version_requested, # Same as incoming $version argument
909 message => $informative_error_message,
910 }
911
912If no version of C<$module> is currently installed, the C<have> value
913will be the string C<< "<none>" >>. Otherwise the C<have> value will
914simply be the version of the installed module. Note that this means
915that if C<$module> is installed but doesn't define a version number,
916the C<have> value will be C<undef> - this is why we don't use C<undef>
917for the case when C<$module> isn't installed at all.
918
919This method may be called either as an object method
920(C<< $build->check_installed_status($module, $version) >>)
921or as a class method
922(C<< Module::Build->check_installed_status($module, $version) >>).
923
924=item check_installed_version($module, $version)
925
a314697d 926[version 0.05]
927
bb4e9162 928Like C<check_installed_status()>, but simply returns true or false
929depending on whether module C<$module> satisfies the dependency
930C<$version>.
931
932If the check succeeds, the return value is the actual version of
933C<$module> installed on the system. This allows you to do the
934following:
935
936 my $installed = $build->check_installed_version('DBI', '1.15');
937 if ($installed) {
938 print "Congratulations, version $installed of DBI is installed.\n";
939 } else {
940 die "Sorry, you must install DBI.\n";
941 }
942
943If the check fails, we return false and set C<$@> to an informative
944error message.
945
946If C<$version> is any non-true value (notably zero) and any version of
947C<$module> is installed, we return true. In this case, if C<$module>
948doesn't define a version, or if its version is zero, we return the
949special value "0 but true", which is numerically zero, but logically
950true.
951
952In general you might prefer to use C<check_installed_status> if you
953need detailed information, or this method if you just need a yes/no
954answer.
955
956=item compare_versions($v1, $op, $v2)
957
a314697d 958[version 0.28]
959
bb4e9162 960Compares two module versions C<$v1> and C<$v2> using the operator
961C<$op>, which should be one of Perl's numeric operators like C<!=> or
962C<< >= >> or the like. We do at least a halfway-decent job of
963handling versions that aren't strictly numeric, like C<0.27_02>, but
964exotic stuff will likely cause problems.
965
966In the future, the guts of this method might be replaced with a call
967out to C<version.pm>.
968
969=item config()
970
a314697d 971[version 0.22]
972
bb4e9162 973Returns a hash reference containing the C<Config.pm> hash, including
974any changes the author or user has specified. This is a reference to
975the actual internal hash we use, so you probably shouldn't modify
976stuff there.
977
978=item config_data($name)
979
980=item config_data($name => $value)
981
a314697d 982[version 0.26]
983
bb4e9162 984With a single argument, returns the value of the configuration
985variable C<$name>. With two arguments, sets the given configuration
986variable to the given value. The value may be any perl scalar that's
987serializable with C<Data::Dumper>. For instance, if you write a
988module that can use a MySQL or PostgreSQL back-end, you might create
989configuration variables called C<mysql_connect> and
990C<postgres_connect>, and set each to an array of connection parameters
991for C<< DBI->connect() >>.
992
993Configuration values set in this way using the Module::Build object
994will be available for querying during the build/test process and after
995installation via the generated C<...::ConfigData> module, as
996C<< ...::ConfigData->config($name) >>.
997
998The C<feature()> and C<config_data()> methods represent
999Module::Build's main support for configuration of installed modules.
1000See also L<SAVING CONFIGURATION INFORMATION>.
1001
1002=item conflicts()
1003
a314697d 1004[version 0.21]
1005
bb4e9162 1006Returns a hash reference indicating the C<conflicts> prerequisites
1007that were passed to the C<new()> method.
1008
1009=item contains_pod($file)
1010
a314697d 1011[version 0.20]
1012
bb4e9162 1013[Deprecated] Please see L<Module::Build::ModuleInfo> instead.
1014
1015Returns true if the given file appears to contain POD documentation.
1016Currently this checks whether the file has a line beginning with
1017'=pod', '=head', or '=item', but the exact semantics may change in the
1018future.
1019
1020=item copy_if_modified(%parameters)
1021
a314697d 1022[version 0.19]
1023
bb4e9162 1024Takes the file in the C<from> parameter and copies it to the file in
1025the C<to> parameter, or the directory in the C<to_dir> parameter, if
1026the file has changed since it was last copied (or if it doesn't exist
1027in the new location). By default the entire directory structure of
1028C<from> will be copied into C<to_dir>; an optional C<flatten>
1029parameter will copy into C<to_dir> without doing so.
1030
1031Returns the path to the destination file, or C<undef> if nothing
1032needed to be copied.
1033
1034Any directories that need to be created in order to perform the
1035copying will be automatically created.
1036
1037=item create_build_script()
1038
a314697d 1039[version 0.05]
1040
bb4e9162 1041Creates an executable script called C<Build> in the current directory
1042that will be used to execute further user actions. This script is
1043roughly analogous (in function, not in form) to the Makefile created
1044by C<ExtUtils::MakeMaker>. This method also creates some temporary
1045data in a directory called C<_build/>. Both of these will be removed
1046when the C<realclean> action is performed.
1047
1048=item current_action()
1049
a314697d 1050[version 0.28]
1051
bb4e9162 1052Returns the name of the currently-running action, such as "build" or
1053"test". This action is not necessarily the action that was originally
1054invoked by the user. For example, if the user invoked the "test"
1055action, current_action() would initially return "test". However,
1056action "test" depends on action "code", so current_action() will
1057return "code" while that dependency is being executed. Once that
1058action has completed, current_action() will again return "test".
1059
1060If you need to know the name of the original action invoked by the
1061user, see L<invoked_action()> below.
1062
1063=item depends_on(@actions)
1064
a314697d 1065[version 0.28]
1066
bb4e9162 1067Invokes the named action or list of actions in sequence. Using this
1068method is preferred to calling the action explicitly because it
1069performs some internal record-keeping, and it ensures that the same
1070action is not invoked multiple times (note: in future versions of
1071Module::Build it's conceivable that this run-only-once mechanism will
1072be changed to something more intelligent).
1073
1074Note that the name of this method is something of a misnomer; it
1075should really be called something like
1076C<invoke_actions_unless_already_invoked()> or something, but for
1077better or worse (perhaps better!) we were still thinking in
1078C<make>-like dependency terms when we created this method.
1079
1080See also C<dispatch()>. The main distinction between the two is that
1081C<depends_on()> is meant to call an action from inside another action,
1082whereas C<dispatch()> is meant to set the very top action in motion.
1083
1084=item dir_contains($first_dir, $second_dir)
1085
a314697d 1086[version 0.28]
1087
bb4e9162 1088Returns true if the first directory logically contains the second
1089directory. This is just a convenience function because C<File::Spec>
1090doesn't really provide an easy way to figure this out (but
1091C<Path::Class> does...).
1092
1093=item dispatch($action, %args)
1094
a314697d 1095[version 0.03]
1096
bb4e9162 1097Invokes the build action C<$action>. Optionally, a list of options
1098and their values can be passed in. This is equivalent to invoking an
1099action at the command line, passing in a list of options.
1100
1101Custom options that have not been registered must be passed in as a
1102hash reference in a key named "args":
1103
1104 $build->dispatch('foo', verbose => 1, args => { my_option => 'value' });
1105
1106This method is intended to be used to programmatically invoke build
1107actions, e.g. by applications controlling Module::Build-based builds
1108rather than by subclasses.
1109
1110See also C<depends_on()>. The main distinction between the two is that
1111C<depends_on()> is meant to call an action from inside another action,
1112whereas C<dispatch()> is meant to set the very top action in motion.
1113
1114=item dist_dir()
1115
a314697d 1116[version 0.28]
1117
bb4e9162 1118Returns the name of the directory that will be created during the
1119C<dist> action. The name is derived from the C<dist_name> and
1120C<dist_version> properties.
1121
1122=item dist_name()
1123
a314697d 1124[version 0.21]
1125
bb4e9162 1126Returns the name of the current distribution, as passed to the
1127C<new()> method in a C<dist_name> or modified C<module_name>
1128parameter.
1129
1130=item dist_version()
1131
a314697d 1132[version 0.21]
1133
bb4e9162 1134Returns the version of the current distribution, as determined by the
1135C<new()> method from a C<dist_version>, C<dist_version_from>, or
1136C<module_name> parameter.
1137
1138=item do_system($cmd, @args)
1139
a314697d 1140[version 0.21]
1141
bb4e9162 1142This is a fairly simple wrapper around Perl's C<system()> built-in
1143command. Given a command and an array of optional arguments, this
1144method will print the command to C<STDOUT>, and then execute it using
1145Perl's C<system()>. It returns true or false to indicate success or
1146failure (the opposite of how C<system()> works, but more intuitive).
1147
1148Note that if you supply a single argument to C<do_system()>, it
1149will/may be processed by the systems's shell, and any special
1150characters will do their special things. If you supply multiple
1151arguments, no shell will get involved and the command will be executed
1152directly.
1153
1154=item feature($name)
1155
1156=item feature($name => $value)
1157
a314697d 1158[version 0.26]
1159
bb4e9162 1160With a single argument, returns true if the given feature is set.
1161With two arguments, sets the given feature to the given boolean value.
1162In this context, a "feature" is any optional functionality of an
1163installed module. For instance, if you write a module that could
1164optionally support a MySQL or PostgreSQL backend, you might create
1165features called C<mysql_support> and C<postgres_support>, and set them
1166to true/false depending on whether the user has the proper databases
1167installed and configured.
1168
1169Features set in this way using the Module::Build object will be
1170available for querying during the build/test process and after
1171installation via the generated C<...::ConfigData> module, as
1172C<< ...::ConfigData->feature($name) >>.
1173
1174The C<feature()> and C<config_data()> methods represent
1175Module::Build's main support for configuration of installed modules.
1176See also L<SAVING CONFIGURATION INFORMATION>.
1177
1178=item have_c_compiler()
1179
a314697d 1180[version 0.21]
1181
bb4e9162 1182Returns true if the current system seems to have a working C compiler.
1183We currently determine this by attempting to compile a simple C source
1184file and reporting whether the attempt was successful.
1185
1186=item install_destination($type)
1187
a314697d 1188[version 0.28]
1189
bb4e9162 1190Returns the directory in which items of type C<$type> (e.g. C<lib>,
1191C<arch>, C<bin>, or anything else returned by the C<install_types()>
1192method) will be installed during the C<install> action. Any settings
1193for C<install_path>, C<install_base>, and C<prefix> are taken into
1194account when determining the return value.
1195
a314697d 1196=item install_path()
1197
1198=item install_path($type)
1199
1200=item install_path($type => $path)
1201
1202[version 0.28]
1203
1204Set or retrieve paths for specific installable elements. This is
1205useful when you want to examine any explicit install paths specified
1206by the user on the command line, or if you want to set the install
1207path for a specific installable element based on another attribute
1208like C<install_base()>.
1209
1210With no argument, it returns a reference to a hash containing all
1211elements and their respective values. This hash should not be modified
1212directly; use the multi-argument below form to change values.
1213
1214The single argument form returns the value associated with the
1215element C<$type>.
1216
1217The multi-argument form allows you to set the paths for one or more
1218element types. The return value is undefined.
1219
bb4e9162 1220=item install_types()
1221
a314697d 1222[version 0.28]
1223
bb4e9162 1224Returns a list of installable types that this build knows about.
1225These types each correspond to the name of a directory in F<blib/>,
1226and the list usually includes items such as C<lib>, C<arch>, C<bin>,
1227C<script>, C<libdoc>, C<bindoc>, and if HTML documentation is to be
1228built, C<libhtml> and C<binhtml>. Other user-defined types may also
1229exist.
1230
1231=item invoked_action()
1232
a314697d 1233[version 0.28]
1234
bb4e9162 1235This is the name of the original action invoked by the user. This
1236value is set when the user invokes F<Build.PL>, the F<Build> script,
1237or programatically through the L<dispatch()> method. It does not
1238change as sub-actions are executed as dependencies are evaluated.
1239
1240To get the name of the currently executing dependency, see
1241L<current_action()> above.
1242
1243=item notes()
1244
1245=item notes($key)
1246
1247=item notes($key => $value)
1248
a314697d 1249[version 0.20]
1250
bb4e9162 1251The C<notes()> value allows you to store your own persistent
1252information about the build, and to share that information among
1253different entities involved in the build. See the example in the
1254C<current()> method.
1255
1256The C<notes()> method is essentally a glorified hash access. With no
1257arguments, C<notes()> returns the entire hash of notes. With one argument,
1258C<notes($key)> returns the value associated with the given key. With two
1259arguments, C<notes($key, $value)> sets the value associated with the given key
1260to C<$value> and returns the new value.
1261
1262The lifetime of the C<notes> data is for "a build" - that is, the
1263C<notes> hash is created when C<perl Build.PL> is run (or when the
1264C<new()> method is run, if the Module::Build Perl API is being used
1265instead of called from a shell), and lasts until C<perl Build.PL> is
1266run again or the C<clean> action is run.
1267
1268=item orig_dir()
1269
a314697d 1270[version 0.28]
1271
bb4e9162 1272Returns a string containing the working directory that was in effect
1273before the F<Build> script chdir()-ed into the C<base_dir>. This
1274might be useful for writing wrapper tools that might need to chdir()
1275back out.
1276
bb4e9162 1277=item os_type()
1278
a314697d 1279[version 0.04]
1280
bb4e9162 1281If you're subclassing Module::Build and some code needs to alter its
1282behavior based on the current platform, you may only need to know
1283whether you're running on Windows, Unix, MacOS, VMS, etc., and not the
1284fine-grained value of Perl's C<$^O> variable. The C<os_type()> method
1285will return a string like C<Windows>, C<Unix>, C<MacOS>, C<VMS>, or
1286whatever is appropriate. If you're running on an unknown platform, it
1287will return C<undef> - there shouldn't be many unknown platforms
1288though.
1289
1290=item prepare_metadata()
1291
a314697d 1292[version 0.28]
1293
bb4e9162 1294This method is provided for authors to override to customize the
1295fields of F<META.yml>. It is passed a YAML::Node node object which can
1296be modified as desired and then returned. E.g.
1297
1298 package My::Builder;
1299 use base 'Module::Build';
1300
1301 sub prepare_metadata {
1302 my $self = shift;
1303 my $node = $self->SUPER::prepare_metadata( shift );
1304 $node->{custom_field} = 'foo';
1305 return $node;
1306 }
1307
1308=item prereq_failures()
1309
a314697d 1310[version 0.11]
1311
bb4e9162 1312Returns a data structure containing information about any failed
1313prerequisites (of any of the types described above), or C<undef> if
1314all prerequisites are met.
1315
1316The data structure returned is a hash reference. The top level keys
1317are the type of prerequisite failed, one of "requires",
1318"build_requires", "conflicts", or "recommends". The associated values
1319are hash references whose keys are the names of required (or
1320conflicting) modules. The associated values of those are hash
1321references indicating some information about the failure. For example:
1322
1323 {
1324 have => '0.42',
1325 need => '0.59',
1326 message => 'Version 0.42 is installed, but we need version 0.59',
1327 }
1328
1329or
1330
1331 {
1332 have => '<none>',
1333 need => '0.59',
1334 message => 'Prerequisite Foo isn't installed',
1335 }
1336
1337This hash has the same structure as the hash returned by the
1338C<check_installed_status()> method, except that in the case of
1339"conflicts" dependencies we change the "need" key to "conflicts" and
1340construct a proper message.
1341
1342Examples:
1343
1344 # Check a required dependency on Foo::Bar
1345 if ( $build->prereq_failures->{requires}{Foo::Bar} ) { ...
1346
1347 # Check whether there were any failures
1348 if ( $build->prereq_failures ) { ...
1349
1350 # Show messages for all failures
1351 my $failures = $build->prereq_failures;
1352 while (my ($type, $list) = each %$failures) {
1353 while (my ($name, $hash) = each %$list) {
1354 print "Failure for $name: $hash->{message}\n";
1355 }
1356 }
1357
1358=item prereq_report()
1359
a314697d 1360[version 0.28]
1361
bb4e9162 1362Returns a human-readable (table-form) string showing all
1363prerequisites, the versions required, and the versions actually
1364installed. This can be useful for reviewing the configuration of your
1365system prior to a build, or when compiling data to send for a bug
1366report. The C<prereq_report> action is just a thin wrapper around the
1367C<prereq_report()> method.
1368
1369=item prompt($message, $default)
1370
a314697d 1371[version 0.12]
1372
bb4e9162 1373Asks the user a question and returns their response as a string. The
1374first argument specifies the message to display to the user (for
1375example, C<"Where do you keep your money?">). The second argument,
1376which is optional, specifies a default answer (for example,
1377C<"wallet">). The user will be asked the question once.
1378
1379If C<prompt()> detects that it is not running interactively and there
1380is nothing on STDIN or if the PERL_MM_USE_DEFAULT environment variable
1381is set to true, the $default will be used without prompting. This
1382prevents automated processes from blocking on user input.
1383
1384If no $default is provided an empty string will be used instead.
1385
1386This method may be called as a class or object method.
1387
1388=item recommends()
1389
a314697d 1390[version 0.21]
1391
bb4e9162 1392Returns a hash reference indicating the C<recommends> prerequisites
1393that were passed to the C<new()> method.
1394
1395=item requires()
1396
a314697d 1397[version 0.21]
1398
bb4e9162 1399Returns a hash reference indicating the C<requires> prerequisites that
1400were passed to the C<new()> method.
1401
a314697d 1402=item rscan_dir($dir, $pattern)
1403
1404[version 0.28]
1405
1406Uses C<File::Find> to traverse the directory C<$dir>, returning a
1407reference to an array of entries matching C<$pattern>. C<$pattern>
1408may either be a regular expression (using C<qr//> or just a plain
1409string), or a reference to a subroutine that will return true for
1410wanted entries. If C<$pattern> is not given, all entries will be
1411returned.
1412
1413Examples:
1414
1415 # All the *.pm files in lib/
1416 $m->rscan_dir('lib', qr/\.pm$/)
1417
1418 # All the files in blib/ that aren't *.html files
1419 $m->rscan_dir('blib', sub {-f $_ and not /\.html$/});
1420
1421 # All the files in t/
1422 $m->rscan_dir('t');
1423
1424=item runtime_params()
1425
1426=item runtime_params($key)
1427
1428[version 0.28]
1429
1430The C<runtime_params()> method stores the values passed on the command line
1431for valid properties (that is, any command line options for which
1432C<valid_property()> returns a true value). The value on the command line may
1433override the default value for a property, as well as any value specified in a
1434call to C<new()>. This allows you to programmatically tell if C<perl Build.PL>
1435or any execution of C<./Build> had command line options specified that
1436override valid properties.
1437
1438The C<runtime_params()> method is essentally a glorified read-only hash. With
1439no arguments, C<runtime_params()> returns the entire hash of properties
1440specified on the command line. With one argument, C<runtime_params($key)>
1441returns the value associated with the given key.
1442
1443The lifetime of the C<runtime_params> data is for "a build" - that is, the
1444C<runtime_params> hash is created when C<perl Build.PL> is run (or when the
1445C<new()> method is called, if the Module::Build Perl API is being used instead
1446of called from a shell), and lasts until C<perl Build.PL> is run again or the
1447C<clean> action is run.
1448
bb4e9162 1449=item script_files()
1450
a314697d 1451[version 0.18]
1452
bb4e9162 1453Returns a hash reference whose keys are the perl script files to be
1454installed, if any. This corresponds to the C<script_files> parameter to the
1455C<new()> method. With an optional argument, this parameter may be set
1456dynamically.
1457
1458For backward compatibility, the C<scripts()> method does exactly the
1459same thing as C<script_files()>. C<scripts()> is deprecated, but it
1460will stay around for several versions to give people time to
1461transition.
1462
1463=item up_to_date($source_file, $derived_file)
1464
1465=item up_to_date(\@source_files, \@derived_files)
1466
a314697d 1467[version 0.20]
1468
bb4e9162 1469This method can be used to compare a set of source files to a set of
1470derived files. If any of the source files are newer than any of the
1471derived files, it returns false. Additionally, if any of the derived
1472files do not exist, it returns false. Otherwise it returns true.
1473
1474The arguments may be either a scalar or an array reference of file
1475names.
1476
1477=item y_n($message, $default)
1478
a314697d 1479[version 0.12]
1480
bb4e9162 1481Asks the user a yes/no question using C<prompt()> and returns true or
1482false accordingly. The user will be asked the question repeatedly
1483until they give an answer that looks like "yes" or "no".
1484
1485The first argument specifies the message to display to the user (for
1486example, C<"Shall I invest your money for you?">), and the second
1487argument specifies the default answer (for example, C<"y">).
1488
1489Note that the default is specified as a string like C<"y"> or C<"n">,
1490and the return value is a Perl boolean value like 1 or 0. I thought
1491about this for a while and this seemed like the most useful way to do
1492it.
1493
1494This method may be called as a class or object method.
1495
1496=back
1497
1498
1499=head2 Autogenerated Accessors
1500
1501In addition to the aforementioned methods, there are also some get/set
1502accessor methods for the following properties:
1503
1504=over 4
1505
1506=item PL_files()
1507
1508=item autosplit()
1509
1510=item base_dir()
1511
1512=item bindoc_dirs()
1513
1514=item blib()
1515
1516=item build_bat()
1517
1518=item build_class()
1519
1520=item build_elements()
1521
1522=item build_requires()
1523
1524=item build_script()
1525
1526=item c_source()
1527
1528=item config()
1529
1530=item config_dir()
1531
1532=item conflicts()
1533
1534=item create_makefile_pl()
1535
a314697d 1536=item create_packlist()
1537
bb4e9162 1538=item create_readme()
1539
1540=item debugger()
1541
1542=item destdir()
1543
bb4e9162 1544=item get_options()
1545
1546=item html_css()
1547
1548=item include_dirs()
1549
1550=item install_base()
1551
1552=item install_path()
1553
1554=item install_sets()
1555
1556=item installdirs()
1557
1558=item libdoc_dirs()
1559
1560=item license()
1561
1562=item magic_number()
1563
1564=item mb_version()
1565
1566=item meta_add()
1567
1568=item meta_merge()
1569
1570=item metafile()
1571
1572=item module_name()
1573
1574=item orig_dir()
1575
1576=item original_prefix()
1577
1578=item perl()
1579
1580=item pm_files()
1581
1582=item pod_files()
1583
1584=item pollute()
1585
1586=item prefix()
1587
1588=item prereq_action_types()
1589
1590=item quiet()
1591
1592=item recommends()
1593
1594=item recurse_into()
1595
1596=item recursive_test_files()
1597
1598=item requires()
1599
1600=item scripts()
1601
1602=item use_rcfile()
1603
1604=item verbose()
1605
1606=item xs_files()
1607
1608=back
1609
1610
1611=head1 PREREQUISITES
1612
1613There are three basic types of prerequisites that can be defined: 1)
1614"requires" - are versions of modules that are required for certain
1615functionality to be available; 2) "recommends" - are versions of
1616modules that are recommended to provide enhanced functionality; and 3)
1617"conflicts" - are versions of modules that conflict with, and that can
1618cause problems with the distribution.
1619
1620Each of the three types of prerequisites listed above can be applied
1621to different aspects of the Build process. For the module distribution
1622itself you simply define "requires", "recommends", or "conflicts". The
1623types can also apply to other aspects of the Build process. Currently,
1624only "build_requires" is defined which is used for modules which are
1625required during the Build process.
1626
1627
1628=head2 Format of prerequisites
1629
1630The prerequisites are given in a hash reference, where the keys are
1631the module names and the values are version specifiers:
1632
1633 requires => {
1634 Foo::Module => '2.4',
1635 Bar::Module => 0,
1636 Ken::Module => '>= 1.2, != 1.5, < 2.0',
1637 perl => '5.6.0'
1638 },
1639
1640These four version specifiers have different effects. The value
1641C<'2.4'> means that B<at least> version 2.4 of C<Foo::Module> must be
1642installed. The value C<0> means that B<any> version of C<Bar::Module>
1643is acceptable, even if C<Bar::Module> doesn't define a version. The
1644more verbose value C<'E<gt>= 1.2, != 1.5, E<lt> 2.0'> means that
1645C<Ken::Module>'s version must be B<at least> 1.2, B<less than> 2.0,
1646and B<not equal to> 1.5. The list of criteria is separated by commas,
1647and all criteria must be satisfied.
1648
1649A special C<perl> entry lets you specify the versions of the Perl
1650interpreter that are supported by your module. The same version
1651dependency-checking semantics are available, except that we also
1652understand perl's new double-dotted version numbers.
1653
1654
1655=head1 SAVING CONFIGURATION INFORMATION
1656
1657Module::Build provides a very convenient way to save configuration
1658information that your installed modules (or your regression tests) can
1659access. If your Build process calls the C<feature()> or
1660C<config_data()> methods, then a C<Foo::Bar::ConfigData> module will
1661automatically be created for you, where C<Foo::Bar> is the
1662C<module_name> parameter as passed to C<new()>. This module provides
1663access to the data saved by these methods, and a way to update the
1664values. There is also a utility script called C<config_data>
1665distributed with Module::Build that provides a command line interface
1666to this same functionality. See also the generated
1667C<Foo::Bar::ConfigData> documentation, and the C<config_data>
1668script's documentation, for more information.
1669
1670
1671=head1 AUTOMATION
1672
1673One advantage of Module::Build is that since it's implemented as Perl
1674methods, you can invoke these methods directly if you want to install
1675a module non-interactively. For instance, the following Perl script
1676will invoke the entire build/install procedure:
1677
1678 my $build = Module::Build->new(module_name => 'MyModule');
1679 $build->dispatch('build');
1680 $build->dispatch('test');
1681 $build->dispatch('install');
1682
1683If any of these steps encounters an error, it will throw a fatal
1684exception.
1685
1686You can also pass arguments as part of the build process:
1687
1688 my $build = Module::Build->new(module_name => 'MyModule');
1689 $build->dispatch('build');
1690 $build->dispatch('test', verbose => 1);
1691 $build->dispatch('install', sitelib => '/my/secret/place/');
1692
1693Building and installing modules in this way skips creating the
1694C<Build> script.
1695
1696
1697=head1 STRUCTURE
1698
1699Module::Build creates a class hierarchy conducive to customization.
1700Here is the parent-child class hierarchy in classy ASCII art:
1701
1702 /--------------------\
1703 | Your::Parent | (If you subclass Module::Build)
1704 \--------------------/
1705 |
1706 |
1707 /--------------------\ (Doesn't define any functionality
1708 | Module::Build | of its own - just figures out what
1709 \--------------------/ other modules to load.)
1710 |
1711 |
1712 /-----------------------------------\ (Some values of $^O may
1713 | Module::Build::Platform::$^O | define specialized functionality.
1714 \-----------------------------------/ Otherwise it's ...::Default, a
1715 | pass-through class.)
1716 |
1717 /--------------------------\
1718 | Module::Build::Base | (Most of the functionality of
1719 \--------------------------/ Module::Build is defined here.)
1720
1721
1722=head1 SUBCLASSING
1723
1724Right now, there are two ways to subclass Module::Build. The first
1725way is to create a regular module (in a C<.pm> file) that inherits
1726from Module::Build, and use that module's class instead of using
1727Module::Build directly:
1728
1729 ------ in Build.PL: ----------
1730 #!/usr/bin/perl
1731
1732 use lib q(/nonstandard/library/path);
1733 use My::Builder; # Or whatever you want to call it
1734
1735 my $build = My::Builder->new
1736 (
1737 module_name => 'Foo::Bar', # All the regular args...
1738 license => 'perl',
1739 dist_author => 'A N Other <me@here.net.au>',
1740 requires => { Carp => 0 }
1741 );
1742 $build->create_build_script;
1743
1744This is relatively straightforward, and is the best way to do things
1745if your My::Builder class contains lots of code. The
1746C<create_build_script()> method will ensure that the current value of
1747C<@INC> (including the C</nonstandard/library/path>) is propogated to
1748the Build script, so that My::Builder can be found when running build
1749actions.
1750
1751For very small additions, Module::Build provides a C<subclass()>
1752method that lets you subclass Module::Build more conveniently, without
1753creating a separate file for your module:
1754
1755 ------ in Build.PL: ----------
1756 #!/usr/bin/perl
1757
1758 use Module::Build;
1759 my $class = Module::Build->subclass
1760 (
1761 class => 'My::Builder',
1762 code => q{
1763 sub ACTION_foo {
1764 print "I'm fooing to death!\n";
1765 }
1766 },
1767 );
1768
1769 my $build = $class->new
1770 (
1771 module_name => 'Foo::Bar', # All the regular args...
1772 license => 'perl',
1773 dist_author => 'A N Other <me@here.net.au>',
1774 requires => { Carp => 0 }
1775 );
1776 $build->create_build_script;
1777
1778Behind the scenes, this actually does create a C<.pm> file, since the
1779code you provide must persist after Build.PL is run if it is to be
1780very useful.
1781
1782See also the documentation for the C<subclass()> method.
1783
1784
1785=head1 STARTING MODULE DEVELOPMENT
1786
1787When starting development on a new module, it's rarely worth your time
1788to create a tree of all the files by hand. Some automatic
1789module-creators are available: the oldest is C<h2xs>, which has
1790shipped with perl itself for a long time. Its name reflects the fact
1791that modules were originally conceived of as a way to wrap up a C
1792library (thus the C<h> part) into perl extensions (thus the C<xs>
1793part).
1794
1795These days, C<h2xs> has largely been superseded by modules like
1796C<ExtUtils::ModuleMaker>, C<Module::Starter>, and C<Module::Maker>.
1797They have varying degrees of support for C<Module::Build>.
1798
1799
1800=head1 MIGRATION
1801
1802Note that if you want to provide both a F<Makefile.PL> and a
1803F<Build.PL> for your distribution, you probably want to add the
1804following to C<WriteMakefile> in your F<Makefile.PL> so that MakeMaker
1805doesn't try to run your F<Build.PL> as a normal F<.PL> file:
1806
1807 PL_FILES => {},
1808
1809You may also be interested in looking at the C<Module::Build::Compat>
1810module, which can automatically create various kinds of F<Makefile.PL>
1811compatibility layers.
1812
1813
1814=head1 AUTHOR
1815
1816Ken Williams, kwilliams@cpan.org
1817
1818Development questions, bug reports, and patches should be sent to the
1819Module-Build mailing list at module-build-general@lists.sourceforge.net .
1820
1821Bug reports are also welcome at
1822http://rt.cpan.org/NoAuth/Bugs.html?Dist=Module-Build .
1823
1824An anonymous CVS repository containing the latest development version
1825is available; see http://sourceforge.net/cvs/?group_id=45731 for the
1826details of how to access it.
1827
1828
1829=head1 SEE ALSO
1830
1831perl(1), Module::Build(3), Module::Build::Cookbook(3),
1832ExtUtils::MakeMaker(3), YAML(3)
1833
1834F<META.yml> Specification:
1835L<http://module-build.sourceforge.net/META-spec-v1.2.html>
1836
1837L<http://www.dsmit.com/cons/>
1838
1839=cut