CPAN-Mini-Inject

 view release on metacpan or  search on metacpan

lib/CPAN/Mini/Inject.pm  view on Meta::CPAN

=cut

sub _repo_file {
  File::Spec->catfile( shift->config->get( 'repository' ), @_ );
}

sub _modulelist { shift->_repo_file( 'modulelist' ) }

sub readlist {
  my $self = shift;

  $self->{modulelist} = undef;

  my $ml = $self->_modulelist;
  return $self unless -e $ml;

  open MODLIST, '<', $ml or croak "$0: cannot read module list: $ml ($!)";
  while ( <MODLIST> ) {
    chomp;
    push @{ $self->{modulelist} }, $_;
  }
  close MODLIST;

  return $self;
}

=item C<writelist>

Write to the repository modulelist.

=cut

sub writelist {
  my $self = shift;

  my $modulelist_file = $self->_repo_file( 'modulelist' );

  croak "$0: repository dir <%s> is not writable", $self->config->get( 'repository' )
  	unless -w $self->config->get( 'repository' );
  croak "$0: modulelist file <%s> is not writable", $modulelist_file
  	if( -e $modulelist_file and ! -w _ );

  return $self unless defined $self->{modulelist};

  open my $fh, '>', $modulelist_file
  	or croak sprintf "$0: modulelist file <%s> cannot be opened for writing: %s", $modulelist_file, $!;
  for ( sort( @{ $self->{modulelist} } ) ) {
    chomp;
    print {$fh} "$_\n";
  }
  close $fh;

  $self->_updperms( $modulelist_file );

  return $self;
}

sub _updperms {
  my ( $self, $file ) = @_;

  chmod oct( $self->config->get( 'dirmode' ) ) & 06666, $file
   if $self->config->get( 'dirmode' );
}

sub _optionchk {
  my ( $options, @list ) = @_;
  my @missing;

  for my $option ( @list ) {
    push @missing, $option
     unless defined $$options{$option};
  }

  return join ' ', @missing;
}

sub _make_path {
  my $um = umask 0;
  make_path( @_ );
  umask $um;
}

sub _authordir {
  my ( $self, $author, $dir ) = @_;

  my @author
   = ( substr( $author, 0, 1 ), substr( $author, 0, 2 ), $author );

  my $dm = $self->config->get( 'dirmode' );
  my @new
   = _make_path( File::Spec->catdir( $dir, 'authors', 'id', @author ),
    defined $dm ? { mode => oct $dm } : {} );

  return return File::Spec->catdir( @author );
}

sub _fmtmodule {
  my ( $module, $file, $version ) = @_;
  my $fw = 38 - length $version;
  $fw = length $module if $fw < length $module;
  return sprintf "%-${fw}s %s  %s", $module, $version, $file;
}

sub _cfg { $_[0]->{config}{ $_[1] } }

sub _readpkgs {
  my $self = shift;
  my $file = catfile( $self->config->get( 'local' ), 'modules', _packages_file() );

  unless( -e $file ) {
  	carp sprintf "$0: <%s> does not exist; starting with empty list of packages\n", $file;
  	return [];
  }

  my $gzread = gzopen( $file, 'rb' ) or do {
    carp sprintf "$0: cannot open <%s>: <%s>; starting with empty list of packages\n", $file, $gzerrno;
    return []
  };

  my $inheader = 1;
  my @packages;



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