This module scans potential modules used by perl programs, and returns a
hash reference; its keys are the module names as appears in %INC
(e.g. Test/More.pm); the values are hash references with this structure:
file => /usr/local/lib/perl5/5.8.0/Test/More.pm,
key => Test/More.pm,
type => module, # or autoload, data, shared
used_by => [ Test/Simple.pm, ... ],
uses => [ Test/Other.pm, ... ],
One function, scan_deps, is exported by default. Other
functions such as (scan_line, scan_chunk, add_deps, path_to_inc_name)
are exported upon request.
Users of <B>App::PackerB> may also use this module as the dependency-checking
frontend, by tweaking their p2e.pl like below:
my $packer = App::Packer->new( frontend => Module::ScanDeps );
Please see App::Packer::Frontend for detailed explanation on
the structure returned by get_files.
$rv_ref = scan_deps(
files => \@files, recurse => $recurse,
rv => \%rv, skip => \%skip,
compile => $compile, execute => $execute,
$rv_ref = scan_deps(@files); # shorthand, with recurse => 1
This function scans each file in @files, registering their
dependencies into %rv, and returns a reference to the updated
%rv. The meaning of keys and values are explained above.
If $recurse is true, scan_deps will call itself recursively,
to perform a breadth-first search on text files (as defined by the
-T operator) found in %rv.
If the \%skip is specified, files that exists as its keys are
skipped. This is used internally to avoid infinite recursion.
If $compile or $execute is true, runs files in either
compile-only or normal mode, then inspects their %INC after
termination to determine additional runtime dependencies.
If $execute is an array reference, passes @$execute
as arguments to each file in @files when it is run.
If performance of the scanning process is a concern, cache_file can be
set to a filename. The scanning results will be cached and written to the
file. This will speed up the scanning process on subsequent runs.
Additionally, an option warn_missing is recognized. If set to true,
scan_deps issues a warning to STDERR for every module file that the
scanned code depends but that wasnt found. Please note that this may
also report numerous false positives. That is why by default, the heuristic
silently drops all dependencies it cannot find.
Like <B>scan_depsB>, but skips the static scanning part.
@modules = scan_line($line);
Splits a line into chunks (currently with the semicolon characters), and
return the union of scan_chunk calls of them.
If the line is __END__ or __DATA__, a single __END__ element is
returned to signify the end of the program.
Similarly, it returns a single __POD__ if the line matches /^=\w/;
the caller is responsible for skipping appropriate number of lines
until =cut, before calling scan_line again.
$module = scan_chunk($chunk);
@modules = scan_chunk($chunk);
Apply various heuristics to $chunk to find and return the module
name(s) it contains. In scalar context, returns only the first module
$rv_ref = add_deps( rv => \%rv, modules => \@modules );
$rv_ref = add_deps( @modules ); # shorthand, without rv
Resolves a list of module names to its actual on-disk location, by
finding in @INC and @Module::ScanDeps::IncludeLibs;
modules that cannot be found are skipped.
This function populates the %rv hash with module/filename pairs, and
returns a reference to it.
$perl_name = path_to_inc_name($path, $warn)
Assumes $path refers to a perl file and does its best to return the
name as it would appear in %INC. Returns undef if no match was found
and a prints a warning to STDERR if $warn is true.
E.g. if $path = perl/site/lib/Module/ScanDeps.pm then $perl_name
will be Module/ScanDeps.pm.