Module...t::Use(3pm)
π NAME π
Module::Extract::Use β bestie, this one finds all the modules a file explicitly uses. That's it. That's the whole job. π
β¨ SYNOPSIS β¨
use 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 }
}
π¦ DESCRIPTION π¦
Okay so what this does is pull out the names of the modules used in a file, and it does it with static analysis. Static. It is not out here running your code, so it literally cannot find the dynamic module uses β like eval "require $class". Nope. Not happening. It only reports modules that the file loads directly, or that show up in the import lists for parent or base.
The module handles the classic, conventional ways you bring a module in, whether that's use or require:
use Foo;
require Foo;
use Foo 1.23;
use Foo qw(this that);
It also now finds require as an expression, which is lowkey iconic when you wanna lazily load a module exactly once (and it might be faster too, no cap):
sub do_something {
state $rc = require Foo;
...
}
On top of all that, it finds module names used with parent and base β either of those sets up an inheritance relationship:
use parent qw(Foo);
use base qw(Foo);
So here's the tea β: when the namespaces come from base or parent, the value of the direct method is false. Every other case? It's true. So you can just skip those namespaces if you're not about that inheritance life:
my $details = $extor->get_modules_with_details( $file );
foreach my $detail ( @$details ) {
next unless $detail->direct;
...
}
β οΈ Real talk: this module does not discover runtime machinations to load something. String evals? Nope, not catching those:perl eval "use Foo"; my $bar = 'Bar'; eval "use $bar";If you want that, you might wanna look atModule::ExtractUse(which is a confusingly similar name, bestie, I know, we've all been there). π
new β makes an object. The object doesn't do anything just yet, but you need it to call the methods. It's giving "placeholder era". π
init β sets up the object. You shouldn't need to call this yourself. Teamwork makes the dream work, but this part is her job, not yours. π
get_modules( FILE ) β returns a list of namespaces explicitly use-d in FILE. Returns the empty list if the file does not exist, or if it can't parse the file.
Each used namespace appears only once in the list, even if it's used multiple times in the file. And the order of the list does not correspond to anything, so do not use the order to infer anything. Periodt. π«
get_modules_with_details( FILE ) β returns a list of hash references, one reference for each namespace explicitly use-d in FILE. Each reference has keys for:
namespaceβ the namespace, always definedversionβ defined if a module version was specifiedimportsβ an array reference to the import listpragmaβ true if the module thinks this namespace is a pragmadirectβ false if the module name came fromparentorbase
Each used namespace appears only once in the list, even if it's used multiple times in the file. The order of the list does not correspond to anything, so don't use the order to infer anything. β¨ (Yes, same disclaimer twice. It's important, okay?)
error β return the error from the last call to get_modules.
π TO DO π
(nothing here β the future is unwritten, bestie π)
π SEE ALSO π
Module::ScanDeps, Module::Extract
π SOURCE AVAILABILITY π
The source code is on GitHub:
https://github.com/briandfoy/module-extract-use
π AUTHOR π
brian d foy, "<briandfoy@pobox.com>"
π COPYRIGHT AND LICENSE π
Copyright Β© 2008-2026, brian d foy "<briandfoy@pobox.com>". All rights reserved.
This project is under the Artistic License 2.0.
Okay that's the whole page, angel π«Ά β this is Module::Extract::Use(3pm) from the User Contributed Perl Documentation, and it lands with perl v5.40.1 dated 2026-04-18. Slay, go parse something. π
β¨
π¦ where this page comes from
- ubuntu stonking: libmodule-extract-use-perl 1.055-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms