Lovely, thanks!
Can I change
- push @dirs, $Config{sitearchexp}, $Config{archlibexp};
+ unshift @dirs, $Config{sitearchexp}, $Config{archlibexp};
because $sub (in ExtUtils::Installed->new)loops through the @dir array and sets $self->{module}{packlist} so if we push them on then if a module is installed in the dir you specified and in say /usr/local, we will always get back the packlist for /usr/local - which isn't very helpful if you want to uninstall something in a local directory. If you want the /usr/local version, just don't give a local dir in the call to new.
If that change is OK, then I wrote a quick thing for easy command line uninstall. Spot any glaring errors?
#!/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 th
+e future, just add them to the file .myperllibs in your home director
+y.\nOne directory path per line.\nStandard installation libraries lik
+e /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 e
+xists.\nGuess it might be a permissions problem?\n";
@locallibs = <LIBFILE> 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;
}