- push @dirs, $Config{sitearchexp}, $Config{archlibexp}; + unshift @dirs, $Config{sitearchexp}, $Config{archlibexp}; #### #!/usr/bin/perl ############################################################### # Uninstallation of perl modules ################################################################ use strict; use warnings; # Need a patched version of ExtUtils::Installed to allow you # to uninstall from locations other than the standard perl libs use lib '/home/bsm/johnston/casspm/lib/perl5'; use Config; use ExtUtils::Installed; use Cwd; use Data::Dumper; my @locallibs; ######################### #get @locallibs - create a ~/.myperllibs file if necessary ######################### my $cwd = getcwd; chdir(); unless (-e ".myperllibs") { #get any libraries the user wants to add print "\n#####\nI can't find a list of your user perl libraries\n". "I will create one for you now.\nTo add libraries to it in the future, just add them to the file .myperllibs in your home directory.\nOne directory path per line.\nStandard installation libraries like /usr/local/lib or /usr/lib will be used anyway - you don't need to add them to your file.\n#####\n\n". "Would you like to add any libraries now?[y|n]\n"; if (<>=~/y|Y/) { print "\nEnter your library paths, seperated by spaces\n:"; @locallibs = split(/\s/, <>); } #create a new file open LIBFILE, '>.myperllibs' or die "\n####\nSorry, I don't seem to be able to make a ~/.myperllibs file.\nTry creating a file called:\n\t'.myperllibs'\nin your home directory.\n####\n\n"; #write libraries (if any) to the file foreach (@locallibs){ print LIBFILE "$_\n"; } close LIBFILE; print "\nCreated library list in your home directory (.myperllibs)\n\n"; if (@locallibs){ print "Added libraries:\n"; map {print "$_\n"} @locallibs; print "\n"; } } open LIBFILE, '<.myperllibs' or die "Can't open library file, but it exists.\nGuess it might be a permissions problem?\n"; @locallibs = unless @locallibs; close LIBFILE; chomp @locallibs; chdir($cwd); ##################################################### # what are we uninstalling and where from? ##################################################### print "Which modules would you like to uninstall?\n". "Enter their names, seperated by spaces\n"; my @mods = split(/\s/,<>); print "\nDo you want to look in the default libraries:\n". "\t$Config{archlibexp} and \n". "\t$Config{sitearchexp} ?\n". "('n' will use only libs in your .myperllibs file)\n". "[y|n]\n"; my $justmylibs = (<>=~/y|Y/) ? 0 : 1 ; print "Uninstalling modules:\n"; foreach (@mods) { print "\t$_\n"; } print "Looking in directories:\n"; unless ($justmylibs) { print "\t$Config{archlibexp}\n\t$Config{sitearchexp}\n"; } foreach (@locallibs) { print "\t$_\n"; } print "\nOK to continue?\n't' will do a test uninstall (doesn't remove any files)\n [y|n|t]\n"; my $ans = <>; die "bye" unless ($ans=~/y|Y|t|T/); my $testing = $ans =~/t|T/ ? 1 : 0; #################################################### # Do the uninstallation #################################################### foreach (@mods) { my $inst = ExtUtils::Installed->new(@locallibs); my $found = $justmylibs ? 0 : 1; foreach my $item (sort($inst->files($_))) { if ($justmylibs) { #ignore everything in default libs if( map {$item=~/$_/} @locallibs){ $found = 1; } else{ next; } } print "removing $item\n"; unlink $item unless $testing; } unless ($found) { print "\n$_ doesn't seem to be installed in:\n"; print "\t$_\n" foreach (@locallibs); print "If you're sure it's there try deleting the files by hand.\nSorry I can't be more help...\n"; next; } my $packfile = $inst->packlist($_)->packlist_file(); print "removing $packfile\n"; unlink $packfile unless $testing; }