Update CPANPLUS::Dist::Build to cpan version 0.42
[p5sagit/p5-mst-13.2.git] / cpan / CPANPLUS-Dist-Build / lib / CPANPLUS / Dist / Build.pm
CommitLineData
9b4bd854 1package CPANPLUS::Dist::Build;
2
3use strict;
e83ba0bd 4use warnings;
9b4bd854 5use vars qw[@ISA $STATUS $VERSION];
6@ISA = qw[CPANPLUS::Dist];
7
9b4bd854 8use CPANPLUS::Internals::Constants;
9
10### these constants were exported by CPANPLUS::Internals::Constants
11### in previous versions.. they do the same though. If we want to have
12### a normal 'use' here, up the dependency to CPANPLUS 0.056 or higher
13BEGIN {
14 require CPANPLUS::Dist::Build::Constants;
15 CPANPLUS::Dist::Build::Constants->import()
16 if not __PACKAGE__->can('BUILD') && __PACKAGE__->can('BUILD_DIR');
17}
18
19use CPANPLUS::Error;
20
21use Config;
22use FileHandle;
23use Cwd;
e83ba0bd 24use version;
9b4bd854 25
26use IPC::Cmd qw[run];
27use Params::Check qw[check];
28use Module::Load::Conditional qw[can_load check_install];
29use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext';
30
31local $Params::Check::VERBOSE = 1;
32
b65597cb 33$VERSION = '0.42';
9b4bd854 34
35=pod
36
37=head1 NAME
38
e83ba0bd 39CPANPLUS::Dist::Build - CPANPLUS plugin to install packages that use Build.PL
9b4bd854 40
41=head1 SYNOPSIS
42
43 my $build = CPANPLUS::Dist->new(
44 format => 'CPANPLUS::Dist::Build',
45 module => $modobj,
46 );
47
e83ba0bd 48 $build->prepare; # runs Build.PL
9b4bd854 49 $build->create; # runs build && build test
50 $build->install; # runs build install
51
52
53=head1 DESCRIPTION
54
55C<CPANPLUS::Dist::Build> is a distribution class for C<Module::Build>
56related modules.
57Using this package, you can create, install and uninstall perl
58modules. It inherits from C<CPANPLUS::Dist>.
59
60Normal users won't have to worry about the interface to this module,
61as it functions transparently as a plug-in to C<CPANPLUS> and will
62just C<Do The Right Thing> when it's loaded.
63
64=head1 ACCESSORS
65
66=over 4
67
e83ba0bd 68=item C<parent()>
9b4bd854 69
70Returns the C<CPANPLUS::Module> object that parented this object.
71
e83ba0bd 72=item C<status()>
9b4bd854 73
74Returns the C<Object::Accessor> object that keeps the status for
75this module.
76
77=back
78
79=head1 STATUS ACCESSORS
80
81All accessors can be accessed as follows:
82 $build->status->ACCESSOR
83
84=over 4
85
e83ba0bd 86=item C<build_pl ()>
9b4bd854 87
88Location of the Build file.
89Set to 0 explicitly if something went wrong.
90
e83ba0bd 91=item C<build ()>
9b4bd854 92
93BOOL indicating if the C<Build> command was successful.
94
e83ba0bd 95=item C<test ()>
9b4bd854 96
97BOOL indicating if the C<Build test> command was successful.
98
e83ba0bd 99=item C<prepared ()>
9b4bd854 100
101BOOL indicating if the C<prepare> call exited succesfully
102This gets set after C<perl Build.PL>
103
e83ba0bd 104=item C<distdir ()>
9b4bd854 105
106Full path to the directory in which the C<prepare> call took place,
107set after a call to C<prepare>.
108
e83ba0bd 109=item C<created ()>
9b4bd854 110
111BOOL indicating if the C<create> call exited succesfully. This gets
112set after C<Build> and C<Build test>.
113
e83ba0bd 114=item C<installed ()>
9b4bd854 115
116BOOL indicating if the module was installed. This gets set after
117C<Build install> exits successfully.
118
119=item uninstalled ()
120
121BOOL indicating if the module was uninstalled properly.
122
e83ba0bd 123=item C<_create_args ()>
9b4bd854 124
125Storage of the arguments passed to C<create> for this object. Used
126for recursive calls when satisfying prerequisites.
127
e83ba0bd 128=item C<_install_args ()>
9b4bd854 129
130Storage of the arguments passed to C<install> for this object. Used
131for recursive calls when satisfying prerequisites.
132
9b4bd854 133=back
134
135=cut
136
9b4bd854 137=head1 METHODS
138
139=head2 $bool = CPANPLUS::Dist::Build->format_available();
140
141Returns a boolean indicating whether or not you can use this package
142to create and install modules in your environment.
143
144=cut
145
146### check if the format is available ###
147sub format_available {
148 my $mod = "Module::Build";
149 unless( can_load( modules => { $mod => '0.2611' } ) ) {
150 error( loc( "You do not have '%1' -- '%2' not available",
151 $mod, __PACKAGE__ ) );
152 return;
153 }
154
155 return 1;
156}
157
158
159=head2 $bool = $dist->init();
160
161Sets up the C<CPANPLUS::Dist::Build> object for use.
162Effectively creates all the needed status accessors.
163
164Called automatically whenever you create a new C<CPANPLUS::Dist> object.
165
166=cut
167
168sub init {
169 my $dist = shift;
170 my $status = $dist->status;
171
172 $status->mk_accessors(qw[build_pl build test created installed uninstalled
173 _create_args _install_args _prepare_args
174 _mb_object _buildflags
175 ]);
176
177 ### just in case 'format_available' didn't get called
178 require Module::Build;
179
180 return 1;
181}
182
183=pod
184
185=head2 $bool = $dist->prepare([perl => '/path/to/perl', buildflags => 'EXTRA=FLAGS', force => BOOL, verbose => BOOL])
186
e83ba0bd 187C<prepare> prepares a distribution, running C<Build.PL>
188and establishing any prerequisites this
9b4bd854 189distribution has.
190
e83ba0bd 191The variable C<PERL5_CPANPLUS_IS_EXECUTING> will be set to the full path
9b4bd854 192of the C<Build.PL> that is being executed. This enables any code inside
193the C<Build.PL> to know that it is being installed via CPANPLUS.
194
195After a succcesfull C<prepare> you may call C<create> to create the
196distribution, followed by C<install> to actually install it.
197
198Returns true on success and false on failure.
199
200=cut
201
202sub prepare {
203 ### just in case you already did a create call for this module object
204 ### just via a different dist object
205 my $dist = shift;
206 my $self = $dist->parent;
207
208 ### we're also the cpan_dist, since we don't need to have anything
209 ### prepared from another installer
210 $dist = $self->status->dist_cpan if $self->status->dist_cpan;
211 $self->status->dist_cpan( $dist ) unless $self->status->dist_cpan;
212
213 my $cb = $self->parent;
214 my $conf = $cb->configure_object;
215 my %hash = @_;
216
217 my $dir;
218 unless( $dir = $self->status->extract ) {
219 error( loc( "No dir found to operate on!" ) );
220 return;
221 }
222
223 my $args;
701602e6 224 my( $force, $verbose, $buildflags, $perl, $prereq_target, $prereq_format,
225 $prereq_build );
9b4bd854 226 { local $Params::Check::ALLOW_UNKNOWN = 1;
227 my $tmpl = {
228 force => { default => $conf->get_conf('force'),
229 store => \$force },
230 verbose => { default => $conf->get_conf('verbose'),
231 store => \$verbose },
232 perl => { default => $^X, store => \$perl },
233 buildflags => { default => $conf->get_conf('buildflags'),
234 store => \$buildflags },
701602e6 235 prereq_target => { default => '', store => \$prereq_target },
236 prereq_format => { default => '',
237 store => \$prereq_format },
238 prereq_build => { default => 0, store => \$prereq_build },
9b4bd854 239 };
240
241 $args = check( $tmpl, \%hash ) or return;
242 }
243
244 return 1 if $dist->status->prepared && !$force;
245
246 $dist->status->_prepare_args( $args );
247
248 ### chdir to work directory ###
249 my $orig = cwd();
250 unless( $cb->_chdir( dir => $dir ) ) {
251 error( loc( "Could not chdir to build directory '%1'", $dir ) );
252 return;
253 }
254
255 ### by now we've loaded module::build, and we're using the API, so
256 ### it's safe to remove CPANPLUS::inc from our inc path, especially
257 ### because it can trip up tests run under taint (just like EU::MM).
258 ### turn off our PERL5OPT so no modules from CPANPLUS::inc get
259 ### included in make test -- it should build without.
260 ### also, modules that run in taint mode break if we leave
261 ### our code ref in perl5opt
262 ### XXX we've removed the ENV settings from cp::inc, so only need
263 ### to reset the @INC
264 #local $ENV{PERL5OPT} = CPANPLUS::inc->original_perl5opt;
265 #local $ENV{PERL5LIB} = CPANPLUS::inc->original_perl5lib;
39a48622 266 #local @INC = CPANPLUS::inc->original_inc;
9b4bd854 267
268 ### this will generate warnings under anything lower than M::B 0.2606
baddfc47 269 my @buildflags = $dist->_buildflags_as_list( $buildflags );
9b4bd854 270 $dist->status->_buildflags( $buildflags );
271
272 my $fail;
273 RUN: {
701602e6 274 # 0.85_01
275 ### we resolve 'configure requires' here, so we can run the 'perl
276 ### Makefile.PL' command
277 ### XXX for tests: mock f_c_r to something that *can* resolve and
278 ### something that *doesnt* resolve. Check the error log for ok
279 ### on this step or failure
280 ### XXX make a seperate tarball to test for this scenario: simply
281 ### containing a makefile.pl/build.pl for test purposes?
282 my $safe_ver = version->new('0.85_01');
283 if ( version->new($CPANPLUS::Internals::VERSION) >= $safe_ver )
284 { my $configure_requires = $dist->find_configure_requires;
285 my $ok = $dist->_resolve_prereqs(
286 format => $prereq_format,
287 verbose => $verbose,
288 prereqs => $configure_requires,
289 target => $prereq_target,
290 force => $force,
291 prereq_build => $prereq_build,
292 );
293
294 unless( $ok ) {
295
296 #### use $dist->flush to reset the cache ###
297 error( loc( "Unable to satisfy '%1' for '%2' " .
298 "-- aborting install",
299 'configure_requires', $self->module ) );
300 $dist->status->prepared(0);
301 $fail++;
302 last RUN;
303 }
304 ### end of prereq resolving ###
305 }
306
9b4bd854 307 # Wrap the exception that may be thrown here (should likely be
308 # done at a much higher level).
e83ba0bd 309 my $prep_output;
310
e42df61f 311 my $env = ENV_CPANPLUS_IS_EXECUTING;
e83ba0bd 312 local $ENV{$env} = BUILD_PL->( $dir );
e42df61f 313 my $run_perl = $conf->get_program('perlwrapper');
36392a5f 314 my $cmd = [$perl, $run_perl, BUILD_PL->($dir), @buildflags];
e83ba0bd 315
ef25d9aa 316 unless ( scalar run( command => $cmd,
e83ba0bd 317 buffer => \$prep_output,
318 verbose => $verbose )
319 ) {
320 error( loc( "Build.PL failed: %1", $prep_output ) );
9b4bd854 321 $fail++; last RUN;
322 }
323
e83ba0bd 324 msg( $prep_output, 0 );
9b4bd854 325
701602e6 326 my $prereqs = $self->status->prereqs;
327
328 $prereqs ||= $dist->_find_prereqs( verbose => $verbose,
329 dir => $dir,
330 perl => $perl,
331 buildflags => $buildflags );
9b4bd854 332
333 }
334
335 ### send out test report? ###
336 if( $fail and $conf->get_conf('cpantest') ) {
337 $cb->_send_report(
338 module => $self,
339 failed => $fail,
340 buffer => CPANPLUS::Error->stack_as_string,
341 verbose => $verbose,
342 force => $force,
343 ) or error(loc("Failed to send test report for '%1'",
344 $self->module ) );
345 }
346
347 unless( $cb->_chdir( dir => $orig ) ) {
348 error( loc( "Could not chdir back to start dir '%1'", $orig ) );
349 }
350
351 ### save where we wrote this stuff -- same as extract dir in normal
352 ### installer circumstances
353 $dist->status->distdir( $self->status->extract );
354
355 return $dist->status->prepared( $fail ? 0 : 1 );
356}
357
358sub _find_prereqs {
359 my $dist = shift;
9b4bd854 360 my $self = $dist->parent;
361 my $cb = $self->parent;
e83ba0bd 362 my $conf = $cb->configure_object;
363 my %hash = @_;
364
365 my ($verbose, $dir, $buildflags, $perl);
366 my $tmpl = {
367 verbose => { default => $conf->get_conf('verbose'), store => \$verbose },
368 dir => { default => $self->status->extract, store => \$dir },
369 perl => { default => $^X, store => \$perl },
370 buildflags => { default => $conf->get_conf('buildflags'),
371 store => \$buildflags },
372 };
373
374 my $args = check( $tmpl, \%hash ) or return;
9b4bd854 375
376 my $prereqs = {};
e83ba0bd 377
9b583d58 378 $prereqs = $dist->find_mymeta_requires()
379 if $dist->can('find_mymeta_requires');
e83ba0bd 380
9b583d58 381 if ( keys %$prereqs ) {
382 # Ugly hack
383 }
384 else {
385 my $safe_ver = version->new('0.31_03');
386 my $content;
387 if ( version->new( $Module::Build::VERSION ) >= $safe_ver and IPC::Cmd->can_capture_buffer ) {
388 my @buildflags = $dist->_buildflags_as_list( $buildflags );
baddfc47 389
9b583d58 390 # Use the new Build action 'prereq_data'
391 my $run_perl = $conf->get_program('perlwrapper');
e42df61f 392
9b583d58 393 unless ( scalar run( command => [$perl, $run_perl, BUILD->($dir), 'prereq_data', @buildflags],
e83ba0bd 394 buffer => \$content,
395 verbose => 0 )
9b583d58 396 ) {
e83ba0bd 397 error( loc( "Build 'prereq_data' failed: %1 %2", $!, $content ) );
398 return;
9b583d58 399 }
e83ba0bd 400
9b583d58 401 }
402 else {
403 my $file = File::Spec->catfile( $dir, '_build', 'prereqs' );
404 return unless -f $file;
e83ba0bd 405
9b583d58 406 my $fh = FileHandle->new();
e83ba0bd 407
9b583d58 408 unless( $fh->open( $file ) ) {
409 error( loc( "Cannot open '%1': %2", $file, $! ) );
410 return;
411 }
e83ba0bd 412
9b583d58 413 $content = do { local $/; <$fh> };
414 }
e83ba0bd 415
9b583d58 416 return unless $content;
417 my $bphash = eval $content;
418 return unless $bphash and ref $bphash eq 'HASH';
419 foreach my $type ('requires', 'build_requires') {
420 next unless $bphash->{$type} and ref $bphash->{$type} eq 'HASH';
421 $prereqs->{$_} = $bphash->{$type}->{$_} for keys %{ $bphash->{$type} };
422 }
9b4bd854 423 }
e83ba0bd 424 # Temporary fix
425 delete $prereqs->{'perl'};
426
9b4bd854 427 ### allows for a user defined callback to filter the prerequisite
428 ### list as they see fit, to remove (or add) any prereqs they see
429 ### fit. The default installed callback will return the hashref in
430 ### an unmodified form
431 ### this callback got added after cpanplus 0.0562, so use a 'can'
432 ### to find out if it's supported. For older versions, we'll just
433 ### return the hashref as is ourselves.
434 my $href = $cb->_callbacks->can('filter_prereqs')
435 ? $cb->_callbacks->filter_prereqs->( $cb, $prereqs )
436 : $prereqs;
437
438 $self->status->prereqs( $href );
439
440 ### make sure it's not the same ref
441 return { %$href };
442}
443
9b4bd854 444=pod
445
446=head2 $dist->create([perl => '/path/to/perl', buildflags => 'EXTRA=FLAGS', prereq_target => TARGET, force => BOOL, verbose => BOOL, skiptest => BOOL])
447
448C<create> preps a distribution for installation. This means it will
e83ba0bd 449run C<Build> and C<Build test>.
9b4bd854 450This will also satisfy any prerequisites the module may have.
451
452If you set C<skiptest> to true, it will skip the C<Build test> stage.
453If you set C<force> to true, it will go over all the stages of the
454C<Build> process again, ignoring any previously cached results. It
455will also ignore a bad return value from C<Build test> and still allow
456the operation to return true.
457
458Returns true on success and false on failure.
459
460You may then call C<< $dist->install >> on the object to actually
461install it.
462
463=cut
464
465sub create {
466 ### just in case you already did a create call for this module object
467 ### just via a different dist object
468 my $dist = shift;
469 my $self = $dist->parent;
470
471 ### we're also the cpan_dist, since we don't need to have anything
472 ### prepared from another installer
473 $dist = $self->status->dist_cpan if $self->status->dist_cpan;
474 $self->status->dist_cpan( $dist ) unless $self->status->dist_cpan;
475
476 my $cb = $self->parent;
477 my $conf = $cb->configure_object;
9b4bd854 478 my %hash = @_;
479
480 my $dir;
481 unless( $dir = $self->status->extract ) {
482 error( loc( "No dir found to operate on!" ) );
483 return;
484 }
485
486 my $args;
487 my( $force, $verbose, $buildflags, $skiptest, $prereq_target,
488 $perl, $prereq_format, $prereq_build);
489 { local $Params::Check::ALLOW_UNKNOWN = 1;
490 my $tmpl = {
491 force => { default => $conf->get_conf('force'),
492 store => \$force },
493 verbose => { default => $conf->get_conf('verbose'),
494 store => \$verbose },
495 perl => { default => $^X, store => \$perl },
496 buildflags => { default => $conf->get_conf('buildflags'),
497 store => \$buildflags },
498 skiptest => { default => $conf->get_conf('skiptest'),
499 store => \$skiptest },
500 prereq_target => { default => '', store => \$prereq_target },
501 ### don't set the default format to 'build' -- that is wrong!
502 prereq_format => { #default => $self->status->installer_type,
503 default => '',
504 store => \$prereq_format },
505 prereq_build => { default => 0, store => \$prereq_build },
506 };
507
508 $args = check( $tmpl, \%hash ) or return;
509 }
510
89b75a3b 511 # restore the state as we have created this already.
512 if ( $dist->status->created && !$force ) {
513 ### add this directory to your lib ###
514 $self->add_to_includepath();
515 return 1;
516 }
9b4bd854 517
518 $dist->status->_create_args( $args );
519
520 ### is this dist prepared?
521 unless( $dist->status->prepared ) {
522 error( loc( "You have not successfully prepared a '%2' distribution ".
523 "yet -- cannot create yet", __PACKAGE__ ) );
524 return;
525 }
526
527 ### chdir to work directory ###
528 my $orig = cwd();
529 unless( $cb->_chdir( dir => $dir ) ) {
530 error( loc( "Could not chdir to build directory '%1'", $dir ) );
531 return;
532 }
533
534 ### by now we've loaded module::build, and we're using the API, so
535 ### it's safe to remove CPANPLUS::inc from our inc path, especially
536 ### because it can trip up tests run under taint (just like EU::MM).
537 ### turn off our PERL5OPT so no modules from CPANPLUS::inc get
538 ### included in make test -- it should build without.
539 ### also, modules that run in taint mode break if we leave
540 ### our code ref in perl5opt
541 ### XXX we've removed the ENV settings from cp::inc, so only need
542 ### to reset the @INC
543 #local $ENV{PERL5OPT} = CPANPLUS::inc->original_perl5opt;
544 #local $ENV{PERL5LIB} = CPANPLUS::inc->original_perl5lib;
39a48622 545 #local @INC = CPANPLUS::inc->original_inc;
9b4bd854 546
547 ### but do it *before* the new_from_context, as M::B seems
548 ### to be actually running the file...
549 ### an unshift in the block seems to be ignored.. somehow...
550 #{ my $lib = $self->best_path_to_module_build;
551 # unshift @INC, $lib if $lib;
552 #}
553 unshift @INC, $self->best_path_to_module_build
554 if $self->best_path_to_module_build;
555
556 ### this will generate warnings under anything lower than M::B 0.2606
baddfc47 557 my @buildflags = $dist->_buildflags_as_list( $buildflags );
9b4bd854 558 $dist->status->_buildflags( $buildflags );
559
560 my $fail; my $prereq_fail; my $test_fail;
561 RUN: {
562
e42df61f 563 my $run_perl = $conf->get_program('perlwrapper');
564
9b4bd854 565 ### this will set the directory back to the start
566 ### dir, so we must chdir /again/
567 my $ok = $dist->_resolve_prereqs(
568 force => $force,
569 format => $prereq_format,
570 verbose => $verbose,
571 prereqs => $self->status->prereqs,
572 target => $prereq_target,
573 prereq_build => $prereq_build,
574 );
575
576 unless( $cb->_chdir( dir => $dir ) ) {
577 error( loc( "Could not chdir to build directory '%1'", $dir ) );
578 return;
579 }
580
581 unless( $ok ) {
582 #### use $dist->flush to reset the cache ###
583 error( loc( "Unable to satisfy prerequisites for '%1' " .
584 "-- aborting install", $self->module ) );
585 $dist->status->build(0);
586 $fail++; $prereq_fail++;
587 last RUN;
588 }
589
ef25d9aa 590 my ($captured, $cmd);
591 if ( ON_VMS ) {
592 $cmd = [$perl, BUILD->($dir), @buildflags];
593 }
594 else {
595 $cmd = [$perl, $run_perl, BUILD->($dir), @buildflags];
596 }
e83ba0bd 597
ef25d9aa 598 unless ( scalar run( command => $cmd,
e83ba0bd 599 buffer => \$captured,
600 verbose => $verbose )
601 ) {
602 error( loc( "MAKE failed:\n%1", $captured ) );
9b4bd854 603 $dist->status->build(0);
604 $fail++; last RUN;
605 }
606
e83ba0bd 607 msg( $captured, 0 );
608
9b4bd854 609 $dist->status->build(1);
610
611 ### add this directory to your lib ###
e83ba0bd 612 $self->add_to_includepath();
9b4bd854 613
614 ### this buffer will not include what tests failed due to a
615 ### M::B/Test::Harness bug. Reported as #9793 with patch
616 ### against 0.2607 on 26/1/2005
617 unless( $skiptest ) {
e83ba0bd 618 my $test_output;
ef25d9aa 619 if ( ON_VMS ) {
620 $cmd = [$perl, BUILD->($dir), "test", @buildflags];
621 }
622 else {
623 $cmd = [$perl, $run_perl, BUILD->($dir), "test", @buildflags];
624 }
e83ba0bd 625 unless ( scalar run( command => $cmd,
626 buffer => \$test_output,
627 verbose => $verbose )
628 ) {
629 error( loc( "MAKE TEST failed:\n%1 ", $test_output ) );
9b4bd854 630
631 ### mark specifically *test* failure.. so we dont
632 ### send success on force...
633 $test_fail++;
634
078adea4 635 if( !$force and !$cb->_callbacks->proceed_on_test_failure->(
e83ba0bd 636 $self, $@ )
078adea4 637 ) {
e83ba0bd 638 $dist->status->test(0);
639 $fail++; last RUN;
9b4bd854 640 }
e83ba0bd 641
642 }
643 else {
a58a4f41 644 msg( loc( "MAKE TEST passed:\n%1", $test_output ), 0 );
645 #msg( $test_output, 0 );
9b4bd854 646 $dist->status->test(1);
647 }
e83ba0bd 648 }
649 else {
9b4bd854 650 msg(loc("Tests skipped"), $verbose);
e83ba0bd 651 }
9b4bd854 652 }
653
654 unless( $cb->_chdir( dir => $orig ) ) {
655 error( loc( "Could not chdir back to start dir '%1'", $orig ) );
656 }
657
658 ### send out test report? ###
659 if( $conf->get_conf('cpantest') and not $prereq_fail ) {
660 $cb->_send_report(
661 module => $self,
662 failed => $test_fail || $fail,
663 buffer => CPANPLUS::Error->stack_as_string,
664 verbose => $verbose,
665 force => $force,
666 tests_skipped => $skiptest,
667 ) or error(loc("Failed to send test report for '%1'",
668 $self->module ) );
669 }
670
671 return $dist->status->created( $fail ? 0 : 1 );
672}
673
674=head2 $dist->install([verbose => BOOL, perl => /path/to/perl])
675
676Actually installs the created dist.
677
678Returns true on success and false on failure.
679
680=cut
681
682sub install {
683 ### just in case you already did a create call for this module object
684 ### just via a different dist object
685 my $dist = shift;
686 my $self = $dist->parent;
687
688 ### we're also the cpan_dist, since we don't need to have anything
689 ### prepared from another installer
690 $dist = $self->status->dist_cpan if $self->status->dist_cpan;
9b4bd854 691
692 my $cb = $self->parent;
693 my $conf = $cb->configure_object;
694 my %hash = @_;
695
696
0183efc5 697 my $verbose; my $perl; my $force; my $buildflags;
9b4bd854 698 { local $Params::Check::ALLOW_UNKNOWN = 1;
699 my $tmpl = {
700 verbose => { default => $conf->get_conf('verbose'),
701 store => \$verbose },
702 force => { default => $conf->get_conf('force'),
703 store => \$force },
0183efc5 704 buildflags => { default => $conf->get_conf('buildflags'),
705 store => \$buildflags },
9b4bd854 706 perl => { default => $^X, store => \$perl },
707 };
708
709 my $args = check( $tmpl, \%hash ) or return;
710 $dist->status->_install_args( $args );
711 }
712
713 my $dir;
714 unless( $dir = $self->status->extract ) {
715 error( loc( "No dir found to operate on!" ) );
716 return;
717 }
718
719 my $orig = cwd();
720
721 unless( $cb->_chdir( dir => $dir ) ) {
722 error( loc( "Could not chdir to build directory '%1'", $dir ) );
723 return;
724 }
725
726 ### value set and false -- means failure ###
727 if( defined $self->status->installed &&
728 !$self->status->installed && !$force
729 ) {
730 error( loc( "Module '%1' has failed to install before this session " .
731 "-- aborting install", $self->module ) );
732 return;
733 }
734
735 my $fail;
0183efc5 736 my @buildflags = $dist->_buildflags_as_list( $buildflags );
e42df61f 737 my $run_perl = $conf->get_program('perlwrapper');
baddfc47 738
9b4bd854 739 ### hmm, how is this going to deal with sudo?
740 ### for now, check effective uid, if it's not root,
741 ### shell out, otherwise use the method
742 if( $> ) {
743
744 ### don't worry about loading the right version of M::B anymore
745 ### the 'new_from_context' already added the 'right' path to
746 ### M::B at the top of the build.pl
ef25d9aa 747 my $cmd;
748 if ( ON_VMS ) {
749 $cmd = [$perl, BUILD->($dir), "install", @buildflags];
750 }
751 else {
752 $cmd = [$perl, $run_perl, BUILD->($dir), "install", @buildflags];
753 }
9b4bd854 754 my $sudo = $conf->get_program('sudo');
755 unshift @$cmd, $sudo if $sudo;
756
757
758 my $buffer;
759 unless( scalar run( command => $cmd,
760 buffer => \$buffer,
761 verbose => $verbose )
762 ) {
763 error(loc("Could not run '%1': %2", 'Build install', $buffer));
764 $fail++;
765 }
766 } else {
ef25d9aa 767 my ($install_output, $cmd);
768 if ( ON_VMS ) {
769 $cmd = [$perl, BUILD->($dir), "install", @buildflags];
770 }
771 else {
772 $cmd = [$perl, $run_perl, BUILD->($dir), "install", @buildflags];
773 }
e83ba0bd 774 unless( scalar run( command => $cmd,
775 buffer => \$install_output,
776 verbose => $verbose )
777 ) {
778 error(loc("Could not run '%1': %2", 'Build install', $install_output));
9b4bd854 779 $fail++;
780 }
e83ba0bd 781 else {
782 msg( $install_output, 0 );
783 }
9b4bd854 784 }
785
786
787 unless( $cb->_chdir( dir => $orig ) ) {
788 error( loc( "Could not chdir back to start dir '%1'", $orig ) );
789 }
790
791 return $dist->status->installed( $fail ? 0 : 1 );
792}
793
baddfc47 794### returns the string 'foo=bar --zot quux'
795### as the list 'foo=bar', '--zot', 'qux'
796sub _buildflags_as_list {
9b4bd854 797 my $self = shift;
798 my $flags = shift or return;
799
baddfc47 800 return Module::Build->split_like_shell($flags);
9b4bd854 801}
802
9b4bd854 803=head1 AUTHOR
804
805Originally by Jos Boumans E<lt>kane@cpan.orgE<gt>. Brought to working
e83ba0bd 806condition by Ken Williams E<lt>kwilliams@cpan.orgE<gt>.
807
4320d094 808Other hackery and currently maintained by Chris C<BinGOs> Williams ( no relation ). E<lt>bingos@cpan.orgE<gt>.
9b4bd854 809
e83ba0bd 810=head1 LICENSE
9b4bd854 811
812The CPAN++ interface (of which this module is a part of) is
813copyright (c) 2001, 2002, 2003, 2004, 2005 Jos Boumans E<lt>kane@cpan.orgE<gt>.
814All rights reserved.
815
816This library is free software;
817you may redistribute and/or modify it under the same
818terms as Perl itself.
819
820=cut
821
0183efc5 822qq[Putting the Module::Build into CPANPLUS];
9b4bd854 823
e83ba0bd 824
9b4bd854 825# Local variables:
826# c-indentation-style: bsd
827# c-basic-offset: 4
828# indent-tabs-mode: nil
829# End:
830# vim: expandtab shiftwidth=4:
e83ba0bd 831