The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

NAME

extract_modules - determine which Perl modules a given file uses

SYNOPSIS

Given Perl files, extract and report the Perl modules included with use or require.

# print a verbose text listing
$ extract_modules filename [...]
Modules required by examples/extract_modules:
- Getopt::Std (first released with Perl 5)
- Module::CoreList (first released with Perl 5.008009)
- Pod::Usage (first released with Perl 5.006)
- strict (first released with Perl 5)
- warnings (first released with Perl 5.006)
5 module(s) in core, 0 external module(s)
# print a succint list, one module per line
$ extract_modules -l filename [...]
Getopt::Std
Module::CoreList
Pod::Usage
open
strict
warnings
# print a succinct list, modules separated by null bytes
# you might like this with xargs -0
$ extract_modules -0 filename [...]
Getopt::StdModule::CoreListPod::Usageopenstrictwarnings
# print the modules list as JSON
$ extract_modules -j filename [...]
[
"Getopt::Std",
"Module::CoreList",
"Pod::Usage",
"open",
"strict",
"warnings"
]
# print the modules list as a basic cpanfile
$ extract_modules -c filename [...]
requires 'Getopt::Std', '1.23';
requires 'Module::CoreList';
requires 'Pod::Usage';
requires 'open';
requires 'strict';
requires 'warnings';

DESCRIPTION

This script does not execute the code in the files it examines. It uses the Module::Extract::Use or Module::ExtractUse modules which statically analyze the source without compiling or running it. These modules cannot discover modules loaded dynamically through a string eval.

Command-line options

  • -c cpanfile output

  • -e exclude core modules

  • -j JSON output

  • -l succint list, one module per line

  • -0 succint list, modules null separated (for xargs -0)

AUTHORS

Jonathan Yu <frequency@cpan.org>

brian d foy <bdfoy@cpan.org>

COPYRIGHT & LICENSE

Copyright © 2009-2024, brian d foy <briandfoy@pobox.com>. All rights reserved.

You can use this script under the same terms as Perl itself.

SEE ALSO

Module::Extract::Use, Module::ExtractUse, Module::ScanDeps,

1 POD Error

The following errors were encountered while parsing the POD:

Around line 223:

You forgot a '=back' before '=head1'