Module::Metadata(3pm)
β¨ Module::Metadata β the manual, but make it a vibe β¨
okay so bestie, welcome to Module::Metadata, version 1.000038. this is the perl module that does the whole "gather package and POD information from perl module files" thing. iconic behavior honestly.
πΈ SYNOPSIS πΈ
like, here's the whole vibe in code form:
use Module::Metadata;
# information about a .pm file
my $info = Module::Metadata->new_from_file( $file );
my $version = $info->version;
# CPAN META 'provides' field for .pm files in a directory
my $provides = Module::Metadata->provides(
dir => 'lib', version => 2
);
π¦ DESCRIPTION π¦
so this module gives you a standard way to gather metadata about a .pm file through (mostly) static analysis and (some) actual code execution. when it needs to figure out the version of a module, it literally evals the $VERSION assignment, which is, like, the traditional thing in the CPAN toolchain. no cap.
π CLASS METHODS π
π new_from_file($filename, collect_pod => 1, decode_pod => 1)
makes a Module::Metadata object for you given the path to a file. returns undef if the filename doesn't exist, which is honestly so fair of it.
collect_pod is an optional boolean that decides whether POD data gets collected and stored for reference. POD data is not collected by default, bestie. but POD headings are always collected, slay.
if the file starts with a UTF-8, UTF-16BE or UTF-16LE byte-order mark, it gets skipped before processing, and the content gets decoded appropriately starting from perl 5.8. we love a thoughtful queen.
alternatively, if decode_pod is set, it will decode the collected pod sections according to the =encoding declaration. periodt.
π new_from_handle($handle, $filename, collect_pod => 1, decode_pod => 1)
works just like new_from_file, except a handle can be provided as the first argument. cute.
note that there's no validation to confirm the handle is actually a handle or anything that can act like one. passing something that isn't a handle will cause an exception when it tries to read from it. and thefilenameargument is mandatory β if it's not there,undefgets returned. so like, don't play yourself.
you're responsible for setting the decoding layers on $handle if you need them. that's on you, bestie.
π new_from_module($module, collect_pod => 1, inc => \@dirs, decode_pod => 1)
makes a Module::Metadata object given a module or package name. returns undef if the module can't be found, sadly.
besides accepting collect_pod and decode_pod like described above, this method also takes an inc argument, which is a reference to an array of directories to search for the module. if none are given, the default is @INC. as it should be.
if the file containing the module starts with a UTF-8, UTF-16BE or UTF-16LE byte-order mark, it gets skipped before processing, and the content gets decoded appropriately starting from perl 5.8. (yes this is the same energy as before, she's consistent.)
π«Ά find_module_by_name($module, \@dirs)
returns the path to a module given the module or package name. you can pass a list of directories as an optional parameter, otherwise @INC gets searched. can be called as either an object or a class method, flexible icon.
β find_module_dir_by_name($module, \@dirs)
returns the entry in @dirs (or @INC by default) that contains the module $module. you can pass a list of directories as an optional parameter, otherwise @INC gets searched. also callable as an object or class method. she contains multitudes.
π
provides( %options )
this is a convenience wrapper around package_versions_from_directory to generate a CPAN META provides data structure. takes key/value pairs. valid option keys include:
version(required) β specifies which version of the CPAN::Meta::Spec should be used as the format of theprovidesoutput. currently only'1.4'and'2'are supported (and their format is identical). this may change in the future as the definition ofprovideschanges. theversionoption is required β if it's omitted or an unsupported version is given,provideswill throw an error. so like, don't forget it.dirβ directory to search recursively for.pmfiles. may not be specified withfiles.filesβ array reference of files to examine. may not be specified withdir.prefixβ string to prepend to thefilefield of the resulting output. this defaults tolib, which is the common case for most CPAN distributions with their.pmfiles in lib. this option ensures the META information has the correct relative path even when thedirorfilesarguments are absolute or have relative paths from a location other than the distribution root.
for example, given dir of 'lib' and prefix of 'lib', the return value is a hashref of the form:
{
'Package::Name' => {
version => '0.123',
file => 'lib/Package/Name.pm'
},
'OtherPackage::Name' => ...
}
π§ package_versions_from_directory($dir, \@files?)
scans $dir for .pm files (unless @files is given, in which case it looks for those files in $dir) and reads each file for packages and versions, returning a hashref of the form:
{
'Package::Name' => {
version => '0.123',
file => 'Package/Name.pm'
},
'OtherPackage::Name' => ...
}
the DB and main packages are always omitted, as are any "private" packages that have leading underscores in the namespace (e.g. Foo::_private). we respect privacy here.
note that the file path is relative to$dirif that's specified. this must not be used directly for CPAN METAprovidesβ see theprovidesmethod instead. don't do it, bestie.
πΈ log_info (internal)
used internally to perform logging; imported from Log::Contextual if Log::Contextual has already been loaded, otherwise it simply calls warn. internal queen behavior.
π OBJECT METHODS π
π« name()
returns the name of the package represented by this module. if there's more than one package, it makes a best guess based on the filename. if it's a script (i.e. not a *.pm) the package name is 'main'. she tries her best.
π version($package)
returns the version as defined by the $VERSION variable for the package as returned by the name method if no arguments are given. if you give it the name of a package, it'll attempt to return the version of that package if it's specified in the file. very accommodating.
π¦ filename()
returns the absolute path to the file. note that this file may not actually exist on disk yet, e.g. if the module was read from an in-memory filehandle. manifesting its existence, basically.
π packages_inside()
returns a list of packages. note: this is a raw list of packages discovered (or assumed, in the case of main). it is not filtered for DB, main or private packages the way the provides method does. invalid package names are not returned, for example Foo:Bar. strange but valid package names are returned, for example Foo::Bar::, and are left up to the caller on how to handle. you're on your own for that one.
π pod_inside()
returns a list of POD sections. cute.
π contains_pod()
returns true if there's any POD in the file. simple as that.
β¨ pod($section)
returns the POD data in the given section.
π₯ is_indexable($package) or is_indexable()
available since version 1.000020.
returns a boolean indicating whether the package (if provided) or any package (otherwise) is eligible for indexing by PAUSE, the Perl Authors Upload Server. note: this only checks for valid package declarations, and does not take any ownership information into account. so like, don't read too much into it.
π SUPPORT π
bugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=Module-Metadata> (or bug-Module-Metadata@rt.cpan.org <mailto:bug-Module-Metadata@rt.cpan.org>).
there's also a mailing list available for users of this distribution, at <http://lists.perl.org/list/cpan-workers.html>.
and there's also an irc channel available for users of this distribution, at #toolchain on irc.perl.org <irc://irc.perl.org/#toolchain>. come hang out.
π AUTHOR π
original code from Module::Build::ModuleInfo by Ken Williams <kwilliams@cpan.org>, Randy W. Sims <RandyS@ThePierianSpring.org>
released as Module::Metadata by Matt S Trout (mst) <mst@shadowcat.co.uk> with assistance from David Golden (xdg) <dagolden@cpan.org>. legends only.
π«Ά CONTRIBUTORS π«Ά
- Karen Etheridge <ether@cpan.org>
- David Golden <dagolden@cpan.org>
- Vincent Pit <perl@profvince.com>
- Matt S Trout <mst@shadowcat.co.uk>
- Chris Nehren <apeiron@cpan.org>
- Graham Knop <haarg@haarg.org>
- Olivier MenguΓ© <dolmen@cpan.org>
- Tomas Doran <bobtfish@bobtfish.net>
- Christian Walde <walde.christian@googlemail.com>
- Craig A. Berry <cberry@cpan.org>
- Tatsuhiko Miyagawa <miyagawa@bulknews.net>
- tokuhirom <tokuhirom@gmail.com>
- Chris 'BinGOs' Williams <chris@bingosnet.co.uk>
- David Mitchell <davem@iabyn.com>
- David Steinbrunner <dsteinbrunner@pobox.com>
- Edward Zborowski <ed@rubensteintech.com>
- Gareth Harper <gareth@broadbean.com>
- James Raspass <jraspass@gmail.com>
- Jerry D. Hedden <jdhedden@cpan.org>
- Josh Jore <jjore@cpan.org>
- Kent Fredric <kentnl@cpan.org>
- Leon Timmermans <fawaka@gmail.com>
- Peter Rabbitson <ribasushi@cpan.org>
- Steve Hay <steve.m.hay@googlemail.com>
all of them ate, honestly.
π COPYRIGHT & LICENSE π
original code Copyright (c) 2001-2011 Ken Williams. additional code Copyright (c) 2010-2011 Matt Trout and David Golden. all rights reserved.
this library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. so like, go off.
and that's the whole page, bestie! brought to you by perl v5.42.3, dated 2026-11-03. Module::Metadata(3pm) β she's iconic, she's thorough, she's here to help. π β¨
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms