1 package ExtUtils
::Installed
;
6 use ExtUtils
::Packlist
;
7 use ExtUtils
::MakeMaker
;
11 our $VERSION = '0.03';
13 my $DOSISH = ($^O
=~ /^(MSWin\d\d|os2|dos|mint)$/);
17 my ($self, $path, $prefix) = @_;
18 if (substr($path, 0, length($prefix)) eq $prefix)
26 if ($path =~ m{^\Q$prefix\E}i)
36 my ($self, $path, $type) = @_;
37 return(1) if ($type eq "all");
40 return($self->_is_prefix($path, $Config{installman1dir
})
42 $self->_is_prefix($path, $Config{installman3dir
})
47 return($self->_is_prefix($path, $Config{prefix
})
49 !$self->_is_prefix($path, $Config{installman1dir
})
51 !$self->_is_prefix($path, $Config{installman3dir
})
59 my ($self, $path, @under) = @_;
60 $under[0] = "" if (! @under);
61 foreach my $dir (@under)
63 return(1) if ($self->_is_prefix($path, $dir));
71 $class = ref($class) || $class;
74 my $installarchlib = $Config{installarchlib
};
75 my $archlib = $Config{archlib
};
76 my $sitearch = $Config{sitearch
};
80 $installarchlib =~ s
|\\|/|g
;
82 $sitearch =~ s
|\\|/|g
;
85 # Read the core packlist
86 $self->{Perl
}{packlist
} =
87 ExtUtils
::Packlist
->new("$installarchlib/.packlist");
88 $self->{Perl
}{version
} = $Config{version
};
90 # Read the module packlists
93 # Only process module .packlists
94 return if ($_) ne ".packlist" || $File::Find
::dir
eq $installarchlib;
96 # Hack of the leading bits of the paths & convert to a module name
97 my $module = $File::Find
::name
;
98 $module =~ s!\Q$archlib\E/auto/(.*)/.packlist!$1!s;
99 $module =~ s!\Q$sitearch\E/auto/(.*)/.packlist!$1!s;
100 my $modfile = "$module.pm";
103 # Find the top-level module file in @INC
104 $self->{$module}{version
} = '';
105 foreach my $dir (@INC)
107 my $p = MM
->catfile($dir, $modfile);
110 $self->{$module}{version
} = MM
->parse_version($p);
116 $self->{$module}{packlist
} = ExtUtils
::Packlist
->new($File::Find
::name
);
118 find
($sub, $archlib, $sitearch);
120 return(bless($self, $class));
126 return(sort(keys(%$self)));
131 my ($self, $module, $type, @under) = @_;
134 Carp
::croak
("$module is not installed") if (! exists($self->{$module}));
135 $type = "all" if (! defined($type));
136 Carp
::croak
('type must be "all", "prog" or "doc"')
137 if ($type ne "all" && $type ne "prog" && $type ne "doc");
140 foreach my $file (keys(%{$self->{$module}{packlist
}}))
143 if ($self->_is_type($file, $type) && $self->_is_under($file, @under));
148 sub directories
($$;$)
150 my ($self, $module, $type, @under) = @_;
152 foreach my $file ($self->files($module, $type, @under))
154 $dirs{dirname
($file)}++;
156 return(sort(keys(%dirs)));
159 sub directory_tree
($$;$)
161 my ($self, $module, $type, @under) = @_;
163 foreach my $dir ($self->directories($module, $type, @under))
167 while ($last ne $dir)
170 $dir = dirname
($dir);
171 last if (! $self->_is_under($dir, @under));
175 return(sort(keys(%dirs)));
180 my ($self, $module, $remove) = @_;
181 Carp
::croak
("$module is not installed") if (! exists($self->{$module}));
182 return($self->{$module}{packlist
}->validate($remove));
187 my ($self, $module) = @_;
188 Carp
::croak
("$module is not installed") if (! exists($self->{$module}));
189 return($self->{$module}{packlist
});
194 my ($self, $module) = @_;
195 Carp
::croak
("$module is not installed") if (! exists($self->{$module}));
196 return($self->{$module}{version
});
209 ExtUtils::Installed - Inventory management of installed modules
213 use ExtUtils::Installed;
214 my ($inst) = ExtUtils::Installed->new();
215 my (@modules) = $inst->modules();
216 my (@missing) = $inst->validate("DBI");
217 my $all_files = $inst->files("DBI");
218 my $files_below_usr_local = $inst->files("DBI", "all", "/usr/local");
219 my $all_dirs = $inst->directories("DBI");
220 my $dirs_below_usr_local = $inst->directory_tree("DBI", "prog");
221 my $packlist = $inst->packlist("DBI");
225 ExtUtils::Installed provides a standard way to find out what core and module
226 files have been installed. It uses the information stored in .packlist files
227 created during installation to provide this information. In addition it
228 provides facilities to classify the installed files and to extract directory
229 information from the .packlist files.
233 The new() function searches for all the installed .packlists on the system, and
234 stores their contents. The .packlists can be queried with the functions
243 This takes no parameters, and searches for all the installed .packlists on the
244 system. The packlists are read using the ExtUtils::packlist module.
248 This returns a list of the names of all the installed modules. The perl 'core'
249 is given the special name 'Perl'.
253 This takes one mandatory parameter, the name of a module. It returns a list of
254 all the filenames from the package. To obtain a list of core perl files, use
255 the module name 'Perl'. Additional parameters are allowed. The first is one
256 of the strings "prog", "man" or "all", to select either just program files,
257 just manual files or all files. The remaining parameters are a list of
258 directories. The filenames returned will be restricted to those under the
259 specified directories.
263 This takes one mandatory parameter, the name of a module. It returns a list of
264 all the directories from the package. Additional parameters are allowed. The
265 first is one of the strings "prog", "man" or "all", to select either just
266 program directories, just manual directories or all directories. The remaining
267 parameters are a list of directories. The directories returned will be
268 restricted to those under the specified directories. This method returns only
269 the leaf directories that contain files from the specified module.
271 =item directory_tree()
273 This is identical in operation to directory(), except that it includes all the
274 intermediate directories back up to the specified directories.
278 This takes one mandatory parameter, the name of a module. It checks that all
279 the files listed in the modules .packlist actually exist, and returns a list of
280 any missing files. If an optional second argument which evaluates to true is
281 given any missing files will be removed from the .packlist
285 This returns the ExtUtils::Packlist object for the specified module.
289 This returns the version number for the specified module.
295 See the example in L<ExtUtils::Packlist>.
299 Alan Burlison <Alan.Burlison@uk.sun.com>