App-pmuninstall
view release on metacpan or search on metacpan
lib/App/pmuninstall.pm view on Meta::CPAN
my $local_lib_base = quotemeta $self->_canon_path_compare($self->{local_lib});
$file = $self->_canon_path_compare($file);
return $file =~ /^$local_lib_base(?:\/|\z)/ ? 1 : 0;
}
sub vname_for {
my ($self, $module) = @_;
$self->puts("Fetching $module vname on cpanmetadb") if $self->{verbose};
my $yaml = $self->fetch("$cpanmetadb/$module") or return;
my $meta = YAML::Load($yaml);
my $info = CPAN::DistnameInfo->new($meta->{distfile}) or return;
return $info->distvname;
}
# taken from cpan-outdated
sub setup_local_lib {
my $self = shift;
return unless $self->{local_lib};
unless (-d $self->{local_lib}) {
$self->puts(colored ['red'], "! $self->{local_lib} : no such directory");
exit 1;
}
local $SIG{__WARN__} = sub { }; # catch 'Attempting to write ...'
$self->{inc} = [
grep { defined }
map { Cwd::realpath($_) }
@{$self->build_active_perl5lib($self->{local_lib}, $self->{self_contained})}
];
push @{$self->{inc}}, @INC unless $self->{self_contained};
}
sub build_active_perl5lib {
my ($self, $path, $interpolate) = @_;
my $perl5libs = [
$self->install_base_arch_path($path),
$self->install_base_perl_path($path),
$interpolate && $ENV{PERL5LIB} ? split(/\Q$Config{path_sep}\E/, $ENV{PERL5LIB}) : (),
];
return $perl5libs;
}
sub install_base_perl_path {
my ($self, $path) = @_;
File::Spec->catdir($path, 'lib', 'perl5');
}
sub install_base_arch_path {
my ($self, $path) = @_;
File::Spec->catdir($self->install_base_perl_path($path), $Config{archname});
}
sub fetch {
my ($self, $url) = @_;
$self->puts("-> Fetching from $url") if $self->{verbose};
my $res = HTTP::Tiny->new->get($url);
return if $res->{status} == 404;
die "[$res->{status}] fetch $url failed!!\n" if !$res->{success};
return $res->{content};
}
sub slurp {
my ($self, $file) = @_;
open my $fh, '<', $file or die "$file $!";
do { local $/; <$fh> };
}
sub puts {
my ($self, @msg) = @_;
push @msg, '' unless @msg;
print ' ' x $OUTPUT_INDENT_LEVEL if $OUTPUT_INDENT_LEVEL;
print @msg, "\n";
}
sub usage {
my $self = shift;
$self->puts(<< 'USAGE');
Usage:
pm-uninstall [options] Module [...]
options:
-v,--verbose Turns on chatty output
-f,--force Uninstalls without prompts
-c,--checkdeps Check dependencies (defaults to on)
-n,--no-checkdeps Don't check dependencies
-q,--quiet Suppress some messages
-h,--help This help message
-V,--version Show version
-l,--local-lib Additional module path
-L,--local-lib-contained Additional module path (don't include non-core modules)
USAGE
exit 1;
}
sub short_usage {
my $self = shift;
$self->puts(<< 'USAGE');
Usage: pm-uninstall [options] Module [...]
Try `pm-uninstall --help` or `man pm-uninstall` for more options.
USAGE
exit 1;
}
sub prepare_include_paths {
my ($class, $inc) = @_;
my $new_inc = [];
my $archname = quotemeta $Config{archname};
for my $path (@$inc) {
push @$new_inc, $path;
next if $path eq '.' or $path =~ /$archname/;
push @$new_inc, File::Spec->catdir($path, $Config{archname});
}
return [do { my %h; grep !$h{$_}++, @$new_inc }];
}
( run in 1.291 second using v1.01-cache-2.11-cpan-39bf76dae61 )