|
NAMEModule::Extract::Use - Discover the modules a module explicitly usesSYNOPSISuse Module::Extract::Use; my $extor = Module::Extract::Use->new; my @modules = $extor->get_modules( $file ); if( $extor->error ) { ... } my $details = $extor->get_modules_with_details( $file ); foreach my $detail ( @$details ) { printf "%s %s imports %s\n", $detail->module, $detail->version, join ' ', @{ $detail->imports } } DESCRIPTIONExtract the names of the modules used in a file using a static analysis. Since this module does not run code, it cannot find dynamic uses of modules, such as "eval "require $class"". It only reports modules that the file loads directly or are in the import lists for parent or base.The module can handle the conventional inclusion of modules with either "use" or "require" as the statement: use Foo; require Foo; use Foo 1.23; use Foo qw(this that); It now finds "require" as an expression, which is useful to lazily load a module once (and may be faster): sub do_something { state $rc = require Foo; ... } Additionally, it finds module names used with "parent" and "base", either of which establish an inheritance relationship: use parent qw(Foo); use base qw(Foo); In the case of namespaces found in "base" or "parent", the value of the "direct" method is false. In all other cases, it is true. You can then skip those namespaces: my $details = $extor->get_modules_with_details( $file ); foreach my $detail ( @$details ) { next unless $detail->direct; ... } This module does not discover runtime machinations to load something, such as string evals: eval "use Foo"; my $bar = 'Bar'; eval "use $bar"; If you want that, you might consider Module::ExtractUse (a confusingly similar name).
TO DOSEE ALSOModule::ScanDeps, Module::ExtractSOURCE AVAILABILITYThe source code is in Github:https://github.com/briandfoy/module-extract-use AUTHORbrian d foy, "<bdfoy@cpan.org>"COPYRIGHT AND LICENSECopyright © 2008-2022, brian d foy "<bdfoy@cpan.org>". All rights reserved.This project is under the Artistic License 2.0.
Visit the GSP FreeBSD Man Page Interface. |