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