1 package ExtUtils::Installed;
6 use ExtUtils::Packlist;
7 use ExtUtils::MakeMaker;
12 require VMS::Filespec if $^O eq 'VMS';
14 our $VERSION = '0.05';
16 my $DOSISH = ($^O =~ /^(MSWin\d\d|os2|dos|mint)$/);
19 my ($self, $path, $prefix) = @_;
20 return unless defined $prefix && defined $path;
23 $prefix = VMS::Filespec::unixify($prefix);
24 $path = VMS::Filespec::unixify($path);
26 return 1 if substr($path, 0, length($prefix)) eq $prefix;
31 return 1 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))
47 my ($self, $path, $type) = @_;
48 return 1 if $type eq "all";
50 return($self->_is_doc($path)) if $type eq "doc";
52 if ($type eq "prog") {
53 return($self->_is_prefix($path, $Config{prefix} || $Config{prefixexp})
55 !($self->_is_doc($path))
62 my ($self, $path, @under) = @_;
63 $under[0] = "" if (! @under);
64 foreach my $dir (@under) {
65 return(1) if ($self->_is_prefix($path, $dir));
73 $class = ref($class) || $class;
76 my $archlib = $Config{archlibexp};
77 my $sitearch = $Config{sitearchexp};
79 # File::Find does not know how to deal with VMS filepaths.
81 $archlib = VMS::Filespec::unixify($archlib);
82 $sitearch = VMS::Filespec::unixify($sitearch);
87 $sitearch =~ s|\\|/|g;
90 # Read the core packlist
91 $self->{Perl}{packlist} =
92 ExtUtils::Packlist->new( File::Spec->catfile($archlib, '.packlist') );
93 $self->{Perl}{version} = $Config{version};
95 # Read the module packlists
97 # Only process module .packlists
98 return if ($_) ne ".packlist" || $File::Find::dir eq $archlib;
100 # Hack of the leading bits of the paths & convert to a module name
101 my $module = $File::Find::name;
103 $module =~ s!\Q$archlib\E/?auto/(.*)/.packlist!$1!s or
104 $module =~ s!\Q$sitearch\E/?auto/(.*)/.packlist!$1!s;
105 my $modfile = "$module.pm";
108 # Find the top-level module file in @INC
109 $self->{$module}{version} = '';
110 foreach my $dir (@INC) {
111 my $p = File::Spec->catfile($dir, $modfile);
113 require ExtUtils::MM;
114 $self->{$module}{version} = MM->parse_version($p);
120 $self->{$module}{packlist} =
121 ExtUtils::Packlist->new($File::Find::name);
124 my(@dirs) = grep { -e } ($archlib, $sitearch);
125 find($sub, @dirs) if @dirs;
127 return(bless($self, $class));
132 return sort keys %$self;
136 my ($self, $module, $type, @under) = @_;
139 Carp::croak("$module is not installed") if (! exists($self->{$module}));
140 $type = "all" if (! defined($type));
141 Carp::croak('type must be "all", "prog" or "doc"')
142 if ($type ne "all" && $type ne "prog" && $type ne "doc");
145 foreach my $file (keys(%{$self->{$module}{packlist}})) {
147 if ($self->_is_type($file, $type) &&
148 $self->_is_under($file, @under));
154 my ($self, $module, $type, @under) = @_;
156 foreach my $file ($self->files($module, $type, @under)) {
157 $dirs{dirname($file)}++;
159 return sort keys %dirs;
163 my ($self, $module, $type, @under) = @_;
165 foreach my $dir ($self->directories($module, $type, @under)) {
168 while ($last ne $dir) {
170 $dir = dirname($dir);
171 last if !$self->_is_under($dir, @under);
175 return(sort(keys(%dirs)));
179 my ($self, $module, $remove) = @_;
180 Carp::croak("$module is not installed") if (! exists($self->{$module}));
181 return($self->{$module}{packlist}->validate($remove));
185 my ($self, $module) = @_;
186 Carp::croak("$module is not installed") if (! exists($self->{$module}));
187 return($self->{$module}{packlist});
191 my ($self, $module) = @_;
192 Carp::croak("$module is not installed") if (! exists($self->{$module}));
193 return($self->{$module}{version});
203 ExtUtils::Installed - Inventory management of installed modules
207 use ExtUtils::Installed;
208 my ($inst) = ExtUtils::Installed->new();
209 my (@modules) = $inst->modules();
210 my (@missing) = $inst->validate("DBI");
211 my $all_files = $inst->files("DBI");
212 my $files_below_usr_local = $inst->files("DBI", "all", "/usr/local");
213 my $all_dirs = $inst->directories("DBI");
214 my $dirs_below_usr_local = $inst->directory_tree("DBI", "prog");
215 my $packlist = $inst->packlist("DBI");
219 ExtUtils::Installed provides a standard way to find out what core and module
220 files have been installed. It uses the information stored in .packlist files
221 created during installation to provide this information. In addition it
222 provides facilities to classify the installed files and to extract directory
223 information from the .packlist files.
227 The new() function searches for all the installed .packlists on the system, and
228 stores their contents. The .packlists can be queried with the functions
237 This takes no parameters, and searches for all the installed .packlists on the
238 system. The packlists are read using the ExtUtils::packlist module.
242 This returns a list of the names of all the installed modules. The perl 'core'
243 is given the special name 'Perl'.
247 This takes one mandatory parameter, the name of a module. It returns a list of
248 all the filenames from the package. To obtain a list of core perl files, use
249 the module name 'Perl'. Additional parameters are allowed. The first is one
250 of the strings "prog", "doc" or "all", to select either just program files,
251 just manual files or all files. The remaining parameters are a list of
252 directories. The filenames returned will be restricted to those under the
253 specified directories.
257 This takes one mandatory parameter, the name of a module. It returns a list of
258 all the directories from the package. Additional parameters are allowed. The
259 first is one of the strings "prog", "doc" or "all", to select either just
260 program directories, just manual directories or all directories. The remaining
261 parameters are a list of directories. The directories returned will be
262 restricted to those under the specified directories. This method returns only
263 the leaf directories that contain files from the specified module.
265 =item directory_tree()
267 This is identical in operation to directories(), except that it includes all the
268 intermediate directories back up to the specified directories.
272 This takes one mandatory parameter, the name of a module. It checks that all
273 the files listed in the modules .packlist actually exist, and returns a list of
274 any missing files. If an optional second argument which evaluates to true is
275 given any missing files will be removed from the .packlist
279 This returns the ExtUtils::Packlist object for the specified module.
283 This returns the version number for the specified module.
289 See the example in L<ExtUtils::Packlist>.
293 Alan Burlison <Alan.Burlison@uk.sun.com>