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