1 package ExtUtils::Installed;
6 use ExtUtils::Packlist;
7 use ExtUtils::MakeMaker;
11 our $VERSION = '0.02';
15 my ($self, $path, $type) = @_;
16 return(1) if ($type eq "all");
19 return(substr($path, 0, length($Config{installman1dir}))
20 eq $Config{installman1dir}
22 substr($path, 0, length($Config{installman3dir}))
23 eq $Config{installman3dir}
28 return(substr($path, 0, length($Config{prefix})) eq $Config{prefix}
30 substr($path, 0, length($Config{installman1dir}))
31 ne $Config{installman1dir}
33 substr($path, 0, length($Config{installman3dir}))
34 ne $Config{installman3dir}
42 my ($self, $path, @under) = @_;
43 $under[0] = "" if (! @under);
44 foreach my $dir (@under)
46 return(1) if (substr($path, 0, length($dir)) eq $dir);
54 $class = ref($class) || $class;
57 # Read the core packlist
58 $self->{Perl}{packlist} =
59 ExtUtils::Packlist->new("$Config{installarchlib}/.packlist");
60 $self->{Perl}{version} = $Config{version};
62 # Read the module packlists
65 # Only process module .packlists
66 return if ($_) ne ".packlist" || $File::Find::dir eq $Config{installarchlib};
68 # Hack of the leading bits of the paths & convert to a module name
69 my $module = $File::Find::name;
70 $module =~ s!$Config{archlib}/auto/(.*)/.packlist!$1!;
71 $module =~ s!$Config{sitearch}/auto/(.*)/.packlist!$1!;
72 my $modfile = "$module.pm";
75 # Find the top-level module file in @INC
76 $self->{$module}{version} = '';
77 foreach my $dir (@INC)
79 my $p = MM->catfile($dir, $modfile);
82 $self->{$module}{version} = MM->parse_version($p);
88 $self->{$module}{packlist} = ExtUtils::Packlist->new($File::Find::name);
90 find($sub, $Config{archlib}, $Config{sitearch});
92 return(bless($self, $class));
98 return(sort(keys(%$self)));
103 my ($self, $module, $type, @under) = @_;
106 Carp::croak("$module is not installed") if (! exists($self->{$module}));
107 $type = "all" if (! defined($type));
108 Carp::croak('type must be "all", "prog" or "doc"')
109 if ($type ne "all" && $type ne "prog" && $type ne "doc");
112 foreach my $file (keys(%{$self->{$module}{packlist}}))
115 if ($self->_is_type($file, $type) && $self->_is_under($file, @under));
120 sub directories($$;$)
122 my ($self, $module, $type, @under) = @_;
124 foreach my $file ($self->files($module, $type, @under))
126 $dirs{dirname($file)}++;
128 return(sort(keys(%dirs)));
131 sub directory_tree($$;$)
133 my ($self, $module, $type, @under) = @_;
135 foreach my $dir ($self->directories($module, $type, @under))
139 while ($last ne $dir)
142 $dir = dirname($dir);
143 last if (! $self->_is_under($dir, @under));
147 return(sort(keys(%dirs)));
152 my ($self, $module, $remove) = @_;
153 Carp::croak("$module is not installed") if (! exists($self->{$module}));
154 return($self->{$module}{packlist}->validate($remove));
159 my ($self, $module) = @_;
160 Carp::croak("$module is not installed") if (! exists($self->{$module}));
161 return($self->{$module}{packlist});
166 my ($self, $module) = @_;
167 Carp::croak("$module is not installed") if (! exists($self->{$module}));
168 return($self->{$module}{version});
181 ExtUtils::Installed - Inventory management of installed modules
185 use ExtUtils::Installed;
186 my ($inst) = ExtUtils::Installed->new();
187 my (@modules) = $inst->modules();
188 my (@missing) = $inst->validate("DBI");
189 my $all_files = $inst->files("DBI");
190 my $files_below_usr_local = $inst->files("DBI", "all", "/usr/local");
191 my $all_dirs = $inst->directories("DBI");
192 my $dirs_below_usr_local = $inst->directory_tree("DBI", "prog");
193 my $packlist = $inst->packlist("DBI");
197 ExtUtils::Installed provides a standard way to find out what core and module
198 files have been installed. It uses the information stored in .packlist files
199 created during installation to provide this information. In addition it
200 provides facilities to classify the installed files and to extract directory
201 information from the .packlist files.
205 The new() function searches for all the installed .packlists on the system, and
206 stores their contents. The .packlists can be queried with the functions
215 This takes no parameters, and searches for all the installed .packlists on the
216 system. The packlists are read using the ExtUtils::packlist module.
220 This returns a list of the names of all the installed modules. The perl 'core'
221 is given the special name 'Perl'.
225 This takes one mandatory parameter, the name of a module. It returns a list of
226 all the filenames from the package. To obtain a list of core perl files, use
227 the module name 'Perl'. Additional parameters are allowed. The first is one
228 of the strings "prog", "man" or "all", to select either just program files,
229 just manual files or all files. The remaining parameters are a list of
230 directories. The filenames returned will be restricted to those under the
231 specified directories.
235 This takes one mandatory parameter, the name of a module. It returns a list of
236 all the directories from the package. Additional parameters are allowed. The
237 first is one of the strings "prog", "man" or "all", to select either just
238 program directories, just manual directories or all directories. The remaining
239 parameters are a list of directories. The directories returned will be
240 restricted to those under the specified directories. This method returns only
241 the leaf directories that contain files from the specified module.
243 =item directory_tree()
245 This is identical in operation to directory(), except that it includes all the
246 intermediate directories back up to the specified directories.
250 This takes one mandatory parameter, the name of a module. It checks that all
251 the files listed in the modules .packlist actually exist, and returns a list of
252 any missing files. If an optional second argument which evaluates to true is
253 given any missing files will be removed from the .packlist
257 This returns the ExtUtils::Packlist object for the specified module.
261 This returns the version number for the specified module.
267 See the example in L<ExtUtils::Packlist>.
271 Alan Burlison <Alan.Burlison@uk.sun.com>