App-Tel
view release on metacpan or search on metacpan
local/lib/perl5/Module/ScanDeps.pm view on Meta::CPAN
Used in a program;
use Module::ScanDeps;
# standard usage
my $hash_ref = scan_deps(
files => [ 'a.pl', 'b.pl' ],
recurse => 1,
);
# shorthand; assume recurse == 1
my $hash_ref = scan_deps( 'a.pl', 'b.pl' );
# App::Packer::Frontend compatible interface
# see App::Packer::Frontend for the structure returned by get_files
my $scan = Module::ScanDeps->new;
$scan->set_file( 'a.pl' );
$scan->set_options( add_modules => [ 'Test::More' ] );
$scan->calculate_info;
my $files = $scan->get_files;
=head1 DESCRIPTION
This module scans potential modules used by perl programs, and returns a
hash reference; its keys are the module names as appears in C<%INC>
(e.g. C<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, C<scan_deps>, is exported by default. Other
functions such as (C<scan_line>, C<scan_chunk>, C<add_deps>, C<path_to_inc_name>)
are exported upon request.
Users of B<App::Packer> may also use this module as the dependency-checking
frontend, by tweaking their F<p2e.pl> like below:
use Module::ScanDeps;
...
my $packer = App::Packer->new( frontend => 'Module::ScanDeps' );
...
Please see L<App::Packer::Frontend> for detailed explanation on
the structure returned by C<get_files>.
=head2 B<scan_deps>
$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 C<@files>, registering their
dependencies into C<%rv>, and returns a reference to the updated
C<%rv>. The meaning of keys and values are explained above.
If C<$recurse> is true, C<scan_deps> will call itself recursively,
to perform a breadth-first search on text files (as defined by the
-T operator) found in C<%rv>.
If the C<\%skip> is specified, files that exists as its keys are
skipped. This is used internally to avoid infinite recursion.
If C<$compile> or C<$execute> is true, runs C<files> in either
compile-only or normal mode, then inspects their C<%INC> after
termination to determine additional runtime dependencies.
If C<$execute> is an array reference, passes C<@$execute>
as arguments to each file in C<@files> when it is run.
If performance of the scanning process is a concern, C<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 C<warn_missing> is recognized. If set to true,
C<scan_deps> issues a warning to STDERR for every module file that the
scanned code depends but that wasn't 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.
=head2 B<scan_deps_runtime>
Like B<scan_deps>, but skips the static scanning part.
=head2 B<scan_line>
@modules = scan_line($line);
Splits a line into chunks (currently with the semicolon characters), and
return the union of C<scan_chunk> calls of them.
If the line is C<__END__> or C<__DATA__>, a single C<__END__> element is
returned to signify the end of the program.
Similarly, it returns a single C<__POD__> if the line matches C</^=\w/>;
the caller is responsible for skipping appropriate number of lines
until C<=cut>, before calling C<scan_line> again.
=head2 B<scan_chunk>
$module = scan_chunk($chunk);
@modules = scan_chunk($chunk);
Apply various heuristics to C<$chunk> to find and return the module
name(s) it contains. In scalar context, returns only the first module
or C<undef>.
=head2 B<add_deps>
$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 C<@INC> and C<@Module::ScanDeps::IncludeLibs>;
( run in 2.903 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )