App-ShellCompleter-cpanm
view release on metacpan or search on metacpan
devdata/Menlo-CLI-Compat.v1.9022.pm.txt view on Meta::CPAN
my %uniq;
$self->{install_types} = [ grep !$uniq{$_}++, @{$self->{install_types}}, $type ];
};
push @handlers, "without-$type" => sub {
$self->{install_types} = [ grep $_ ne $type, @{$self->{install_types}} ];
};
}
@handlers;
}
sub build_args_handlers {
my $self = shift;
my @handlers;
for my $phase (qw( configure build test install )) {
push @handlers, "$phase-args=s" => \($self->{build_args}{$phase});
}
@handlers;
}
sub parse_options {
my $self = shift;
local @ARGV = @{$self->{argv}};
push @ARGV, grep length, split /\s+/, $self->env('OPT');
push @ARGV, @_;
Getopt::Long::Configure("bundling");
Getopt::Long::GetOptions(
'f|force' => sub { $self->{skip_installed} = 0; $self->{force} = 1 },
'n|notest!' => \$self->{notest},
'test-only' => sub { $self->{notest} = 0; $self->{skip_installed} = 0; $self->{test_only} = 1 },
'S|sudo!' => \$self->{sudo},
'v|verbose' => \$self->{verbose},
'verify!' => \$self->{verify},
'q|quiet!' => \$self->{quiet},
'h|help' => sub { $self->{action} = 'show_help' },
'V|version' => sub { $self->{action} = 'show_version' },
'perl=s' => sub {
$self->diag("--perl is deprecated since it's known to be fragile in figuring out dependencies. Run `$_[1] -S cpanm` instead.\n", 1);
$self->{perl} = $_[1];
},
'l|local-lib=s' => sub { $self->{local_lib} = $self->maybe_abs($_[1]) },
'L|local-lib-contained=s' => sub {
$self->{local_lib} = $self->maybe_abs($_[1]);
$self->{self_contained} = 1;
$self->{pod2man} = undef;
},
'self-contained!' => \$self->{self_contained},
'exclude-vendor!' => \$self->{exclude_vendor},
'mirror=s@' => $self->{mirrors},
'mirror-only!' => \$self->{mirror_only},
'mirror-index=s' => sub { $self->{mirror_index} = $self->maybe_abs($_[1]) },
'M|from=s' => sub {
$self->{mirrors} = [$_[1]];
$self->{mirror_only} = 1;
},
'cpanmetadb=s' => \$self->{cpanmetadb},
'cascade-search!' => \$self->{cascade_search},
'prompt!' => \$self->{prompt},
'installdeps' => \$self->{installdeps},
'skip-installed!' => \$self->{skip_installed},
'skip-satisfied!' => \$self->{skip_satisfied},
'reinstall' => sub { $self->{skip_installed} = 0 },
'interactive!' => \$self->{interactive},
'i|install' => sub { $self->{cmd} = 'install' },
'info' => sub { $self->{cmd} = 'info' },
'look' => sub { $self->{cmd} = 'look'; $self->{skip_installed} = 0 },
'U|uninstall' => sub { $self->{cmd} = 'uninstall' },
'self-upgrade' => sub { $self->{action} = 'self_upgrade' },
'uninst-shadows!' => \$self->{uninstall_shadows},
'lwp!' => \$self->{try_lwp},
'wget!' => \$self->{try_wget},
'curl!' => \$self->{try_curl},
'auto-cleanup=s' => \$self->{auto_cleanup},
'man-pages!' => \$self->{pod2man},
'scandeps' => \$self->{scandeps},
'showdeps' => sub { $self->{showdeps} = 1; $self->{skip_installed} = 0 },
'format=s' => \$self->{format},
'save-dists=s' => sub {
$self->{save_dists} = $self->maybe_abs($_[1]);
},
'skip-configure!' => \$self->{skip_configure},
'static-install!' => \$self->{static_install},
'dev!' => \$self->{dev_release},
'metacpan!' => \$self->{metacpan},
'report-perl-version!' => \$self->{report_perl_version},
'configure-timeout=i' => \$self->{configure_timeout},
'build-timeout=i' => \$self->{build_timeout},
'test-timeout=i' => \$self->{test_timeout},
'with-develop' => \$self->{with_develop},
'without-develop' => sub { $self->{with_develop} = 0 },
'with-configure' => \$self->{with_configure},
'without-configure' => sub { $self->{with_configure} = 0 },
'with-feature=s' => sub { $self->{features}{$_[1]} = 1 },
'without-feature=s' => sub { $self->{features}{$_[1]} = 0 },
'with-all-features' => sub { $self->{features}{__all} = 1 },
'pp|pureperl!' => \$self->{pure_perl},
"cpanfile=s" => \$self->{cpanfile_path},
$self->install_type_handlers,
$self->build_args_handlers,
);
if (!@ARGV && $0 ne '-' && !-t STDIN){ # e.g. # cpanm < author/requires.cpanm
push @ARGV, $self->load_argv_from_fh(\*STDIN);
$self->{load_from_stdin} = 1;
}
$self->{argv} = \@ARGV;
}
sub check_upgrade {
my $self = shift;
my $install_base = $ENV{PERL_LOCAL_LIB_ROOT} ? $self->local_lib_target($ENV{PERL_LOCAL_LIB_ROOT}) : $Config{installsitebin};
if ($0 eq '-') {
# run from curl, that's fine
return;
} elsif ($0 !~ /^$install_base/) {
if ($0 =~ m!perlbrew/bin!) {
devdata/Menlo-CLI-Compat.v1.9022.pm.txt view on Meta::CPAN
die "Can't write to cpanm home '$self->{home}': You should fix it with chown/chmod first.\n";
}
$self->{base} = "$self->{home}/work/" . time . ".$$";
File::Path::mkpath([ $self->{base} ], 0, 0777);
# native path because we use shell redirect
$self->{log} = File::Spec->catfile($self->{base}, "build.log");
my $final_log = "$self->{home}/build.log";
{ open my $out, ">$self->{log}" or die "$self->{log}: $!" }
if (CAN_SYMLINK) {
my $build_link = "$self->{home}/latest-build";
unlink $build_link;
symlink $self->{base}, $build_link;
unlink $final_log;
symlink $self->{log}, $final_log;
} else {
my $log = $self->{log}; my $home = $self->{home};
$self->{at_exit} = sub {
my $self = shift;
my $temp_log = "$home/build.log." . time . ".$$";
File::Copy::copy($log, $temp_log)
&& unlink($final_log);
rename($temp_log, $final_log);
}
}
$self->chat("cpanm ($self->{name}) $Menlo::VERSION on perl $] built for $Config{archname}\n" .
"Work directory is $self->{base}\n");
}
sub search_mirror_index_local {
my ($self, $local, $module, $version) = @_;
require CPAN::Common::Index::LocalPackage;
my $index = CPAN::Common::Index::LocalPackage->new({ source => $local });
$self->search_common($index, { package => $module }, $version);
}
sub search_mirror_index {
my ($self, $mirror, $module, $version) = @_;
require Menlo::Index::Mirror;
my $index = Menlo::Index::Mirror->new({
mirror => $mirror,
cache => $self->source_for($mirror),
fetcher => sub { $self->mirror(@_) },
});
$self->search_common($index, { package => $module }, $version);
}
sub search_common {
my($self, $index, $search_args, $want_version) = @_;
$index->refresh_index;
my $found = $index->search_packages($search_args);
$found = $self->cpan_module_common($found) if $found;
return $found unless $self->{cascade_search};
if ($found) {
if ($self->satisfy_version($found->{module}, $found->{module_version}, $want_version)) {
return $found;
} else {
$self->chat("Found $found->{module} $found->{module_version} which doesn't satisfy $want_version.\n");
}
}
return;
}
sub with_version_range {
my($self, $version) = @_;
defined($version) && $version =~ /(?:<|!=|==)/;
}
sub search_metacpan {
my($self, $module, $version, $dev_release) = @_;
require Menlo::Index::MetaCPAN;
$self->chat("Searching $module ($version) on metacpan ...\n");
my $index = Menlo::Index::MetaCPAN->new({ include_dev => $self->{dev_release} });
my $pkg = $self->search_common($index, { package => $module, version_range => $version }, $version);
return $pkg if $pkg;
$self->diag_fail("Finding $module ($version) on metacpan failed.");
return;
}
sub search_database {
my($self, $module, $version) = @_;
my $found;
if ($self->{dev_release} or $self->{metacpan}) {
$found = $self->search_metacpan($module, $version, $self->{dev_release}) and return $found;
$found = $self->search_cpanmetadb($module, $version, $self->{dev_release}) and return $found;
} else {
$found = $self->search_cpanmetadb($module, $version) and return $found;
$found = $self->search_metacpan($module, $version) and return $found;
}
}
sub search_cpanmetadb {
my($self, $module, $version, $dev_release) = @_;
require Menlo::Index::MetaDB;
$self->chat("Searching $module ($version) on cpanmetadb ...\n");
my $args = { package => $module };
if ($self->with_version_range($version)) {
$args->{version_range} = $version;
}
my $index = Menlo::Index::MetaDB->new({ uri => $self->{cpanmetadb} });
my $pkg = $self->search_common($index, $args, $version);
return $pkg if $pkg;
$self->diag_fail("Finding $module on cpanmetadb failed.");
return;
}
sub search_module {
my($self, $module, $version) = @_;
if ($self->{mirror_index}) {
$self->mask_output( chat => "Searching $module on mirror index $self->{mirror_index} ...\n" );
my $pkg = $self->search_mirror_index_local($self->{mirror_index}, $module, $version);
return $pkg if $pkg;
unless ($self->{cascade_search}) {
$self->mask_output( diag_fail => "Finding $module ($version) on mirror index $self->{mirror_index} failed." );
return;
}
}
unless ($self->{mirror_only}) {
my $found = $self->search_database($module, $version);
return $found if $found;
}
MIRROR: for my $mirror (@{ $self->{mirrors} }) {
$self->mask_output( chat => "Searching $module on mirror $mirror ...\n" );
my $pkg = $self->search_mirror_index($mirror, $module, $version);
return $pkg if $pkg;
$self->mask_output( diag_fail => "Finding $module ($version) on mirror $mirror failed." );
}
return;
}
sub source_for {
my($self, $mirror) = @_;
$mirror =~ s/[^\w\.\-]+/%/g;
my $dir = "$self->{home}/sources/$mirror";
File::Path::mkpath([ $dir ], 0, 0777);
return $dir;
}
sub load_argv_from_fh {
my($self, $fh) = @_;
my @argv;
while(defined(my $line = <$fh>)){
chomp $line;
$line =~ s/#.+$//; # comment
$line =~ s/^\s+//; # trim spaces
$line =~ s/\s+$//; # trim spaces
push @argv, split ' ', $line if $line;
}
return @argv;
}
sub show_version {
my $self = shift;
print "cpanm ($self->{name}) version $VERSION ($0)\n";
print "perl version $] ($^X)\n\n";
print " \%Config:\n";
for my $key (qw( archname installsitelib installsitebin installman1dir installman3dir
sitearchexp sitelibexp vendorarch vendorlibexp archlibexp privlibexp )) {
print " $key=$Config{$key}\n" if $Config{$key};
}
print " \%ENV:\n";
( run in 0.524 second using v1.01-cache-2.11-cpan-39bf76dae61 )