Skip to content

Commit

Permalink
suppressed uninstall for core-module
Browse files Browse the repository at this point in the history
  • Loading branch information
xaicron committed Oct 23, 2010
1 parent fd9817f commit bd0a836
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ WriteMakefile(
'YAML' => 0,
'LWP::Simple' => 0,
'local::lib' => 0,
'Module::CoreList' => 0,
},
LICENSE => 'perl',
EXE_FILES => [ 'bin/pm-uninstall' ],
Expand Down
33 changes: 18 additions & 15 deletions bin/pm-uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ use ExtUtils::MakeMaker;
use LWP::Simple;
use YAML;
use CPAN::DistnameInfo;
use Module::CoreList;

my $perl_version = version->new($^V)->numify;

my $base_url = 'http://deps.cpantesters.org/depended-on-by.pl?dist=';
my $cpanmetadb = 'http://cpanmetadb.appspot.com/v1.0/package';
Expand Down Expand Up @@ -47,13 +50,20 @@ sub main {

for my $module (@modules) {
my($packlist, $dist, $vname) = find_packlist($module);
unless ($packlist) {
warn "Module $module not installed\n";

unless ($dist) {
warn "$module is not found.\n";
next;
}

if (is_core_module($dist)) {
warn "$dist is Core Module!! Can't be uninstall.\n";
next;
}

if ($opt->{force} or is_core_module($packlist)) {
next if lc(prompt("$dist is Core Module. Are you sure process?", 'n')) eq 'n';
unless ($packlist) {
warn "Module $module not installed.\n";
next;
}

if ($opt->{force} or ask_permission($module, $dist, $vname, $packlist, $opt->{local_lib})) {
Expand Down Expand Up @@ -92,7 +102,7 @@ sub ask_permission {
warn "$module is included in the distribution $dist and contains:\n\n";

for (fixup_packilist($packlist, $local_lib_base)) {
warn " $_";
warn " $_";
}
warn "\n";

Expand Down Expand Up @@ -127,19 +137,12 @@ sub find_packlist {
my $info = CPAN::DistnameInfo->new($meta->{distfile});

my $pl2 = locate_pack($info->dist);
return ($pl2, $info->dist, $info->distvname) if $pl2;

return;
return ($pl2, $info->dist, $info->distvname);
}

sub is_core_module {
my ($packlist) = @_;
for my $lib (@{[$Config{installprivlib}, $Config{installarchlib}]}) {
next unless $lib;
$lib = quotemeta $lib;
return 1 if $packlist =~ /^$lib/;
}
return;
my ($dist) = @_;
exists $Module::CoreList::version{$perl_version}{$dist} ? 1 : 0;
}

sub locate_pack {
Expand Down

0 comments on commit bd0a836

Please sign in to comment.