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);
20 $VERSION = eval $VERSION;
23 my ($self, $path, $prefix) = @_;
24 return unless defined $prefix && defined $path;
27 $prefix = VMS::Filespec::unixify($prefix);
28 $path = VMS::Filespec::unixify($path);
31 # Sloppy Unix path normalization.
35 return 1 if substr($path, 0, length($prefix)) eq $prefix;
40 return 1 if $path =~ m{^\Q$prefix\E}i;
46 my ($self, $path) = @_;
47 my $man1dir = $Config{man1direxp};
48 my $man3dir = $Config{man3direxp};
49 return(($man1dir && $self->_is_prefix($path, $man1dir))
51 ($man3dir && $self->_is_prefix($path, $man3dir))
56 my ($self, $path, $type) = @_;
57 return 1 if $type eq "all";
59 return($self->_is_doc($path)) if $type eq "doc";
61 if ($type eq "prog") {
62 return($self->_is_prefix($path, $Config{prefix} || $Config{prefixexp})
64 !($self->_is_doc($path))
71 my ($self, $path, @under) = @_;
72 $under[0] = "" if (! @under);
73 foreach my $dir (@under) {
74 return(1) if ($self->_is_prefix($path, $dir));
82 $class = ref($class) || $class;
85 my $archlib = $Config{archlibexp};
86 my $sitearch = $Config{sitearchexp};
88 # File::Find does not know how to deal with VMS filepaths.
90 $archlib = VMS::Filespec::unixify($archlib);
91 $sitearch = VMS::Filespec::unixify($sitearch);
96 $sitearch =~ s|\\|/|g;
99 # Read the core packlist
100 $self->{Perl}{packlist} =
101 ExtUtils::Packlist->new( File::Spec->catfile($archlib, '.packlist') );
102 $self->{Perl}{version} = $Config{version};
104 # Read the module packlists
106 # Only process module .packlists
107 return if $_ ne ".packlist" || $File::Find::dir eq $archlib;
109 # Hack of the leading bits of the paths & convert to a module name
110 my $module = $File::Find::name;
112 $module =~ s!\Q$archlib\E/?auto/(.*)/.packlist!$1!s or
113 $module =~ s!\Q$sitearch\E/?auto/(.*)/.packlist!$1!s;
114 my $modfile = "$module.pm";
117 # Find the top-level module file in @INC
118 $self->{$module}{version} = '';
119 foreach my $dir (@INC) {
120 my $p = File::Spec->catfile($dir, $modfile);
122 $module = _module_name($p, $module) if $Is_VMS;
124 require ExtUtils::MM;
125 $self->{$module}{version} = MM->parse_version($p);
131 $self->{$module}{packlist} =
132 ExtUtils::Packlist->new($File::Find::name);
135 my(@dirs) = grep { -e } ($archlib, $sitearch);
136 find($sub, @dirs) if @dirs;
138 return(bless($self, $class));
141 # VMS's non-case preserving file-system means the package name can't
142 # be reconstructed from the filename.
144 my($file, $orig_module) = @_;
147 if (open PACKFH, $file) {
149 if (/package\s+(\S+)\s*;/) {
151 # Make a sanity check, that lower case $module
152 # is identical to lowercase $pack before
154 if (lc($pack) eq lc($orig_module)) {
163 print STDERR "Couldn't figure out the package name for $file\n"
174 # Bug/feature of sort in scalar context requires this.
175 return wantarray ? sort keys %$self : keys %$self;
179 my ($self, $module, $type, @under) = @_;
182 Carp::croak("$module is not installed") if (! exists($self->{$module}));
183 $type = "all" if (! defined($type));
184 Carp::croak('type must be "all", "prog" or "doc"')
185 if ($type ne "all" && $type ne "prog" && $type ne "doc");
188 foreach my $file (keys(%{$self->{$module}{packlist}})) {
190 if ($self->_is_type($file, $type) &&
191 $self->_is_under($file, @under));
197 my ($self, $module, $type, @under) = @_;
199 foreach my $file ($self->files($module, $type, @under)) {
200 $dirs{dirname($file)}++;
202 return sort keys %dirs;
206 my ($self, $module, $type, @under) = @_;
208 foreach my $dir ($self->directories($module, $type, @under)) {
211 while ($last ne $dir) {
213 $dir = dirname($dir);
214 last if !$self->_is_under($dir, @under);
218 return(sort(keys(%dirs)));
222 my ($self, $module, $remove) = @_;
223 Carp::croak("$module is not installed") if (! exists($self->{$module}));
224 return($self->{$module}{packlist}->validate($remove));
228 my ($self, $module) = @_;
229 Carp::croak("$module is not installed") if (! exists($self->{$module}));
230 return($self->{$module}{packlist});
234 my ($self, $module) = @_;
235 Carp::croak("$module is not installed") if (! exists($self->{$module}));
236 return($self->{$module}{version});
246 ExtUtils::Installed - Inventory management of installed modules
250 use ExtUtils::Installed;
251 my ($inst) = ExtUtils::Installed->new();
252 my (@modules) = $inst->modules();
253 my (@missing) = $inst->validate("DBI");
254 my $all_files = $inst->files("DBI");
255 my $files_below_usr_local = $inst->files("DBI", "all", "/usr/local");
256 my $all_dirs = $inst->directories("DBI");
257 my $dirs_below_usr_local = $inst->directory_tree("DBI", "prog");
258 my $packlist = $inst->packlist("DBI");
262 ExtUtils::Installed provides a standard way to find out what core and module
263 files have been installed. It uses the information stored in .packlist files
264 created during installation to provide this information. In addition it
265 provides facilities to classify the installed files and to extract directory
266 information from the .packlist files.
270 The new() function searches for all the installed .packlists on the system, and
271 stores their contents. The .packlists can be queried with the functions
280 This takes no parameters, and searches for all the installed .packlists on the
281 system. The packlists are read using the ExtUtils::packlist module.
285 This returns a list of the names of all the installed modules. The perl 'core'
286 is given the special name 'Perl'.
290 This takes one mandatory parameter, the name of a module. It returns a list of
291 all the filenames from the package. To obtain a list of core perl files, use
292 the module name 'Perl'. Additional parameters are allowed. The first is one
293 of the strings "prog", "doc" or "all", to select either just program files,
294 just manual files or all files. The remaining parameters are a list of
295 directories. The filenames returned will be restricted to those under the
296 specified directories.
300 This takes one mandatory parameter, the name of a module. It returns a list of
301 all the directories from the package. Additional parameters are allowed. The
302 first is one of the strings "prog", "doc" or "all", to select either just
303 program directories, just manual directories or all directories. The remaining
304 parameters are a list of directories. The directories returned will be
305 restricted to those under the specified directories. This method returns only
306 the leaf directories that contain files from the specified module.
308 =item directory_tree()
310 This is identical in operation to directories(), except that it includes all the
311 intermediate directories back up to the specified directories.
315 This takes one mandatory parameter, the name of a module. It checks that all
316 the files listed in the modules .packlist actually exist, and returns a list of
317 any missing files. If an optional second argument which evaluates to true is
318 given any missing files will be removed from the .packlist
322 This returns the ExtUtils::Packlist object for the specified module.
326 This returns the version number for the specified module.
332 See the example in L<ExtUtils::Packlist>.
336 Alan Burlison <Alan.Burlison@uk.sun.com>