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, $type) = @_;
38 return(1) if ($type eq "all");
41 return($self->_is_prefix($path, $Config{installman1dir})
43 $self->_is_prefix($path, $Config{installman3dir})
48 return($self->_is_prefix($path, $Config{prefix})
50 !($Config{installman1dir} &&
51 $self->_is_prefix($path, $Config{installman1dir}))
53 !($Config{installman3dir} &&
54 $self->_is_prefix($path, $Config{installman3dir}))
62 my ($self, $path, @under) = @_;
63 $under[0] = "" if (! @under);
64 foreach my $dir (@under)
66 return(1) if ($self->_is_prefix($path, $dir));
74 $class = ref($class) || $class;
77 my $installarchlib = $Config{installarchlib};
78 my $archlib = $Config{archlib};
79 my $sitearch = $Config{sitearch};
83 $installarchlib =~ s|\\|/|g;
85 $sitearch =~ s|\\|/|g;
88 # Read the core packlist
89 $self->{Perl}{packlist} =
90 ExtUtils::Packlist->new( File::Spec->catfile($installarchlib, '.packlist') );
91 $self->{Perl}{version} = $Config{version};
93 # Read the module packlists
96 # Only process module .packlists
97 return if ($_) ne ".packlist" || $File::Find::dir eq $installarchlib;
99 # Hack of the leading bits of the paths & convert to a module name
100 my $module = $File::Find::name;
101 $module =~ s!\Q$archlib\E/auto/(.*)/.packlist!$1!s;
102 $module =~ s!\Q$sitearch\E/auto/(.*)/.packlist!$1!s;
103 my $modfile = "$module.pm";
106 # Find the top-level module file in @INC
107 $self->{$module}{version} = '';
108 foreach my $dir (@INC)
110 my $p = File::Spec->catfile($dir, $modfile);
113 $self->{$module}{version} = MM->parse_version($p);
119 $self->{$module}{packlist} = ExtUtils::Packlist->new($File::Find::name);
121 find($sub, $archlib, $sitearch);
123 return(bless($self, $class));
129 return(sort(keys(%$self)));
134 my ($self, $module, $type, @under) = @_;
137 Carp::croak("$module is not installed") if (! exists($self->{$module}));
138 $type = "all" if (! defined($type));
139 Carp::croak('type must be "all", "prog" or "doc"')
140 if ($type ne "all" && $type ne "prog" && $type ne "doc");
143 foreach my $file (keys(%{$self->{$module}{packlist}}))
146 if ($self->_is_type($file, $type) && $self->_is_under($file, @under));
151 sub directories($$;$)
153 my ($self, $module, $type, @under) = @_;
155 foreach my $file ($self->files($module, $type, @under))
157 $dirs{dirname($file)}++;
159 return(sort(keys(%dirs)));
162 sub directory_tree($$;$)
164 my ($self, $module, $type, @under) = @_;
166 foreach my $dir ($self->directories($module, $type, @under))
170 while ($last ne $dir)
173 $dir = dirname($dir);
174 last if (! $self->_is_under($dir, @under));
178 return(sort(keys(%dirs)));
183 my ($self, $module, $remove) = @_;
184 Carp::croak("$module is not installed") if (! exists($self->{$module}));
185 return($self->{$module}{packlist}->validate($remove));
190 my ($self, $module) = @_;
191 Carp::croak("$module is not installed") if (! exists($self->{$module}));
192 return($self->{$module}{packlist});
197 my ($self, $module) = @_;
198 Carp::croak("$module is not installed") if (! exists($self->{$module}));
199 return($self->{$module}{version});
212 ExtUtils::Installed - Inventory management of installed modules
216 use ExtUtils::Installed;
217 my ($inst) = ExtUtils::Installed->new();
218 my (@modules) = $inst->modules();
219 my (@missing) = $inst->validate("DBI");
220 my $all_files = $inst->files("DBI");
221 my $files_below_usr_local = $inst->files("DBI", "all", "/usr/local");
222 my $all_dirs = $inst->directories("DBI");
223 my $dirs_below_usr_local = $inst->directory_tree("DBI", "prog");
224 my $packlist = $inst->packlist("DBI");
228 ExtUtils::Installed provides a standard way to find out what core and module
229 files have been installed. It uses the information stored in .packlist files
230 created during installation to provide this information. In addition it
231 provides facilities to classify the installed files and to extract directory
232 information from the .packlist files.
236 The new() function searches for all the installed .packlists on the system, and
237 stores their contents. The .packlists can be queried with the functions
246 This takes no parameters, and searches for all the installed .packlists on the
247 system. The packlists are read using the ExtUtils::packlist module.
251 This returns a list of the names of all the installed modules. The perl 'core'
252 is given the special name 'Perl'.
256 This takes one mandatory parameter, the name of a module. It returns a list of
257 all the filenames from the package. To obtain a list of core perl files, use
258 the module name 'Perl'. Additional parameters are allowed. The first is one
259 of the strings "prog", "man" or "all", to select either just program files,
260 just manual files or all files. The remaining parameters are a list of
261 directories. The filenames returned will be restricted to those under the
262 specified directories.
266 This takes one mandatory parameter, the name of a module. It returns a list of
267 all the directories from the package. Additional parameters are allowed. The
268 first is one of the strings "prog", "man" or "all", to select either just
269 program directories, just manual directories or all directories. The remaining
270 parameters are a list of directories. The directories returned will be
271 restricted to those under the specified directories. This method returns only
272 the leaf directories that contain files from the specified module.
274 =item directory_tree()
276 This is identical in operation to directory(), except that it includes all the
277 intermediate directories back up to the specified directories.
281 This takes one mandatory parameter, the name of a module. It checks that all
282 the files listed in the modules .packlist actually exist, and returns a list of
283 any missing files. If an optional second argument which evaluates to true is
284 given any missing files will be removed from the .packlist
288 This returns the ExtUtils::Packlist object for the specified module.
292 This returns the version number for the specified module.
298 See the example in L<ExtUtils::Packlist>.
302 Alan Burlison <Alan.Burlison@uk.sun.com>