App-MechaCPAN

 view release on metacpan or  search on metacpan

lib/App/MechaCPAN/Install.pm  view on Meta::CPAN

  my $alias  = shift;
  my $cache  = shift;

  $target = _find_target( $target, $cache );

  if ( $alias =~ $ident_re )
  {
    $target->{modules}->{$alias} = {
      inital_version => _get_mod_ver($alias),
    };
  }

  $cache->{targets}->{$alias} = $target;
  return;
}

sub _targets_from_cpanfile
{
  my $cpanfile = shift;
  my $cache    = shift;
  my $update   = shift;

  my $iname
    = $cpanfile =~ m{^(.[/\\])?cpanfile$}
    ? 'cpanfile'
    : "cpanfile $cpanfile";
  info "Reading $iname";

  my $prereq = parse_cpanfile($cpanfile);
  my @phases = qw/configure build test runtime/;

  my @acc = map {%$_} map { values %{ $prereq->{$_} } } @phases;
  my @reqs;
  while (@acc)
  {
    my $req    = [ splice( @acc, 0, 2 ) ];
    my $target = _create_target( $req, $cache );
    $target->{update} = $update // 1;
    push @reqs, $target;
  }

  return @reqs;
}

sub _create_inital_target
{
  my $src_name = shift;
  my $cache    = shift;
  my $update   = shift;

  # Check to see if the source is a cpanfile
  if ( ref $src_name eq '' || ref $src_name eq 'GLOB' )
  {
    if ( -d $src_name )
    {
      $src_name = File::Spec->catfile( $src_name, 'cpanfile' );
    }

    if ( -e -f $src_name )
    {
      # If the filename includes the work cpanfile or looks like a text file,
      # assume it's a cpanfile because a module archive must be binary
      if ( $src_name =~ m/cpanfile/ || -T $src_name )
      {
        return _targets_from_cpanfile( $src_name, $cache, $update );
      }
    }
  }

  my $target = _create_target( $src_name, $cache );
  $target->{update} = $update // 1;

  return $target;
}

sub _create_target
{
  my $target = shift;
  my $cache  = shift;

  my $src = _src_normalize($target);
  my $cached_target = _find_target( $target, $cache );

  if ( !defined $cached_target )
  {
    my $src_name = $src->{src_name};

    $cached_target = { %$src, state => 0 };
    $cache->{targets}->{$src_name} = $cached_target;
    $cached_target->{key} = $src_name;
  }

  if ( $cached_target->{state} eq $COMPLETE
    && $src->{constraint} ne $cached_target->{constraint} )
  {
    $cached_target->{constraint} = $src->{constraint};
    $cached_target->{state}      = 0;
    delete $cached_target->{version};
  }

  for my $altkey (qw/distvname name module/)
  {
    my $altname = $cached_target->{$altkey};
    if ( defined $altname )
    {
      if ( !exists $cache->{targets}->{$altname} )
      {
        _alias_target( $cached_target, $altname, $cache );
      }
    }
  }

  if ( $src->{src_name} =~ $ident_re )
  {
    $cached_target->{module} = $src->{src_name};
  }

  return $cached_target;
}

sub _target_prereqs



( run in 1.515 second using v1.01-cache-2.11-cpan-39bf76dae61 )