1Module::Metadata(3)   User Contributed Perl Documentation  Module::Metadata(3)
2
3
4

NAME

6       Module::Metadata - Gather package and POD information from perl module
7       files
8

VERSION

10       version 1.000036
11

SYNOPSIS

13         use Module::Metadata;
14
15         # information about a .pm file
16         my $info = Module::Metadata->new_from_file( $file );
17         my $version = $info->version;
18
19         # CPAN META 'provides' field for .pm files in a directory
20         my $provides = Module::Metadata->provides(
21           dir => 'lib', version => 2
22         );
23

DESCRIPTION

25       This module provides a standard way to gather metadata about a .pm file
26       through (mostly) static analysis and (some) code execution.  When
27       determining the version of a module, the $VERSION assignment is
28       "eval"ed, as is traditional in the CPAN toolchain.
29

CLASS METHODS

31   "new_from_file($filename, collect_pod => 1)"
32       Constructs a "Module::Metadata" object given the path to a file.
33       Returns undef if the filename does not exist.
34
35       "collect_pod" is a optional boolean argument that determines whether
36       POD data is collected and stored for reference.  POD data is not
37       collected by default.  POD headings are always collected.
38
39       If the file begins by an UTF-8, UTF-16BE or UTF-16LE byte-order mark,
40       then it is skipped before processing, and the content of the file is
41       also decoded appropriately starting from perl 5.8.
42
43   "new_from_handle($handle, $filename, collect_pod => 1)"
44       This works just like "new_from_file", except that a handle can be
45       provided as the first argument.
46
47       Note that there is no validation to confirm that the handle is a handle
48       or something that can act like one.  Passing something that isn't a
49       handle will cause a exception when trying to read from it.  The
50       "filename" argument is mandatory or undef will be returned.
51
52       You are responsible for setting the decoding layers on $handle if
53       required.
54
55   "new_from_module($module, collect_pod => 1, inc => \@dirs)"
56       Constructs a "Module::Metadata" object given a module or package name.
57       Returns undef if the module cannot be found.
58
59       In addition to accepting the "collect_pod" argument as described above,
60       this method accepts a "inc" argument which is a reference to an array
61       of directories to search for the module.  If none are given, the
62       default is @INC.
63
64       If the file that contains the module begins by an UTF-8, UTF-16BE or
65       UTF-16LE byte-order mark, then it is skipped before processing, and the
66       content of the file is also decoded appropriately starting from perl
67       5.8.
68
69   "find_module_by_name($module, \@dirs)"
70       Returns the path to a module given the module or package name. A list
71       of directories can be passed in as an optional parameter, otherwise
72       @INC is searched.
73
74       Can be called as either an object or a class method.
75
76   "find_module_dir_by_name($module, \@dirs)"
77       Returns the entry in @dirs (or @INC by default) that contains the
78       module $module. A list of directories can be passed in as an optional
79       parameter, otherwise @INC is searched.
80
81       Can be called as either an object or a class method.
82
83   "provides( %options )"
84       This is a convenience wrapper around "package_versions_from_directory"
85       to generate a CPAN META "provides" data structure.  It takes key/value
86       pairs.  Valid option keys include:
87
88       version (required)
89           Specifies which version of the CPAN::Meta::Spec should be used as
90           the format of the "provides" output.  Currently only '1.4' and '2'
91           are supported (and their format is identical).  This may change in
92           the future as the definition of "provides" changes.
93
94           The "version" option is required.  If it is omitted or if an
95           unsupported version is given, then "provides" will throw an error.
96
97       dir Directory to search recursively for .pm files.  May not be
98           specified with "files".
99
100       files
101           Array reference of files to examine.  May not be specified with
102           "dir".
103
104       prefix
105           String to prepend to the "file" field of the resulting output. This
106           defaults to lib, which is the common case for most CPAN
107           distributions with their .pm files in lib.  This option ensures the
108           META information has the correct relative path even when the "dir"
109           or "files" arguments are absolute or have relative paths from a
110           location other than the distribution root.
111
112       For example, given "dir" of 'lib' and "prefix" of 'lib', the return
113       value is a hashref of the form:
114
115         {
116           'Package::Name' => {
117             version => '0.123',
118             file => 'lib/Package/Name.pm'
119           },
120           'OtherPackage::Name' => ...
121         }
122
123   "package_versions_from_directory($dir, \@files?)"
124       Scans $dir for .pm files (unless @files is given, in which case looks
125       for those files in $dir - and reads each file for packages and
126       versions, returning a hashref of the form:
127
128         {
129           'Package::Name' => {
130             version => '0.123',
131             file => 'Package/Name.pm'
132           },
133           'OtherPackage::Name' => ...
134         }
135
136       The "DB" and "main" packages are always omitted, as are any "private"
137       packages that have leading underscores in the namespace (e.g.
138       "Foo::_private")
139
140       Note that the file path is relative to $dir if that is specified.  This
141       must not be used directly for CPAN META "provides".  See the "provides"
142       method instead.
143
144   "log_info (internal)"
145       Used internally to perform logging; imported from Log::Contextual if
146       Log::Contextual has already been loaded, otherwise simply calls warn.
147

OBJECT METHODS

149   "name()"
150       Returns the name of the package represented by this module. If there is
151       more than one package, it makes a best guess based on the filename. If
152       it's a script (i.e. not a *.pm) the package name is 'main'.
153
154   "version($package)"
155       Returns the version as defined by the $VERSION variable for the package
156       as returned by the "name" method if no arguments are given. If given
157       the name of a package it will attempt to return the version of that
158       package if it is specified in the file.
159
160   "filename()"
161       Returns the absolute path to the file.  Note that this file may not
162       actually exist on disk yet, e.g. if the module was read from an in-
163       memory filehandle.
164
165   "packages_inside()"
166       Returns a list of packages. Note: this is a raw list of packages
167       discovered (or assumed, in the case of "main").  It is not filtered for
168       "DB", "main" or private packages the way the "provides" method does.
169       Invalid package names are not returned, for example "Foo:Bar".  Strange
170       but valid package names are returned, for example "Foo::Bar::", and are
171       left up to the caller on how to handle.
172
173   "pod_inside()"
174       Returns a list of POD sections.
175
176   "contains_pod()"
177       Returns true if there is any POD in the file.
178
179   "pod($section)"
180       Returns the POD data in the given section.
181
182   "is_indexable($package)" or "is_indexable()"
183       Available since version 1.000020.
184
185       Returns a boolean indicating whether the package (if provided) or any
186       package (otherwise) is eligible for indexing by PAUSE, the Perl Authors
187       Upload Server.  Note This only checks for valid "package" declarations,
188       and does not take any ownership information into account.
189

SUPPORT

191       Bugs may be submitted through the RT bug tracker
192       <https://rt.cpan.org/Public/Dist/Display.html?Name=Module-Metadata> (or
193       bug-Module-Metadata@rt.cpan.org <mailto:bug-Module-
194       Metadata@rt.cpan.org>).
195
196       There is also a mailing list available for users of this distribution,
197       at <http://lists.perl.org/list/cpan-workers.html>.
198
199       There is also an irc channel available for users of this distribution,
200       at "#toolchain" on "irc.perl.org" <irc://irc.perl.org/#toolchain>.
201

AUTHOR

203       Original code from Module::Build::ModuleInfo by Ken Williams
204       <kwilliams@cpan.org>, Randy W. Sims <RandyS@ThePierianSpring.org>
205
206       Released as Module::Metadata by Matt S Trout (mst)
207       <mst@shadowcat.co.uk> with assistance from David Golden (xdg)
208       <dagolden@cpan.org>.
209

CONTRIBUTORS

211       ·   Karen Etheridge <ether@cpan.org>
212
213       ·   David Golden <dagolden@cpan.org>
214
215       ·   Vincent Pit <perl@profvince.com>
216
217       ·   Matt S Trout <mst@shadowcat.co.uk>
218
219       ·   Chris Nehren <apeiron@cpan.org>
220
221       ·   Graham Knop <haarg@haarg.org>
222
223       ·   Olivier Mengué <dolmen@cpan.org>
224
225       ·   Tomas Doran <bobtfish@bobtfish.net>
226
227       ·   tokuhirom <tokuhirom@gmail.com>
228
229       ·   Christian Walde <walde.christian@googlemail.com>
230
231       ·   Tatsuhiko Miyagawa <miyagawa@bulknews.net>
232
233       ·   Peter Rabbitson <ribasushi@cpan.org>
234
235       ·   Steve Hay <steve.m.hay@googlemail.com>
236
237       ·   Jerry D. Hedden <jdhedden@cpan.org>
238
239       ·   Craig A. Berry <cberry@cpan.org>
240
241       ·   Craig A. Berry <craigberry@mac.com>
242
243       ·   David Mitchell <davem@iabyn.com>
244
245       ·   David Steinbrunner <dsteinbrunner@pobox.com>
246
247       ·   Edward Zborowski <ed@rubensteintech.com>
248
249       ·   Gareth Harper <gareth@broadbean.com>
250
251       ·   James Raspass <jraspass@gmail.com>
252
253       ·   Chris 'BinGOs' Williams <chris@bingosnet.co.uk>
254
255       ·   Josh Jore <jjore@cpan.org>
256
257       ·   Kent Fredric <kentnl@cpan.org>
258
260       Original code Copyright (c) 2001-2011 Ken Williams.  Additional code
261       Copyright (c) 2010-2011 Matt Trout and David Golden.  All rights
262       reserved.
263
264       This library is free software; you can redistribute it and/or modify it
265       under the same terms as Perl itself.
266
267
268
269perl v5.28.1                      2019-04-18               Module::Metadata(3)
Impressum