package ExtUtils
::Installed
;
my $Is_VMS = $^O
eq 'VMS';
my $DOSISH = ($^O
=~ /^(MSWin\d\d|os2|dos|mint)$/);
require VMS
::Filespec
if $Is_VMS;
my ($self, $path, $prefix) = @_;
return unless defined $prefix && defined $path;
$prefix = VMS::Filespec::unixify($prefix);
$path = VMS::Filespec::unixify($path);
# Sloppy Unix path normalization.
return 1 if substr($path, 0, length($prefix)) eq $prefix;
return 1 if $path =~ m{^\Q$prefix\E}i;
my $man1dir = $Config{man1direxp};
my $man3dir = $Config{man3direxp};
return(($man1dir && $self->_is_prefix($path, $man1dir))
($man3dir && $self->_is_prefix($path, $man3dir))
my ($self, $path, $type) = @_;
return 1 if $type eq "all";
return($self->_is_doc($path)) if $type eq "doc";
return($self->_is_prefix($path, $Config{prefix} || $Config{prefixexp})
my ($self, $path, @under) = @_;
$under[0] = "" if (! @under);
foreach my $dir (@under) {
return(1) if ($self->_is_prefix($path, $dir));
$class = ref($class) || $class;
my $archlib = $Config{archlibexp};
my $sitearch = $Config{sitearchexp};
# File::Find does not know how to deal with VMS filepaths.
$archlib = VMS::Filespec::unixify($archlib);
$sitearch = VMS::Filespec::unixify($sitearch);
$self->{Perl}{packlist} =
ExtUtils::Packlist->new( File::Spec->catfile($archlib, '.packlist') );
$self->{Perl}{version} = $Config{version};
# Read the module packlists
# Only process module .packlists
return if $_ ne ".packlist" || $File::Find::dir eq $archlib;
# Hack of the leading bits of the paths & convert to a module name
my $module = $File::Find::name;
$module =~ s!\Q$archlib\E/?auto/(.*)/.packlist!$1!s or
$module =~ s!\Q$sitearch\E/?auto/(.*)/.packlist!$1!s;
my $modfile = "$module.pm";
# Find the top-level module file in @INC
$self->{$module}{version} = '';
my $p = File::Spec->catfile($dir, $modfile);
$module = _module_name($p, $module) if $Is_VMS;
$self->{$module}{version} = MM->parse_version($p);
$self->{$module}{packlist} =
ExtUtils::Packlist->new($File::Find::name);
my(@dirs) = grep { -e } ($archlib, $sitearch);
find($sub, @dirs) if @dirs;
return(bless($self, $class));
# VMS's non-case preserving file-system means the package name can't
# be reconstructed from the filename.
my($file, $orig_module) = @_;
if (open PACKFH, $file) {
if (/package\s+(\S+)\s*;/) {
# Make a sanity check, that lower case $module
# is identical to lowercase $pack before
if (lc($pack) eq lc($orig_module)) {
print STDERR "Couldn't figure out the package name for $file\n"
# Bug/feature of sort in scalar context requires this.
return wantarray ? sort keys %$self : keys %$self;
my ($self, $module, $type, @under) = @_;
Carp::croak("$module is not installed") if (! exists($self->{$module}));
$type = "all" if (! defined($type));
Carp::croak('type must be "all", "prog" or "doc"')
if ($type ne "all" && $type ne "prog" && $type ne "doc");
foreach my $file (keys(%{$self->{$module}{packlist}})) {
if ($self->_is_type($file, $type) &&
$self->_is_under($file, @under));
my ($self, $module, $type, @under) = @_;
foreach my $file ($self->files($module, $type, @under)) {
my ($self, $module, $type, @under) = @_;
foreach my $dir ($self->directories($module, $type, @under)) {
last if !$self->_is_under($dir, @under);
return(sort(keys(%dirs)));
my ($self, $module, $remove) = @_;
Carp::croak("$module is not installed") if (! exists($self->{$module}));
return($self->{$module}{packlist}->validate($remove));
my ($self, $module) = @_;
Carp::croak("$module is not installed") if (! exists($self->{$module}));
return($self->{$module}{packlist});
my ($self, $module) = @_;
Carp::croak("$module is not installed") if (! exists($self->{$module}));
return($self->{$module}{version});
ExtUtils::Installed - Inventory management of installed modules
my ($inst) = ExtUtils::Installed->new();
my (@modules) = $inst->modules();
my (@missing) = $inst->validate("DBI");
my $all_files = $inst->files("DBI");
my $files_below_usr_local = $inst->files("DBI", "all", "/usr/local");
my $all_dirs = $inst->directories("DBI");
my $dirs_below_usr_local = $inst->directory_tree("DBI", "prog");
my $packlist = $inst->packlist("DBI");
ExtUtils::Installed provides a standard way to find out what core and module
files have been installed. It uses the information stored in .packlist files
created during installation to provide this information. In addition it
provides facilities to classify the installed files and to extract directory
information from the .packlist files.
The new() function searches for all the installed .packlists on the system, and
stores their contents. The .packlists can be queried with the functions
This takes no parameters, and searches for all the installed .packlists on the
system. The packlists are read using the ExtUtils::packlist module.
This returns a list of the names of all the installed modules. The perl 'core'
is given the special name 'Perl'.
This takes one mandatory parameter, the name of a module. It returns a list of
all the filenames from the package. To obtain a list of core perl files, use
the module name 'Perl'. Additional parameters are allowed. The first is one
of the strings "prog", "doc" or "all", to select either just program files,
just manual files or all files. The remaining parameters are a list of
directories. The filenames returned will be restricted to those under the
This takes one mandatory parameter, the name of a module. It returns a list of
all the directories from the package. Additional parameters are allowed. The
first is one of the strings "prog", "doc" or "all", to select either just
program directories, just manual directories or all directories. The remaining
parameters are a list of directories. The directories returned will be
restricted to those under the specified directories. This method returns only
the leaf directories that contain files from the specified module.
This is identical in operation to directories(), except that it includes all the
intermediate directories back up to the specified directories.
This takes one mandatory parameter, the name of a module. It checks that all
the files listed in the modules .packlist actually exist, and returns a list of
any missing files. If an optional second argument which evaluates to true is
given any missing files will be removed from the .packlist
This returns the ExtUtils::Packlist object for the specified module.
This returns the version number for the specified module.
See the example in L<ExtUtils::Packlist>.