This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add some basic POD to lib/ExtUtils/instmodsh so that
[perl5.git] / lib / ExtUtils / instmodsh
CommitLineData
03c94fc2 1#!/usr/bin/perl -w
354f3b56
AB
2
3use strict;
4use IO::File;
5use ExtUtils::Packlist;
6use ExtUtils::Installed;
7
8use vars qw($Inst @Modules);
9
a7d1454b
RGS
10
11=head1 NAME
12
13instmodsh - A shell to examine installed modules
14
15=head1 SYNOPSIS
16
17 instmodsh
18
19=head1 DESCRIPTION
20
21A little interface to ExtUtils::Installed to examine installed modules,
22validate your packlists and even create a tarball from an installed module.
23
24=cut
25
354f3b56 26
03c94fc2 27my $Module_Help = <<EOF;
354f3b56
AB
28Available commands are:
29 f [all|prog|doc] - List installed files of a given type
30 d [all|prog|doc] - List the directories used by a module
31 v - Validate the .packlist - check for missing files
32 t <tarfile> - Create a tar archive of the module
03c94fc2 33 h - Display module help
354f3b56
AB
34 q - Quit the module
35EOF
03c94fc2
RGS
36
37my %Module_Commands = (
38 f => \&list_installed,
39 d => \&list_directories,
40 v => \&validate_packlist,
41 t => \&create_archive,
42 h => \&module_help,
43 );
44
45sub do_module($) {
46 my ($module) = @_;
47
48 print($Module_Help);
49 MODULE_CMD: while (1) {
50 print("$module cmd? ");
51
52 my $reply = <STDIN>; chomp($reply);
53 my($cmd) = $reply =~ /^(\w)\b/;
54
55 last if $cmd eq 'q';
56
57 if( $Module_Commands{$cmd} ) {
58 $Module_Commands{$cmd}->($reply, $module);
59 }
60 elsif( $cmd eq 'q' ) {
61 last MODULE_CMD;
62 }
63 else {
64 module_help();
65 }
66 }
67}
68
69
70sub list_installed {
71 my($reply, $module) = @_;
72
73 my $class = (split(' ', $reply))[1];
74 $class = 'all' unless $class;
75
76 my @files;
77 if (eval { @files = $Inst->files($module, $class); }) {
78 print("$class files in $module are:\n ",
79 join("\n ", @files), "\n");
80 }
81 else {
82 print($@);
83 }
84};
85
86
87sub list_directories {
88 my($reply, $module) = @_;
89
90 my $class = (split(' ', $reply))[1];
91 $class = 'all' unless $class;
92
93 my @dirs;
94 if (eval { @dirs = $Inst->directories($module, $class); }) {
95 print("$class directories in $module are:\n ",
96 join("\n ", @dirs), "\n");
97 }
98 else {
99 print($@);
100 }
354f3b56
AB
101}
102
03c94fc2
RGS
103
104sub create_archive {
105 my($reply, $module) = @_;
106
107 my $file = (split(' ', $reply))[1];
03c94fc2
RGS
108
109 if( !(defined $file and length $file) ) {
110 print "No tar file specified\n";
111 }
112 elsif( eval { require Archive::Tar } ) {
113 Archive::Tar->create_archive($file, 0, $Inst->files($module));
114 }
115 else {
116 my($first, @rest) = $Inst->files($module);
117 system('tar', 'cvf', $file, $first);
118 for my $f (@rest) {
119 system('tar', 'rvf', $file, $f);
120 }
121 print "Can't use tar\n" if $?;
122 }
123}
124
125
126sub validate_packlist {
127 my($reply, $module) = @_;
128
129 if (my @missing = $Inst->validate($module)) {
130 print("Files missing from $module are:\n ",
131 join("\n ", @missing), "\n");
132 }
133 else {
134 print("$module has no missing files\n");
135 }
136}
137
138sub module_help {
139 print $Module_Help;
140}
141
142
143
144##############################################################################
354f3b56
AB
145
146sub toplevel()
147{
148my $help = <<EOF;
149Available commands are:
150 l - List all installed modules
151 m <module> - Select a module
152 q - Quit the program
153EOF
154print($help);
155while (1)
156 {
157 print("cmd? ");
158 my $reply = <STDIN>; chomp($reply);
159 CASE:
160 {
161 $reply eq 'l' and do
162 {
163 print("Installed modules are:\n ", join("\n ", @Modules), "\n");
164 last CASE;
165 };
166 $reply =~ /^m\s+/ and do
167 {
168 do_module((split(' ', $reply))[1]);
169 last CASE;
170 };
171 $reply eq 'q' and do
172 {
173 exit(0);
174 };
175 # Default
176 print($help);
177 }
178 }
179}
180
03c94fc2
RGS
181
182###############################################################################
354f3b56
AB
183
184$Inst = ExtUtils::Installed->new();
185@Modules = $Inst->modules();
186toplevel();
187
03c94fc2 188###############################################################################
791eb772
BD
189
190__END__
191
192=head1 NAME
193
194instmodsh - interactive inventory for installed Perl modules
195
196=head1 SYNOPSIS
197
198instmodsh
199
200=head1 DESCRIPTION
201
202C<instmodsh> provides an interactive shell to query details of
203installed Perl modules.
204
205The shell provides a list of installed modules, each of which
206may be queried to to list files and directories, checked for missing
207files or packaged up as a tar archive.
208
209=head1 SEE ALSO
210
211ExtUtils::Installed(3perl)
212
213=cut