App-EPAN

 view release on metacpan or  search on metacpan

lib/App/EPAN.pm  view on Meta::CPAN

   return $self->action_update;
} ## end sub action_create

sub action_update {
   my ($self) = @_;

   my $target = $self->target_dir;
   $target->mkpath() unless -d $target;

   my $dists   = $target->stringify();
   my $local   = $target->subdir('local')->stringify();
   my @command = (
      qw< cpanm --reinstall --quiet --self-contained >,
      ($self->execute_tests ? () : '--notest'),
      '--local-lib-contained' => $local,
      '--save-dists'          => $dists,
      $self->args(),
   );

   my ($out, $err);
   {
      local $SIG{TERM} = sub {
         WARN "cpanm: received TERM signal, ignoring";
      };
      INFO "calling @command";
      IPC::Run::run \@command, \undef, \*STDOUT, \*STDERR
        or LOGDIE "cpanm: $? ($err)";
   }

   INFO 'onboarding completed, indexing...';
   $self->_do_index($target);
   my $data_for = $self->last_index();

   INFO 'saving distlist';
   my @distros = $self->last_distlist();
   $self->_save2($target->file('distlist.txt'), join "\n", @distros, '');

   INFO 'saving modlist';
   my @modules = $self->last_modlist();
   $self->_save2($target->file('modlist.txt'), join "\n", @modules, '');

   my $file = $target->file('install.sh');
   if (!-e $file) {
      $self->_save2($file, <<'END_OF_INSTALL');
#!/bin/bash
ME=$(readlink -f "$0")
MYDIR=$(dirname "$ME")

TARGET="$MYDIR/local"
[ $# -gt 0 ] && TARGET=$1

if [ -n "$TARGET" ]; then
   "$MYDIR/cpanm" --mirror "file://$MYDIR" --mirror-only \
      -L "$TARGET" \
      $(<"$MYDIR/modlist.txt")
else
   "$MYDIR/cpanm" --mirror "file://$MYDIR" --mirror-only \
      $(<"$MYDIR/modlist.txt")
fi
END_OF_INSTALL
      chmod 0777 & ~umask(), $file->stringify();
   } ## end if (!-e $file)

   $file = $target->file('cpanm');
   if (!-e $file) {
      my $cpanm = which('cpanm');
      File::Copy::copy($cpanm, $file->stringify());
      chmod 0777 & ~umask(), $file->stringify();
   }
} ## end sub action_update

{
   no strict 'subs';
   *action_install = \&action_update;
   *action_add     = \&action_update;
}

sub action_inject {
   my ($self) = @_;

   my $target = $self->target_dir;
   $target->mkpath() unless -d $target;

   my $author = $self->config('author') // $ENV{EPAN_AUTHOR} // 'LOCAL';
   my $first = substr $author, 0, 1;
   my $first_two = substr $author, 0, 2;
   my $repo = $target->subdir(qw< authors id >, $first, $first_two, $author);
   $repo->mkpath;
   $repo = $repo->stringify;

   File::Copy::copy($_, $repo) for $self->args;

   INFO 'onboarding completed, indexing...';
   $self->_do_index($target);

   return;
}

sub _list_obsoletes {
   my ($self) = @_;
   my $basedir = $self->target_dir;
   my $data_for = $self->_collect_index_for($basedir);
   return sort {$a cmp $b} keys %{$data_for->{obsolete}};
}

sub action_list_obsoletes {
   my ($self) = @_;
   say for $self->_list_obsoletes;
   return;
}

sub action_purge_obsoletes {
   my ($self) = @_;
   for my $file ($self->_list_obsoletes) {
      INFO "removing $file";
      unlink $file;
   }
   return;
}

sub action_list_actions {
   my $self = shift;
   no strict 'refs';
   say 'Available actions:';
   say for
     sort {$a cmp $b}
     map {s/^action_/- /; s/_/-/g; $_ }
     grep {/^action_/ && $self->can($_)}



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