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