MODULE::METADATA(3perl)
πΈ Module::Metadata π
okay so bestie, welcome to Module::Metadata, a page from the Perl Programmers Reference Guide. she lives at Module::Metadata(3perl) and here's the whole tea. β¨
β¨ NAME β¨
Module::Metadata β gather package and POD information from perl module files. that's it, that's the job. π
π¦ VERSION π¦
version 1.000039. slay.
π SYNOPSIS π
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. it does it through (mostly) static analysis and (some) actual code execution. and when it's figuring out the version of a module, the $VERSION assignment gets evaled β which is, like, the traditional thing in the CPAN toolchain. periodt.
π CLASS METHODS π
π new_from_file($filename, collect_pod => 1, decode_pod => 1)
makes you a Module::Metadata object when you hand it the path to a file. if the filename doesn't exist? returns undef, sorry babe. π
collect_pod is an optional boolean that decides whether POD data gets collected and stored for reference. POD data is not collected by default. POD headings are always collected though, no matter what. πββοΈ
if the file starts with a UTF-8, UTF-16BE or UTF-16LE byte-order mark, it gets skipped before processing, and the content of the file is also decoded appropriately starting from perl 5.8. iconic behavior.
alternatively β if decode_pod is set, it'll decode the collected pod sections according to the =encoding declaration.
π¦ new_from_handle($handle, $filename, collect_pod => 1, decode_pod => 1)
works exactly like new_from_file, except you can hand it a handle as the first argument instead.
β οΈ ok important: there is no validation to confirm the handle is a handle or something that can act like one. passing something that isn't a handle will cause an exception when it tries to read from it. and the filename argument is mandatory or undef gets returned. no filename, no vibes.
you are responsible for setting the decoding layers on $handle if required. that's on you bestie. π
πΈ new_from_module($module, collect_pod => 1, inc => \@dirs, decode_pod => 1)
constructs a Module::Metadata object from a module or package name. returns undef if the module can't be found. π₯²
besides accepting the collect_pod and decode_pod arguments described above, this one also takes an inc argument, which is a reference to an array of directories to search for the module. if you give none, the default is @INC.
if the file containing the module starts with a UTF-8, UTF-16BE or UTF-16LE byte-order mark, it's skipped before processing, and the content of the file is also decoded appropriately starting from perl 5.8.
π find_module_by_name($module, \@dirs)
gives you back the path to a module when you hand it the module or package name. you can optionally pass in a list of directories, otherwise @INC gets searched.
can be called as either an object method or a class method. flexible queen. β¨
π 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 either an object or a class method. π«Ά
π provides( %options )
this is a cute lil convenience wrapper around package_versions_from_directory that generates a CPAN META provides data structure. it takes key/value pairs. the valid option keys are:
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 if an unsupported version is given, thenprovideswill throw an error. π₯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).
note that the file path is relative to $dir if that's specified. this must not be used directly for CPAN META provides. see the provides method instead. π
π log_info (internal)
used internally to perform logging; imported from Log::Contextual if Log::Contextual has already been loaded, otherwise it just calls warn. lowkey doing its own thing.
π§ 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'.
π version($package)
returns the version as defined by the $VERSION variable for the package as returned by the name method, if you don't give it any arguments. 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. π
πΈ 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. spooky but valid. π»
π 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 it's left up to the caller how to handle those. you're on your own for that one bestie. π
π¦ pod_inside()
returns a list of POD sections.
β¨ contains_pod()
returns true if there's any POD in the file.
π 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 don't come for her about that. π€
π«Ά GIVING THANKS π«Ά
if you found this module to be useful, please show your appreciation by adding a +1 in MetaCPAN at https://metacpan.org/dist/Module-Metadata and a star in GitHub at https://github.com/Perl-Toolchain-Gang/Module-Metadata. it's giving gratitude, it's giving support. π
π SUPPORT π
bugs may be submitted through the RT bug tracker at https://rt.cpan.org/Public/Dist/Display.html?Name=Module-Metadata (or 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.
there's also an irc channel available for users of this distribution, at #toolchain on irc.perl.org β that's irc://irc.perl.org/#toolchain. come say hi. πΈ
π 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, honestly. π₯
π 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> - Erik Huelsmann
<ehuels@gmail.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>
every single one of them, we love to see it. π«Άβ¨
π 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.
okay and the cute sign-off bestie: this whole page is from perl v5.44.0, dated 2026-10-17, and it's the manual page for Module::Metadata(3perl). that's the source and the date, right there at the bottom like a lil bow on a gift. ππ go gather that metadata, you icon. π
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms