1 package ExtUtils::Installed;
6 use ExtUtils::Packlist;
7 use ExtUtils::MakeMaker;
12 our $VERSION = '0.04';
14 my $DOSISH = ($^O =~ /^(MSWin\d\d|os2|dos|mint)$/);
18 my ($self, $path, $prefix) = @_;
19 if (substr($path, 0, length($prefix)) eq $prefix)
27 if ($path =~ m{^\Q$prefix\E}i)
37 my ($self, $path) = @_;
38 my $man1dir = $Config{man1direxp};
39 my $man3dir = $Config{man3direxp};
40 return(($man1dir && $self->_is_prefix($path, $man1dir))
42 ($man3dir && $self->_is_prefix($path, $man3dir))
48 my ($self, $path, $type) = @_;
49 return(1) if ($type eq "all");
53 return($self->_is_doc($path))
57 return($self->_is_prefix($path, $Config{prefixexp})
59 !($self->_is_doc($path))
67 my ($self, $path, @under) = @_;
68 $under[0] = "" if (! @under);
69 foreach my $dir (@under)
71 return(1) if ($self->_is_prefix($path, $dir));
79 $class = ref($class) || $class;
82 my $archlib = $Config{archlibexp};
83 my $sitearch = $Config{sitearchexp};
88 $sitearch =~ s|\\|/|g;
91 # Read the core packlist
92 $self->{Perl}{packlist} =
93 ExtUtils::Packlist->new( File::Spec->catfile($archlib, '.packlist') );
94 $self->{Perl}{version} = $Config{version};
96 # Read the module packlists
99 # Only process module .packlists
100 return if ($_) ne ".packlist" || $File::Find::dir eq $archlib;
102 # Hack of the leading bits of the paths & convert to a module name
103 my $module = $File::Find::name;
104 $module =~ s!\Q$archlib\E/auto/(.*)/.packlist!$1!s;
105 $module =~ s!\Q$sitearch\E/auto/(.*)/.packlist!$1!s;
106 my $modfile = "$module.pm";
109 # Find the top-level module file in @INC
110 $self->{$module}{version} = '';
111 foreach my $dir (@INC)
113 my $p = File::Spec->catfile($dir, $modfile);
116 $self->{$module}{version} = MM->parse_version($p);
122 $self->{$module}{packlist} = ExtUtils::Packlist->new($File::Find::name);
124 find($sub, $archlib, $sitearch);
126 return(bless($self, $class));
132 return(sort(keys(%$self)));
137 my ($self, $module, $type, @under) = @_;
140 Carp::croak("$module is not installed") if (! exists($self->{$module}));
141 $type = "all" if (! defined($type));
142 Carp::croak('type must be "all", "prog" or "doc"')
143 if ($type ne "all" && $type ne "prog" && $type ne "doc");
146 foreach my $file (keys(%{$self->{$module}{packlist}}))
149 if ($self->_is_type($file, $type) && $self->_is_under($file, @under));
154 sub directories($$;$)
156 my ($self, $module, $type, @under) = @_;
158 foreach my $file ($self->files($module, $type, @under))
160 $dirs{dirname($file)}++;
162 return(sort(keys(%dirs)));
165 sub directory_tree($$;$)
167 my ($self, $module, $type, @under) = @_;
169 foreach my $dir ($self->directories($module, $type, @under))
173 while ($last ne $dir)
176 $dir = dirname($dir);
177 last if (! $self->_is_under($dir, @under));
181 return(sort(keys(%dirs)));
186 my ($self, $module, $remove) = @_;
187 Carp::croak("$module is not installed") if (! exists($self->{$module}));
188 return($self->{$module}{packlist}->validate($remove));
193 my ($self, $module) = @_;
194 Carp::croak("$module is not installed") if (! exists($self->{$module}));
195 return($self->{$module}{packlist});
200 my ($self, $module) = @_;
201 Carp::croak("$module is not installed") if (! exists($self->{$module}));
202 return($self->{$module}{version});
215 ExtUtils::Installed - Inventory management of installed modules
219 use ExtUtils::Installed;
220 my ($inst) = ExtUtils::Installed->new();
221 my (@modules) = $inst->modules();
222 my (@missing) = $inst->validate("DBI");
223 my $all_files = $inst->files("DBI");
224 my $files_below_usr_local = $inst->files("DBI", "all", "/usr/local");
225 my $all_dirs = $inst->directories("DBI");
226 my $dirs_below_usr_local = $inst->directory_tree("DBI", "prog");
227 my $packlist = $inst->packlist("DBI");
231 ExtUtils::Installed provides a standard way to find out what core and module
232 files have been installed. It uses the information stored in .packlist files
233 created during installation to provide this information. In addition it
234 provides facilities to classify the installed files and to extract directory
235 information from the .packlist files.
239 The new() function searches for all the installed .packlists on the system, and
240 stores their contents. The .packlists can be queried with the functions
249 This takes no parameters, and searches for all the installed .packlists on the
250 system. The packlists are read using the ExtUtils::packlist module.
254 This returns a list of the names of all the installed modules. The perl 'core'
255 is given the special name 'Perl'.
259 This takes one mandatory parameter, the name of a module. It returns a list of
260 all the filenames from the package. To obtain a list of core perl files, use
261 the module name 'Perl'. Additional parameters are allowed. The first is one
262 of the strings "prog", "doc" or "all", to select either just program files,
263 just manual files or all files. The remaining parameters are a list of
264 directories. The filenames returned will be restricted to those under the
265 specified directories.
269 This takes one mandatory parameter, the name of a module. It returns a list of
270 all the directories from the package. Additional parameters are allowed. The
271 first is one of the strings "prog", "doc" or "all", to select either just
272 program directories, just manual directories or all directories. The remaining
273 parameters are a list of directories. The directories returned will be
274 restricted to those under the specified directories. This method returns only
275 the leaf directories that contain files from the specified module.
277 =item directory_tree()
279 This is identical in operation to directories(), except that it includes all the
280 intermediate directories back up to the specified directories.
284 This takes one mandatory parameter, the name of a module. It checks that all
285 the files listed in the modules .packlist actually exist, and returns a list of
286 any missing files. If an optional second argument which evaluates to true is
287 given any missing files will be removed from the .packlist
291 This returns the ExtUtils::Packlist object for the specified module.
295 This returns the version number for the specified module.
301 See the example in L<ExtUtils::Packlist>.
305 Alan Burlison <Alan.Burlison@uk.sun.com>