CPAN-Mini-Inject
view release on metacpan or search on metacpan
use v5.16;
use strict;
use Pod::Usage 1.12;
use Getopt::Long;
use YAML qw( Load );
use CPAN::Mini::Inject;
use Env;
use File::Slurp 'write_file';
use File::Temp;
our $VERSION = '0.38';
our %options = ();
sub print_version {
printf( "mcpani v%s, using CPAN::Mini::Inject v%s and Perl v%vd\n",
$VERSION, $CPAN::Mini::Inject::VERSION, $^V );
}
sub chkactions {
for my $action ( qw(add update mirror inject) ) {
return 1 if ( $options{actionname} eq $action );
}
return 0;
}
sub setsub {
$options{actionname} = shift;
$options{action} = shift;
}
sub add {
my $mcpi = shift;
$mcpi->readlist;
$mcpi->add(
module => $options{module},
authorid => $options{authorid},
version => $options{version},
file => $options{file}
);
if ( $options{verbose} ) {
my @added = $mcpi->added_modules;
foreach my $added ( @added ){
print "\nAdding File: $added->{file}\n";
print "Author ID: $added->{authorid}\n";
my $modules = $added->{modules};
foreach my $mod ( sort keys %$modules ){
print "Module: $mod\n";
print "Version: $modules->{$mod}\n";
}
print "To repository: $mcpi->{config}{repository}\n\n";
}
}
$mcpi->writelist;
}
sub update {
my $mcpi = shift;
mirror( $mcpi );
inject( $mcpi );
}
sub mirror {
my $mcpi = shift;
# these come from the command line
my %mirroropts =
map { $_ => $options{$_} }
grep { defined $options{$_} }
qw(remote local verbose);
$mcpi->update_mirror( %mirroropts );
}
sub inject {
my $mcpi = shift;
print "Injecting modules from $mcpi->{config}{repository}\n"
if ( $options{verbose} );
$mcpi->inject( $options{verbose} );
}
# MAIN
Getopt::Long::Configure( 'no_ignore_case' );
Getopt::Long::Configure( 'bundling' );
GetOptions(
'h|help|?' =>
sub { pod2usage( { -verbose => 1, -input => \*DATA } ); exit },
'H|man' =>
sub { pod2usage( { -verbose => 2, -input => \*DATA } ); exit },
'V|version' => sub { print_version(); exit; },
'v|verbose' => \$options{verbose},
'l|local=s' => \$options{local},
'r|remote=s' => \$options{remote},
'p|passive' => \$ENV{FTP_PASSIVE},
'add' => sub { setsub( 'add', \&add ) },
'update' => sub { setsub( 'update', \&update ) },
'mirror' => sub { setsub( 'mirror', \&mirror ) },
'inject' => sub { setsub( 'inject', \&inject ) },
'module=s' => \$options{module},
'authorid=s' => \$options{authorid},
'modversion=s' => \$options{version},
'file=s' => \$options{file},
'all-in-meta' => \$options{'all-in-meta'},
'signing-key=s' => \$options{'signing_key'},
'discover-packages' => \$options{'discover-packages'},
) or exit 1;
unless ( defined( $options{action} ) && chkactions() ) {
pod2usage( { -verbose => 1, -input => \*DATA } );
exit;
}
my $mcpi = CPAN::Mini::Inject->new->loadcfg( $options{cfg} )->parsecfg;
( run in 0.881 second using v1.01-cache-2.11-cpan-39bf76dae61 )