Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: uninstalling modules

by gellyfish (Monsignor)
on Jul 20, 2004 at 12:42 UTC ( [id://375881]=note: print w/replies, xml ) Need Help??


in reply to uninstalling modules

ExtUtils::Installed uses the $Config{sitearchlibexp} and $Config{archlibexp} values as defined in the Config module - you can assign the appropriate values to these before you call ExtUtils::Installed->new() and everything should work fine.

/J\

Replies are listed 'Best First'.
Re^2: uninstalling modules
by CassJ (Sexton) on Jul 20, 2004 at 15:03 UTC
    I'm probably being deeply gormless, but I can't figure out how to do what you suggest.
    I don't have write access to Config.pm file and if I use it and try to change the values in the hash it just tells me that it's read-only (does this mean it's tied to the file?). How can I fake these values for the duration of my call to ExtUtils::Installed->new()? I thought maybe I could copy the file to the lib I was using, correcting the lines on the way, but then how do I make sure that my fake Config.pm is used in preference to the real one in /usr/local?

    thanks again!

    Cxx

      No it's not you at all. I have made a patch for ExtUtils::Installed that will allow you to supply a list of locations which are outside the perl install prefix - I need to add some tests and change the documentation before I send it to p5p but this:

      --- Installed.pm.orig 2004-07-20 16:37:50.000000000 +0100 +++ Installed.pm 2004-07-20 17:23:53.000000000 +0100 @@ -77,24 +77,32 @@ } sub new { - my ($class) = @_; + my ($class, @dirs) = @_; $class = ref($class) || $class; my $self = {}; - my $archlib = $Config{archlibexp}; - my $sitearch = $Config{sitearchexp}; + push @dirs, $Config{sitearchexp}, $Config{archlibexp}; # File::Find does not know how to deal with VMS filepaths. - if( $Is_VMS ) { - $archlib = VMS::Filespec::unixify($archlib); - $sitearch = VMS::Filespec::unixify($sitearch); - } - if ($DOSISH) { - $archlib =~ s|\\|/|g; - $sitearch =~ s|\\|/|g; + foreach ( @dirs ) { + if (!m!$Config{archname}/?$!) { + $_ = File::Spec->catfile($_, $Config{archname}); + } + + if( $Is_VMS ) { + $_ = VMS::Filespec::unixify($_); + } + + if ($DOSISH) { + s|\\|/|g; + } + } + my $archlib = @dirs[-1]; + + # Read the core packlist $self->{Perl}{packlist} = ExtUtils::Packlist->new( File::Spec->catfile($archlib, '.packli +st') ); @@ -108,11 +116,15 @@ # Hack of the leading bits of the paths & convert to a module + name my $module = $File::Find::name; - $module =~ s!\Q$archlib\E/?auto/(.*)/.packlist!$1!s or - $module =~ s!\Q$sitearch\E/?auto/(.*)/.packlist!$1!s; + + foreach my $dir ( @dirs ) { + $module =~ s!\Q$dir\E/?auto/(.*)/.packlist!$1!s and last; + } + my $modfile = "$module.pm"; $module =~ s!/!::!g; + print $module,"\n"; # Find the top-level module file in @INC $self->{$module}{version} = ''; foreach my $dir (@INC) { @@ -131,8 +143,8 @@ ExtUtils::Packlist->new($File::Find::name); }; - my(@dirs) = grep { -e } ($archlib, $sitearch); - find($sub, @dirs) if @dirs; + my(@search_dirs) = grep { -e } (@dirs); + find($sub, @search_dirs) if @search_dirs; return(bless($self, $class)); }
      Will allow you to do something like:
      use ExtUtils::Installed; + + use lib qw( /home/jonathan/foo/lib/perl5/site_perl/5.8.1); + my $ff = ExtUtils::Installed->new('/home/jonathan/foo/lib/perl5/site_p +erl/5.8.1'); + print $ff->files('Foo','all');
      where I have installed the module 'Foo' with a PREFIX of '/home/jonathan/foo'

      /J\

        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; }
Re^2: uninstalling modules
by Anonymous Monk on Jul 20, 2004 at 12:53 UTC
    How do you know that?

      Er, because I looked at the code ....

      /J\

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://375881]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-20 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found