{
    "mode": "perldoc",
    "parameter": "Module::Metadata",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Module%3A%3AMetadata/json",
    "generated": "2026-06-09T16:48:42Z",
    "synopsis": "use Module::Metadata;\n# information about a .pm file\nmy $info = Module::Metadata->newfromfile( $file );\nmy $version = $info->version;\n# CPAN META 'provides' field for .pm files in a directory\nmy $provides = Module::Metadata->provides(\ndir => 'lib', version => 2\n);",
    "sections": {
        "NAME": {
            "content": "Module::Metadata - Gather package and POD information from perl module files\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 1.000037\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Module::Metadata;\n\n# information about a .pm file\nmy $info = Module::Metadata->newfromfile( $file );\nmy $version = $info->version;\n\n# CPAN META 'provides' field for .pm files in a directory\nmy $provides = Module::Metadata->provides(\ndir => 'lib', version => 2\n);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module provides a standard way to gather metadata about a .pm file through (mostly) static\nanalysis and (some) code execution. When determining the version of a module, the $VERSION\nassignment is \"eval\"ed, as is traditional in the CPAN toolchain.\n",
            "subsections": []
        },
        "CLASS METHODS": {
            "content": "\"newfromfile($filename, collectpod => 1, decodepod => 1)\"\nConstructs a \"Module::Metadata\" object given the path to a file. Returns undef if the filename\ndoes not exist.\n\n\"collectpod\" is a optional boolean argument that determines whether POD data is collected and\nstored for reference. POD data is not collected by default. POD headings are always collected.\n\nIf the file begins by an UTF-8, UTF-16BE or UTF-16LE byte-order mark, then it is skipped before\nprocessing, and the content of the file is also decoded appropriately starting from perl 5.8.\n\nAlternatively, if \"decodepod\" is set, it will decode the collected pod sections according to\nthe \"=encoding\" declaration.\n\n\"newfromhandle($handle, $filename, collectpod => 1, decodepod => 1)\"\nThis works just like \"newfromfile\", except that a handle can be provided as the first\nargument.\n\nNote that there is no validation to confirm that the handle is a handle or something that can\nact like one. Passing something that isn't a handle will cause a exception when trying to read\nfrom it. The \"filename\" argument is mandatory or undef will be returned.\n\nYou are responsible for setting the decoding layers on $handle if required.\n\n\"newfrommodule($module, collectpod => 1, inc => \\@dirs, decodepod => 1)\"\nConstructs a \"Module::Metadata\" object given a module or package name. Returns undef if the\nmodule cannot be found.\n\nIn addition to accepting the \"collectpod\" and \"decodepod\" arguments as described above, this\nmethod accepts a \"inc\" argument which is a reference to an array of directories to search for\nthe module. If none are given, the default is @INC.\n\nIf the file that contains the module begins by an UTF-8, UTF-16BE or UTF-16LE byte-order mark,\nthen it is skipped before processing, and the content of the file is also decoded appropriately\nstarting from perl 5.8.\n\n\"findmodulebyname($module, \\@dirs)\"\nReturns the path to a module given the module or package name. A list of directories can be\npassed in as an optional parameter, otherwise @INC is searched.\n\nCan be called as either an object or a class method.\n\n\"findmoduledirbyname($module, \\@dirs)\"\nReturns the entry in @dirs (or @INC by default) that contains the module $module. A list of\ndirectories can be passed in as an optional parameter, otherwise @INC is searched.\n\nCan be called as either an object or a class method.\n\n\"provides( %options )\"\nThis is a convenience wrapper around \"packageversionsfromdirectory\" to generate a CPAN META\n\"provides\" data structure. It takes key/value pairs. Valid option keys include:\n\nversion (required)\nSpecifies which version of the CPAN::Meta::Spec should be used as the format of the\n\"provides\" output. Currently only '1.4' and '2' are supported (and their format is\nidentical). This may change in the future as the definition of \"provides\" changes.\n\nThe \"version\" option is required. If it is omitted or if an unsupported version is given,\nthen \"provides\" will throw an error.\n\ndir Directory to search recursively for .pm files. May not be specified with \"files\".\n\nfiles\nArray reference of files to examine. May not be specified with \"dir\".\n\nprefix\nString to prepend to the \"file\" field of the resulting output. This defaults to lib, which\nis the common case for most CPAN distributions with their .pm files in lib. This option\nensures the META information has the correct relative path even when the \"dir\" or \"files\"\narguments are absolute or have relative paths from a location other than the distribution\nroot.\n\nFor example, given \"dir\" of 'lib' and \"prefix\" of 'lib', the return value is a hashref of the\nform:\n\n{\n'Package::Name' => {\nversion => '0.123',\nfile => 'lib/Package/Name.pm'\n},\n'OtherPackage::Name' => ...\n}\n\n\"packageversionsfromdirectory($dir, \\@files?)\"\nScans $dir for .pm files (unless @files is given, in which case looks for those files in $dir -\nand reads each file for packages and versions, returning a hashref of the form:\n\n{\n'Package::Name' => {\nversion => '0.123',\nfile => 'Package/Name.pm'\n},\n'OtherPackage::Name' => ...\n}\n\nThe \"DB\" and \"main\" packages are always omitted, as are any \"private\" packages that have leading\nunderscores in the namespace (e.g. \"Foo::private\")\n\nNote that the file path is relative to $dir if that is specified. This must not be used directly\nfor CPAN META \"provides\". See the \"provides\" method instead.\n\n\"loginfo (internal)\"\nUsed internally to perform logging; imported from Log::Contextual if Log::Contextual has already\nbeen loaded, otherwise simply calls warn.\n",
            "subsections": []
        },
        "OBJECT METHODS": {
            "content": "\"name()\"\nReturns the name of the package represented by this module. If there is more than one package,\nit makes a best guess based on the filename. If it's a script (i.e. not a *.pm) the package name\nis 'main'.\n\n\"version($package)\"\nReturns the version as defined by the $VERSION variable for the package as returned by the\n\"name\" method if no arguments are given. If given the name of a package it will attempt to\nreturn the version of that package if it is specified in the file.\n\n\"filename()\"\nReturns the absolute path to the file. Note that this file may not actually exist on disk yet,\ne.g. if the module was read from an in-memory filehandle.\n\n\"packagesinside()\"\nReturns a list of packages. Note: this is a raw list of packages discovered (or assumed, in the\ncase of \"main\"). It is not filtered for \"DB\", \"main\" or private packages the way the \"provides\"\nmethod does. Invalid package names are not returned, for example \"Foo:Bar\". Strange but valid\npackage names are returned, for example \"Foo::Bar::\", and are left up to the caller on how to\nhandle.\n\n\"podinside()\"\nReturns a list of POD sections.\n\n\"containspod()\"\nReturns true if there is any POD in the file.\n\n\"pod($section)\"\nReturns the POD data in the given section.\n\n\"isindexable($package)\" or \"isindexable()\"\nAvailable since version 1.000020.\n\nReturns a boolean indicating whether the package (if provided) or any package (otherwise) is\neligible for indexing by PAUSE, the Perl Authors Upload Server. Note This only checks for valid\n\"package\" declarations, and does not take any ownership information into account.\n",
            "subsections": []
        },
        "SUPPORT": {
            "content": "Bugs may be submitted through the RT bug tracker\n<https://rt.cpan.org/Public/Dist/Display.html?Name=Module-Metadata> (or\nbug-Module-Metadata@rt.cpan.org <mailto:bug-Module-Metadata@rt.cpan.org>).\n\nThere is also a mailing list available for users of this distribution, at\n<http://lists.perl.org/list/cpan-workers.html>.\n\nThere is also an irc channel available for users of this distribution, at \"#toolchain\" on\n\"irc.perl.org\" <irc://irc.perl.org/#toolchain>.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Original code from Module::Build::ModuleInfo by Ken Williams <kwilliams@cpan.org>, Randy W. Sims\n<RandyS@ThePierianSpring.org>\n\nReleased as Module::Metadata by Matt S Trout (mst) <mst@shadowcat.co.uk> with assistance from\nDavid Golden (xdg) <dagolden@cpan.org>.\n",
            "subsections": []
        },
        "CONTRIBUTORS": {
            "content": "*   Karen Etheridge <ether@cpan.org>\n\n*   David Golden <dagolden@cpan.org>\n\n*   Vincent Pit <perl@profvince.com>\n\n*   Matt S Trout <mst@shadowcat.co.uk>\n\n*   Chris Nehren <apeiron@cpan.org>\n\n*   Tomas Doran <bobtfish@bobtfish.net>\n\n*   Olivier Mengué <dolmen@cpan.org>\n\n*   Graham Knop <haarg@haarg.org>\n\n*   tokuhirom <tokuhirom@gmail.com>\n\n*   Tatsuhiko Miyagawa <miyagawa@bulknews.net>\n\n*   Christian Walde <walde.christian@googlemail.com>\n\n*   Leon Timmermans <fawaka@gmail.com>\n\n*   Peter Rabbitson <ribasushi@cpan.org>\n\n*   Steve Hay <steve.m.hay@googlemail.com>\n\n*   Jerry D. Hedden <jdhedden@cpan.org>\n\n*   Craig A. Berry <cberry@cpan.org>\n\n*   Craig A. Berry <craigberry@mac.com>\n\n*   David Mitchell <davem@iabyn.com>\n\n*   David Steinbrunner <dsteinbrunner@pobox.com>\n\n*   Edward Zborowski <ed@rubensteintech.com>\n\n*   Gareth Harper <gareth@broadbean.com>\n\n*   James Raspass <jraspass@gmail.com>\n\n*   Chris 'BinGOs' Williams <chris@bingosnet.co.uk>\n\n*   Josh Jore <jjore@cpan.org>\n\n*   Kent Fredric <kentnl@cpan.org>\n\nCOPYRIGHT & LICENSE\nOriginal code Copyright (c) 2001-2011 Ken Williams. Additional code Copyright (c) 2010-2011 Matt\nTrout and David Golden. All rights reserved.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "Module::Metadata - Gather package and POD information from perl module files",
    "flags": [],
    "examples": [],
    "see_also": []
}