This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pod nits from Simon Cozens <simon@brecon.co.uk> and others
[perl5.git] / lib / ExtUtils / Packlist.pm
index 3ba1c8f..eeb0a5b 100644 (file)
@@ -235,6 +235,52 @@ This returns the name of the associated .packlist file
 
 =back
 
+=head1 EXAMPLE
+
+Here's C<modrm>, 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 = <STDIN>; 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 <Alan.Burlison@uk.sun.com>