CPANPLUS-Dist-Build

 view release on metacpan or  search on metacpan

lib/CPANPLUS/Dist/Build.pm  view on Meta::CPAN

    }
    else {
      my $safe_ver = version->new('0.31_03');
      my $content;
      PREREQS: {
        if ( version->new( $Module::Build::VERSION ) >= $safe_ver and IPC::Cmd->can_capture_buffer ) {
          my @buildflags = $dist->_buildflags_as_list( $buildflags );

          # Use the new Build action 'prereq_data'
          my @run_perl    = $dist->_perlrun();

          unless ( scalar run(    command => [$perl, @run_perl, BUILD->($dir), 'prereq_data', @buildflags],
                                buffer  => \$content,
                                verbose => 0 )
          ) {
            error( loc( "Build 'prereq_data' failed: %1 %2", $!, $content ) );
            #return;
          }
          else {
            last PREREQS;
          }

        }

        my $file = File::Spec->catfile( $dir, '_build', 'prereqs' );
        return unless -f $file;

        my $fh = FileHandle->new();

        unless( $fh->open( $file ) ) {
          error( loc( "Cannot open '%1': %2", $file, $! ) );
          return;
        }

        $content = do { local $/; <$fh> };

      }

      return unless $content;
      my $bphash = eval $content;
      return unless $bphash and ref $bphash eq 'HASH';
      foreach my $type ('requires', 'build_requires', 'test_requires') {
        next unless $bphash->{$type} and ref $bphash->{$type} eq 'HASH';
        $prereqs->{$_} = $bphash->{$type}->{$_} for keys %{ $bphash->{$type} };
      }
    }

    {
      delete $prereqs->{'perl'}
         unless version->new($CPANPLUS::Internals::VERSION)
             >= version->new('0.9102');
    }

    ### allows for a user defined callback to filter the prerequisite
    ### list as they see fit, to remove (or add) any prereqs they see
    ### fit. The default installed callback will return the hashref in
    ### an unmodified form
    ### this callback got added after cpanplus 0.0562, so use a 'can'
    ### to find out if it's supported. For older versions, we'll just
    ### return the hashref as is ourselves.
    my $href    = $cb->_callbacks->can('filter_prereqs')
                    ? $cb->_callbacks->filter_prereqs->( $cb, $prereqs )
                    : $prereqs;

    $self->status->prereqs( $href );

    ### make sure it's not the same ref
    return { %$href };
}


sub create {
    ### just in case you already did a create call for this module object
    ### just via a different dist object
    my $dist = shift;
    my $self = $dist->parent;

    ### we're also the cpan_dist, since we don't need to have anything
    ### prepared from another installer
    $dist    = $self->status->dist_cpan if      $self->status->dist_cpan;
    $self->status->dist_cpan( $dist )   unless  $self->status->dist_cpan;

    my $cb   = $self->parent;
    my $conf = $cb->configure_object;
    my %hash = @_;

    my $dir;
    unless( $dir = $self->status->extract ) {
        error( loc( "No dir found to operate on!" ) );
        return;
    }

    my $args;
    my( $force, $verbose, $buildflags, $skiptest, $prereq_target,
        $perl, $prereq_format, $prereq_build);
    {   local $Params::Check::ALLOW_UNKNOWN = 1;
        my $tmpl = {
            force           => {    default => $conf->get_conf('force'),
                                    store   => \$force },
            verbose         => {    default => $conf->get_conf('verbose'),
                                    store   => \$verbose },
            perl            => {    default => $^X, store => \$perl },
            buildflags      => {    default => $conf->get_conf('buildflags'),
                                    store   => \$buildflags },
            skiptest        => {    default => $conf->get_conf('skiptest'),
                                    store   => \$skiptest },
            prereq_target   => {    default => '', store => \$prereq_target },
            ### don't set the default format to 'build' -- that is wrong!
            prereq_format   => {    #default => $self->status->installer_type,
                                    default => '',
                                    store   => \$prereq_format },
            prereq_build    => {    default => 0, store => \$prereq_build },
        };

        $args = check( $tmpl, \%hash ) or return;
    }

    # restore the state as we have created this already.
    if ( $dist->status->created && !$force ) {
        ### add this directory to your lib ###
        $self->add_to_includepath();
        return 1;

lib/CPANPLUS/Dist/Build.pm  view on Meta::CPAN


        unless( $ok ) {
            #### use $dist->flush to reset the cache ###
            error( loc( "Unable to satisfy prerequisites for '%1' " .
                        "-- aborting install", $self->module ) );
            $dist->status->build(0);
            $fail++; $prereq_fail++;
            last RUN;
        }

        my ($captured, $cmd);
        if ( ON_VMS ) {
            $cmd = [$perl, BUILD->($dir), @buildflags];
        }
        else {
            $cmd = [$perl, @run_perl, BUILD->($dir), @buildflags];
        }

        unless ( scalar run(    command => $cmd,
                                buffer  => \$captured,
                                verbose => $verbose )
        ) {
            error( loc( "MAKE failed:\n%1", $captured ) );
            $dist->status->build(0);
            if ( $conf->get_conf('cpantest') ) {
               $status->{stage} = 'build';
               $status->{capture} = $captured;
            }
            $fail++; last RUN;
        }

        msg( $captured, 0 );

        $dist->status->build(1);

        ### add this directory to your lib ###
        $self->add_to_includepath();

        ### this buffer will not include what tests failed due to a
        ### M::B/Test::Harness bug. Reported as #9793 with patch
        ### against 0.2607 on 26/1/2005
        unless( $skiptest ) {
            my $test_output;
            if ( ON_VMS ) {
                $cmd     = [$perl, BUILD->($dir), "test", @buildflags];
            }
            else {
                $cmd     = [$perl, @run_perl, BUILD->($dir), "test", @buildflags];
            }
            local $ENV{PERL_INSTALL_QUIET};
            unless ( scalar run(    command => $cmd,
                                    buffer  => \$test_output,
                                    verbose => $verbose )
            ) {
                error( loc( "MAKE TEST failed:\n%1 ", $test_output ), ( $verbose ? 0 : 1 ) );

                ### mark specifically *test* failure.. so we don't
                ### send success on force...
                $test_fail++;

                if( !$force and !$cb->_callbacks->proceed_on_test_failure->(
                                      $self, $@ )
                ) {
                    $dist->status->test(0);
                    if ( $conf->get_conf('cpantest') ) {
                      $status->{stage} = 'test';
                      $status->{capture} = $test_output;
                    }
                    $fail++; last RUN;
                }

            }
            else {
                msg( loc( "MAKE TEST passed:\n%1", $test_output ), 0 );
                $dist->status->test(1);
                if ( $conf->get_conf('cpantest') ) {
                   $status->{stage} = 'test';
                   $status->{capture} = $test_output;
                }
            }
        }
        else {
            msg(loc("Tests skipped"), $verbose);
        }
    }

    unless( $cb->_chdir( dir => $orig ) ) {
        error( loc( "Could not chdir back to start dir '%1'", $orig ) );
    }

    ### send out test report? ###
    if( $conf->get_conf('cpantest') and not $prereq_fail ) {
        $cb->_send_report(
            module          => $self,
            failed          => $test_fail || $fail,
            buffer          => CPANPLUS::Error->stack_as_string,
            status          => $status,
            verbose         => $verbose,
            force           => $force,
            tests_skipped   => $skiptest,
        ) or error(loc("Failed to send test report for '%1'",
                    $self->module ) );
    }

    return $dist->status->created( $fail ? 0 : 1 );
}


sub install {
    ### just in case you already did a create call for this module object
    ### just via a different dist object
    my $dist = shift;
    my $self = $dist->parent;

    ### we're also the cpan_dist, since we don't need to have anything
    ### prepared from another installer
    $dist    = $self->status->dist_cpan if $self->status->dist_cpan;

    my $cb   = $self->parent;
    my $conf = $cb->configure_object;
    my %hash = @_;



( run in 1.266 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )