From: Alan Burlison Date: Fri, 3 Jul 1998 11:28:03 +0000 (+0100) Subject: add suggested tool as an example in ExtUtils::Packlist X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ddf41153d84059bfb9eed5a5c9fa0aef2cb074e0;p=p5sagit%2Fp5-mst-13.2.git add suggested tool as an example in ExtUtils::Packlist Message-Id: <199807031028.LAA10456@sale-wts> Subject: Re: [make install] another horror story p4raw-id: //depot/perl@1315 --- diff --git a/lib/ExtUtils/Installed.pm b/lib/ExtUtils/Installed.pm index 0ee1f50..dda594e 100644 --- a/lib/ExtUtils/Installed.pm +++ b/lib/ExtUtils/Installed.pm @@ -261,6 +261,10 @@ This returns the version number for the specified module. =back +=head1 EXAMPLE + +See the example in L. + =head1 AUTHOR Alan Burlison diff --git a/lib/ExtUtils/Packlist.pm b/lib/ExtUtils/Packlist.pm index 3ba1c8f..eeb0a5b 100644 --- a/lib/ExtUtils/Packlist.pm +++ b/lib/ExtUtils/Packlist.pm @@ -235,6 +235,52 @@ This returns the name of the associated .packlist file =back +=head1 EXAMPLE + +Here's C, a little utility to cleanly remove an installed module. + + #!/usr/local/bin/perl -w + + use strict; + use IO::Dir; + use ExtUtils::Packlist; + use ExtUtils::Installed; + + sub emptydir($) { + my ($dir) = @_; + my $dh = IO::Dir->new($dir) || return(0); + my @count = $dh->read(); + $dh->close(); + return(@count == 2 ? 1 : 0); + } + + # Find all the installed packages + print("Finding all installed modules...\n"); + my $installed = ExtUtils::Installed->new(); + + foreach my $module (grep(!/^Perl$/, $installed->modules())) { + my $version = $installed->version($module) || "???"; + print("Found module $module Version $version\n"); + print("Do you want to delete $module? [n] "); + my $r = ; chomp($r); + if ($r && $r =~ /^y/i) { + # Remove all the files + foreach my $file (sort($installed->files($module))) { + print("rm $file\n"); + unlink($file); + } + my $pf = $installed->packlist($module)->packlist_file(); + print("rm $pf\n"); + unlink($pf); + foreach my $dir (sort($installed->directory_tree($module))) { + if (emptydir($dir)) { + print("rmdir $dir\n"); + rmdir($dir); + } + } + } + } + =head1 AUTHOR Alan Burlison