cpanp-mirror
#!/usr/bin/perl
use strict;
use warnings;
use URI;
my $mirror = shift;
die 'usage: cpanp-mirror <mirror, ie: "ftp://ftp.cpan.org/pub/CPAN/">\n'
unless $mirror;
print "Mirroring from $mirror\n";
my $uri = URI->new( $mirror ) or die "Error creating URI from $mirror\n";
my $local = {
path => $uri->path,
scheme => $uri->scheme,
host => $uri->host,
};
use vars '$VERSION';
use CPANPLUS;
use CPANPLUS::Shell qw[Default];
use CPANPLUS::Backend;
$VERSION = CPANPLUS->VERSION;
# my $cb = new CPANPLUS::Backend;
my $shell = CPANPLUS::Shell->new;
my $conf = $shell->backend->configure_object;
# my $hosts = $conf->get_conf('hosts');
# unshift @$hosts, $local;
my $hosts = [ $local ];
$conf->set_conf('hosts' => $hosts);
### if we're given a command, run it; otherwise, open a shell.
if (@ARGV) {
### take the command line arguments as a command
my $input = "@ARGV";
### if they said "--help", fix it up to work.
$input = 'h' if $input =~ /^\s*--?h(?:elp)?\s*$/i;
### strip the leading dash
$input =~ s/^\s*-//;
### pass the command line to the shell
$shell->dispatch_on_input(input => $input, noninteractive => 1);
} else {
### open a shell for the user
$shell->shell();
}