1 package ExtUtils::Installed;
6 use ExtUtils::Packlist;
7 use ExtUtils::MakeMaker;
13 my $Is_VMS = $^O eq 'VMS';
14 my $DOSISH = ($^O =~ /^(MSWin\d\d|os2|dos|mint)$/);
16 require VMS::Filespec if $Is_VMS;
18 use vars qw($VERSION);
22 my ($self, $path, $prefix) = @_;
23 return unless defined $prefix && defined $path;
26 $prefix = VMS::Filespec::unixify($prefix);
27 $path = VMS::Filespec::unixify($path);
30 # Sloppy Unix path normalization.
34 return 1 if substr($path, 0, length($prefix)) eq $prefix;
39 return 1 if $path =~ m{^\Q$prefix\E}i;
45 my ($self, $path) = @_;
46 my $man1dir = $Config{man1direxp};
47 my $man3dir = $Config{man3direxp};
48 return(($man1dir && $self->_is_prefix($path, $man1dir))
50 ($man3dir && $self->_is_prefix($path, $man3dir))
55 my ($self, $path, $type) = @_;
56 return 1 if $type eq "all";
58 return($self->_is_doc($path)) if $type eq "doc";
60 if ($type eq "prog") {
61 return($self->_is_prefix($path, $Config{prefix} || $Config{prefixexp})
63 !($self->_is_doc($path))
70 my ($self, $path, @under) = @_;
71 $under[0] = "" if (! @under);
72 foreach my $dir (@under) {
73 return(1) if ($self->_is_prefix($path, $dir));
81 $class = ref($class) || $class;
84 my $archlib = $Config{archlibexp};
85 my $sitearch = $Config{sitearchexp};
87 # File::Find does not know how to deal with VMS filepaths.
89 $archlib = VMS::Filespec::unixify($archlib);
90 $sitearch = VMS::Filespec::unixify($sitearch);
95 $sitearch =~ s|\\|/|g;
98 # Read the core packlist
99 $self->{Perl}{packlist} =
100 ExtUtils::Packlist->new( File::Spec->catfile($archlib, '.packlist') );
101 $self->{Perl}{version} = $Config{version};
103 # Read the module packlists
105 # Only process module .packlists
106 return if $_ ne ".packlist" || $File::Find::dir eq $archlib;
108 # Hack of the leading bits of the paths & convert to a module name
109 my $module = $File::Find::name;
111 $module =~ s!\Q$archlib\E/?auto/(.*)/.packlist!$1!s or
112 $module =~ s!\Q$sitearch\E/?auto/(.*)/.packlist!$1!s;
113 my $modfile = "$module.pm";
116 # Find the top-level module file in @INC
117 $self->{$module}{version} = '';
118 foreach my $dir (@INC) {
119 my $p = File::Spec->catfile($dir, $modfile);
121 $module = _module_name($p, $module) if $Is_VMS;
123 require ExtUtils::MM;
124 $self->{$module}{version} = MM->parse_version($p);
130 $self->{$module}{packlist} =
131 ExtUtils::Packlist->new($File::Find::name);
134 my(@dirs) = grep { -e } ($archlib, $sitearch);
135 find($sub, @dirs) if @dirs;
137 return(bless($self, $class));
140 # VMS's non-case preserving file-system means the package name can't
141 # be reconstructed from the filename.
143 my($file, $orig_module) = @_;
146 if (open PACKFH, $file) {
148 if (/package\s+(\S+)\s*;/) {
150 # Make a sanity check, that lower case $module
151 # is identical to lowercase $pack before
153 if (lc($pack) eq lc($orig_module)) {
162 print STDERR "Couldn't figure out the package name for $file\n"
173 # Bug/feature of sort in scalar context requires this.
174 return wantarray ? sort keys %$self : keys %$self;
178 my ($self, $module, $type, @under) = @_;
181 Carp::croak("$module is not installed") if (! exists($self->{$module}));
182 $type = "all" if (! defined($type));
183 Carp::croak('type must be "all", "prog" or "doc"')
184 if ($type ne "all" && $type ne "prog" && $type ne "doc");
187 foreach my $file (keys(%{$self->{$module}{packlist}})) {
189 if ($self->_is_type($file, $type) &&
190 $self->_is_under($file, @under));
196 my ($self, $module, $type, @under) = @_;
198 foreach my $file ($self->files($module, $type, @under)) {
199 $dirs{dirname($file)}++;
201 return sort keys %dirs;
205 my ($self, $module, $type, @under) = @_;
207 foreach my $dir ($self->directories($module, $type, @under)) {
210 while ($last ne $dir) {
212 $dir = dirname($dir);
213 last if !$self->_is_under($dir, @under);
217 return(sort(keys(%dirs)));
221 my ($self, $module, $remove) = @_;
222 Carp::croak("$module is not installed") if (! exists($self->{$module}));
223 return($self->{$module}{packlist}->validate($remove));
227 my ($self, $module) = @_;
228 Carp::croak("$module is not installed") if (! exists($self->{$module}));
229 return($self->{$module}{packlist});
233 my ($self, $module) = @_;
234 Carp::croak("$module is not installed") if (! exists($self->{$module}));
235 return($self->{$module}{version});
245 ExtUtils::Installed - Inventory management of installed modules
249 use ExtUtils::Installed;
250 my ($inst) = ExtUtils::Installed->new();
251 my (@modules) = $inst->modules();
252 my (@missing) = $inst->validate("DBI");
253 my $all_files = $inst->files("DBI");
254 my $files_below_usr_local = $inst->files("DBI", "all", "/usr/local");
255 my $all_dirs = $inst->directories("DBI");
256 my $dirs_below_usr_local = $inst->directory_tree("DBI", "prog");
257 my $packlist = $inst->packlist("DBI");
261 ExtUtils::Installed provides a standard way to find out what core and module
262 files have been installed. It uses the information stored in .packlist files
263 created during installation to provide this information. In addition it
264 provides facilities to classify the installed files and to extract directory
265 information from the .packlist files.
269 The new() function searches for all the installed .packlists on the system, and
270 stores their contents. The .packlists can be queried with the functions
279 This takes no parameters, and searches for all the installed .packlists on the
280 system. The packlists are read using the ExtUtils::packlist module.
284 This returns a list of the names of all the installed modules. The perl 'core'
285 is given the special name 'Perl'.
289 This takes one mandatory parameter, the name of a module. It returns a list of
290 all the filenames from the package. To obtain a list of core perl files, use
291 the module name 'Perl'. Additional parameters are allowed. The first is one
292 of the strings "prog", "doc" or "all", to select either just program files,
293 just manual files or all files. The remaining parameters are a list of
294 directories. The filenames returned will be restricted to those under the
295 specified directories.
299 This takes one mandatory parameter, the name of a module. It returns a list of
300 all the directories from the package. Additional parameters are allowed. The
301 first is one of the strings "prog", "doc" or "all", to select either just
302 program directories, just manual directories or all directories. The remaining
303 parameters are a list of directories. The directories returned will be
304 restricted to those under the specified directories. This method returns only
305 the leaf directories that contain files from the specified module.
307 =item directory_tree()
309 This is identical in operation to directories(), except that it includes all the
310 intermediate directories back up to the specified directories.
314 This takes one mandatory parameter, the name of a module. It checks that all
315 the files listed in the modules .packlist actually exist, and returns a list of
316 any missing files. If an optional second argument which evaluates to true is
317 given any missing files will be removed from the .packlist
321 This returns the ExtUtils::Packlist object for the specified module.
325 This returns the version number for the specified module.
331 See the example in L<ExtUtils::Packlist>.
335 Alan Burlison <Alan.Burlison@uk.sun.com>