X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FExtUtils%2FPacklist.pm;h=eeb0a5b0c1c45fab31d1f2b93a10c8136852be76;hb=2bd2b9e04a68ec86766c4219cf4da7f0d3168395;hp=3ba1c8fe0455d2f5ddc52c6e16df06867075a95a;hpb=9b604809b69cab4edbbec886a40fb8a044651368;p=p5sagit%2Fp5-mst-13.2.git 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