xref: /openbsd-src/gnu/usr.bin/perl/cpan/CPAN-Meta/lib/CPAN/Meta/Spec.pm (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1# XXX RULES FOR PATCHING THIS FILE XXX
2# Patches that fix typos or formatting are acceptable.  Patches
3# that change semantics are not acceptable without prior approval
4# by David Golden or Ricardo Signes.
5
6use 5.006;
7use strict;
8use warnings;
9package CPAN::Meta::Spec;
10our $VERSION = '2.140640'; # VERSION
11
121;
13
14# ABSTRACT: specification for CPAN distribution metadata
15
16
17# vi:tw=72
18
19__END__
20
21=pod
22
23=encoding UTF-8
24
25=head1 NAME
26
27CPAN::Meta::Spec - specification for CPAN distribution metadata
28
29=head1 VERSION
30
31version 2.140640
32
33=head1 SYNOPSIS
34
35  my $distmeta = {
36    name => 'Module-Build',
37    abstract => 'Build and install Perl modules',
38    description =>  "Module::Build is a system for "
39      . "building, testing, and installing Perl modules. "
40      . "It is meant to ... blah blah blah ...",
41    version  => '0.36',
42    release_status => 'stable',
43    author   => [
44      'Ken Williams <kwilliams@cpan.org>',
45      'Module-Build List <module-build@perl.org>', # additional contact
46    ],
47    license  => [ 'perl_5' ],
48    prereqs => {
49      runtime => {
50        requires => {
51          'perl'   => '5.006',
52          'ExtUtils::Install' => '0',
53          'File::Basename' => '0',
54          'File::Compare'  => '0',
55          'IO::File'   => '0',
56        },
57        recommends => {
58          'Archive::Tar' => '1.00',
59          'ExtUtils::Install' => '0.3',
60          'ExtUtils::ParseXS' => '2.02',
61        },
62      },
63      build => {
64        requires => {
65          'Test::More' => '0',
66        },
67      }
68    },
69    resources => {
70      license => ['http://dev.perl.org/licenses/'],
71    },
72    optional_features => {
73      domination => {
74        description => 'Take over the world',
75        prereqs     => {
76          develop => { requires => { 'Genius::Evil'     => '1.234' } },
77          runtime => { requires => { 'Machine::Weather' => '2.0'   } },
78        },
79      },
80    },
81    dynamic_config => 1,
82    keywords => [ qw/ toolchain cpan dual-life / ],
83    'meta-spec' => {
84      version => '2',
85      url     => 'https://metacpan.org/pod/CPAN::Meta::Spec',
86    },
87    generated_by => 'Module::Build version 0.36',
88  };
89
90=head1 DESCRIPTION
91
92This document describes version 2 of the CPAN distribution metadata
93specification, also known as the "CPAN Meta Spec".
94
95Revisions of this specification for typo corrections and prose
96clarifications may be issued as CPAN::Meta::Spec 2.I<x>.  These
97revisions will never change semantics or add or remove specified
98behavior.
99
100Distribution metadata describe important properties of Perl
101distributions. Distribution building tools like Module::Build,
102Module::Install, ExtUtils::MakeMaker or Dist::Zilla should create a
103metadata file in accordance with this specification and include it with
104the distribution for use by automated tools that index, examine, package
105or install Perl distributions.
106
107=head1 TERMINOLOGY
108
109=over 4
110
111=item distribution
112
113This is the primary object described by the metadata. In the context of
114this document it usually refers to a collection of modules, scripts,
115and/or documents that are distributed together for other developers to
116use.  Examples of distributions are C<Class-Container>, C<libwww-perl>,
117or C<DBI>.
118
119=item module
120
121This refers to a reusable library of code contained in a single file.
122Modules usually contain one or more packages and are often referred
123to by the name of a primary package that can be mapped to the file
124name. For example, one might refer to C<File::Spec> instead of
125F<File/Spec.pm>
126
127=item package
128
129This refers to a namespace declared with the Perl C<package> statement.
130In Perl, packages often have a version number property given by the
131C<$VERSION> variable in the namespace.
132
133=item consumer
134
135This refers to code that reads a metadata file, deserializes it into a
136data structure in memory, or interprets a data structure of metadata
137elements.
138
139=item producer
140
141This refers to code that constructs a metadata data structure,
142serializes into a bytestream and/or writes it to disk.
143
144=item must, should, may, etc.
145
146These terms are interpreted as described in IETF RFC 2119.
147
148=back
149
150=head1 DATA TYPES
151
152Fields in the L</STRUCTURE> section describe data elements, each of
153which has an associated data type as described herein.  There are four
154primitive types: Boolean, String, List and Map.  Other types are
155subtypes of primitives and define compound data structures or define
156constraints on the values of a data element.
157
158=head2 Boolean
159
160A I<Boolean> is used to provide a true or false value.  It B<must> be
161represented as a defined value.
162
163=head2 String
164
165A I<String> is data element containing a non-zero length sequence of
166Unicode characters, such as an ordinary Perl scalar that is not a
167reference.
168
169=head2 List
170
171A I<List> is an ordered collection of zero or more data elements.
172Elements of a List may be of mixed types.
173
174Producers B<must> represent List elements using a data structure which
175unambiguously indicates that multiple values are possible, such as a
176reference to a Perl array (an "arrayref").
177
178Consumers expecting a List B<must> consider a String as equivalent to a
179List of length 1.
180
181=head2 Map
182
183A I<Map> is an unordered collection of zero or more data elements
184("values"), indexed by associated String elements ("keys").  The Map's
185value elements may be of mixed types.
186
187=head2 License String
188
189A I<License String> is a subtype of String with a restricted set of
190values.  Valid values are described in detail in the description of
191the L</license> field.
192
193=head2 URL
194
195I<URL> is a subtype of String containing a Uniform Resource Locator or
196Identifier.  [ This type is called URL and not URI for historical reasons. ]
197
198=head2 Version
199
200A I<Version> is a subtype of String containing a value that describes
201the version number of packages or distributions.  Restrictions on format
202are described in detail in the L</Version Formats> section.
203
204=head2 Version Range
205
206The I<Version Range> type is a subtype of String.  It describes a range
207of Versions that may be present or installed to fulfill prerequisites.
208It is specified in detail in the L</Version Ranges> section.
209
210=head1 STRUCTURE
211
212The metadata structure is a data element of type Map.  This section
213describes valid keys within the Map.
214
215Any keys not described in this specification document (whether top-level
216or within compound data structures described herein) are considered
217I<custom keys> and B<must> begin with an "x" or "X" and be followed by an
218underscore; i.e. they must match the pattern: C<< qr{\Ax_}i >>.  If a
219custom key refers to a compound data structure, subkeys within it do not
220need an "x_" or "X_" prefix.
221
222Consumers of metadata may ignore any or all custom keys.  All other keys
223not described herein are invalid and should be ignored by consumers.
224Producers must not generate or output invalid keys.
225
226For each key, an example is provided followed by a description.  The
227description begins with the version of spec in which the key was added
228or in which the definition was modified, whether the key is I<required>
229or I<optional> and the data type of the corresponding data element.
230These items are in parentheses, brackets and braces, respectively.
231
232If a data type is a Map or Map subtype, valid subkeys will be described
233as well.
234
235Some fields are marked I<Deprecated>.  These are shown for historical
236context and must not be produced in or consumed from any metadata structure
237of version 2 or higher.
238
239=head2 REQUIRED FIELDS
240
241=head3 abstract
242
243Example:
244
245  abstract => 'Build and install Perl modules'
246
247(Spec 1.2) [required] {String}
248
249This is a short description of the purpose of the distribution.
250
251=head3 author
252
253Example:
254
255  author => [ 'Ken Williams <kwilliams@cpan.org>' ]
256
257(Spec 1.2) [required] {List of one or more Strings}
258
259This List indicates the person(s) to contact concerning the
260distribution. The preferred form of the contact string is:
261
262  contact-name <email-address>
263
264This field provides a general contact list independent of other
265structured fields provided within the L</resources> field, such as
266C<bugtracker>.  The addressee(s) can be contacted for any purpose
267including but not limited to (security) problems with the distribution,
268questions about the distribution or bugs in the distribution.
269
270A distribution's original author is usually the contact listed within
271this field.  Co-maintainers, successor maintainers or mailing lists
272devoted to the distribution may also be listed in addition to or instead
273of the original author.
274
275=head3 dynamic_config
276
277Example:
278
279  dynamic_config => 1
280
281(Spec 2) [required] {Boolean}
282
283A boolean flag indicating whether a F<Build.PL> or F<Makefile.PL> (or
284similar) must be executed to determine prerequisites.
285
286This field should be set to a true value if the distribution performs
287some dynamic configuration (asking questions, sensing the environment,
288etc.) as part of its configuration.  This field should be set to a false
289value to indicate that prerequisites included in metadata may be
290considered final and valid for static analysis.
291
292This field explicitly B<does not> indicate whether installation may be
293safely performed without using a Makefile or Build file, as there may be
294special files to install or custom installation targets (e.g. for
295dual-life modules that exist on CPAN as well as in the Perl core).  This
296field only defines whether prerequisites are complete as given in the
297metadata.
298
299=head3 generated_by
300
301Example:
302
303  generated_by => 'Module::Build version 0.36'
304
305(Spec 1.0) [required] {String}
306
307This field indicates the tool that was used to create this metadata.
308There are no defined semantics for this field, but it is traditional to
309use a string in the form "Generating::Package version 1.23" or the
310author's name, if the file was generated by hand.
311
312=head3 license
313
314Example:
315
316  license => [ 'perl_5' ]
317
318  license => [ 'apache_2_0', 'mozilla_1_0' ]
319
320(Spec 2) [required] {List of one or more License Strings}
321
322One or more licenses that apply to some or all of the files in the
323distribution.  If multiple licenses are listed, the distribution
324documentation should be consulted to clarify the interpretation of
325multiple licenses.
326
327The following list of license strings are valid:
328
329 string          description
330 -------------   -----------------------------------------------
331 agpl_3          GNU Affero General Public License, Version 3
332 apache_1_1      Apache Software License, Version 1.1
333 apache_2_0      Apache License, Version 2.0
334 artistic_1      Artistic License, (Version 1)
335 artistic_2      Artistic License, Version 2.0
336 bsd             BSD License (three-clause)
337 freebsd         FreeBSD License (two-clause)
338 gfdl_1_2        GNU Free Documentation License, Version 1.2
339 gfdl_1_3        GNU Free Documentation License, Version 1.3
340 gpl_1           GNU General Public License, Version 1
341 gpl_2           GNU General Public License, Version 2
342 gpl_3           GNU General Public License, Version 3
343 lgpl_2_1        GNU Lesser General Public License, Version 2.1
344 lgpl_3_0        GNU Lesser General Public License, Version 3.0
345 mit             MIT (aka X11) License
346 mozilla_1_0     Mozilla Public License, Version 1.0
347 mozilla_1_1     Mozilla Public License, Version 1.1
348 openssl         OpenSSL License
349 perl_5          The Perl 5 License (Artistic 1 & GPL 1 or later)
350 qpl_1_0         Q Public License, Version 1.0
351 ssleay          Original SSLeay License
352 sun             Sun Internet Standards Source License (SISSL)
353 zlib            zlib License
354
355The following license strings are also valid and indicate other
356licensing not described above:
357
358 string          description
359 -------------   -----------------------------------------------
360 open_source     Other Open Source Initiative (OSI) approved license
361 restricted      Requires special permission from copyright holder
362 unrestricted    Not an OSI approved license, but not restricted
363 unknown         License not provided in metadata
364
365All other strings are invalid in the license field.
366
367=head3 meta-spec
368
369Example:
370
371  'meta-spec' => {
372    version => '2',
373    url     => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec',
374  }
375
376(Spec 1.2) [required] {Map}
377
378This field indicates the version of the CPAN Meta Spec that should be
379used to interpret the metadata.  Consumers must check this key as soon
380as possible and abort further metadata processing if the meta-spec
381version is not supported by the consumer.
382
383The following keys are valid, but only C<version> is required.
384
385=over
386
387=item version
388
389This subkey gives the integer I<Version> of the CPAN Meta Spec against
390which the document was generated.
391
392=item url
393
394This is a I<URL> of the metadata specification document corresponding to
395the given version.  This is strictly for human-consumption and should
396not impact the interpretation of the document.
397
398For the version 2 spec, either of these are recommended:
399
400=over 4
401
402=item *
403
404C<https://metacpan.org/pod/CPAN::Meta::Spec>
405
406=item *
407
408C<http://search.cpan.org/perldoc?CPAN::Meta::Spec>
409
410=back
411
412=back
413
414=head3 name
415
416Example:
417
418  name => 'Module-Build'
419
420(Spec 1.0) [required] {String}
421
422This field is the name of the distribution.  This is often created by
423taking the "main package" in the distribution and changing C<::> to
424C<->, but the name may be completely unrelated to the packages within
425the distribution.  For example, L<LWP::UserAgent> is distributed as part
426of the distribution name "libwww-perl".
427
428=head3 release_status
429
430Example:
431
432  release_status => 'stable'
433
434(Spec 2) [required] {String}
435
436This field provides the  release status of this distribution.  If the
437C<version> field contains an underscore character, then
438C<release_status> B<must not> be "stable."
439
440The C<release_status> field B<must> have one of the following values:
441
442=over
443
444=item stable
445
446This indicates an ordinary, "final" release that should be indexed by PAUSE
447or other indexers.
448
449=item testing
450
451This indicates a "beta" release that is substantially complete, but has an
452elevated risk of bugs and requires additional testing.  The distribution
453should not be installed over a stable release without an explicit request
454or other confirmation from a user.  This release status may also be used
455for "release candidate" versions of a distribution.
456
457=item unstable
458
459This indicates an "alpha" release that is under active development, but has
460been released for early feedback or testing and may be missing features or
461may have serious bugs.  The distribution should not be installed over a
462stable release without an explicit request or other confirmation from a
463user.
464
465=back
466
467Consumers B<may> use this field to determine how to index the
468distribution for CPAN or other repositories in addition to or in
469replacement of heuristics based on version number or file name.
470
471=head3 version
472
473Example:
474
475  version => '0.36'
476
477(Spec 1.0) [required] {Version}
478
479This field gives the version of the distribution to which the metadata
480structure refers.
481
482=head2 OPTIONAL FIELDS
483
484=head3 description
485
486Example:
487
488    description =>  "Module::Build is a system for "
489      . "building, testing, and installing Perl modules. "
490      . "It is meant to ... blah blah blah ...",
491
492(Spec 2) [optional] {String}
493
494A longer, more complete description of the purpose or intended use of
495the distribution than the one provided by the C<abstract> key.
496
497=head3 keywords
498
499Example:
500
501  keywords => [ qw/ toolchain cpan dual-life / ]
502
503(Spec 1.1) [optional] {List of zero or more Strings}
504
505A List of keywords that describe this distribution.  Keywords
506B<must not> include whitespace.
507
508=head3 no_index
509
510Example:
511
512  no_index => {
513    file      => [ 'My/Module.pm' ],
514    directory => [ 'My/Private' ],
515    package   => [ 'My::Module::Secret' ],
516    namespace => [ 'My::Module::Sample' ],
517  }
518
519(Spec 1.2) [optional] {Map}
520
521This Map describes any files, directories, packages, and namespaces that
522are private to the packaging or implementation of the distribution and
523should be ignored by indexing or search tools.
524
525Valid subkeys are as follows:
526
527=over
528
529=item file
530
531A I<List> of relative paths to files.  Paths B<must be> specified with
532unix conventions.
533
534=item directory
535
536A I<List> of relative paths to directories.  Paths B<must be> specified
537with unix conventions.
538
539[ Note: previous editions of the spec had C<dir> instead of C<directory> ]
540
541=item package
542
543A I<List> of package names.
544
545=item namespace
546
547A I<List> of package namespaces, where anything below the namespace
548must be ignored, but I<not> the namespace itself.
549
550In the example above for C<no_index>, C<My::Module::Sample::Foo> would
551be ignored, but C<My::Module::Sample> would not.
552
553=back
554
555=head3 optional_features
556
557Example:
558
559  optional_features => {
560    sqlite => {
561      description => 'Provides SQLite support',
562      prereqs => {
563        runtime => {
564          requires => {
565            'DBD::SQLite' => '1.25'
566          }
567        }
568      }
569    }
570  }
571
572(Spec 2) [optional] {Map}
573
574This Map describes optional features with incremental prerequisites.
575Each key of the C<optional_features> Map is a String used to identify
576the feature and each value is a Map with additional information about
577the feature.  Valid subkeys include:
578
579=over
580
581=item description
582
583This is a String describing the feature.  Every optional feature
584should provide a description
585
586=item prereqs
587
588This entry is required and has the same structure as that of the
589C<L</prereqs>> key.  It provides a list of package requirements
590that must be satisfied for the feature to be supported or enabled.
591
592There is one crucial restriction:  the prereqs of an optional feature
593B<must not> include C<configure> phase prereqs.
594
595=back
596
597Consumers B<must not> include optional features as prerequisites without
598explicit instruction from users (whether via interactive prompting,
599a function parameter or a configuration value, etc. ).
600
601If an optional feature is used by a consumer to add additional
602prerequisites, the consumer should merge the optional feature
603prerequisites into those given by the C<prereqs> key using the same
604semantics.  See L</Merging and Resolving Prerequisites> for details on
605merging prerequisites.
606
607I<Suggestion for disuse:> Because there is currently no way for a
608distribution to specify a dependency on an optional feature of another
609dependency, the use of C<optional_feature> is discouraged.  Instead,
610create a separate, installable distribution that ensures the desired
611feature is available.  For example, if C<Foo::Bar> has a C<Baz> feature,
612release a separate C<Foo-Bar-Baz> distribution that satisfies
613requirements for the feature.
614
615=head3 prereqs
616
617Example:
618
619  prereqs => {
620    runtime => {
621      requires => {
622        'perl'          => '5.006',
623        'File::Spec'    => '0.86',
624        'JSON'          => '2.16',
625      },
626      recommends => {
627        'JSON::XS'      => '2.26',
628      },
629      suggests => {
630        'Archive::Tar'  => '0',
631      },
632    },
633    build => {
634      requires => {
635        'Alien::SDL'    => '1.00',
636      },
637    },
638    test => {
639      recommends => {
640        'Test::Deep'    => '0.10',
641      },
642    }
643  }
644
645(Spec 2) [optional] {Map}
646
647This is a Map that describes all the prerequisites of the distribution.
648The keys are phases of activity, such as C<configure>, C<build>, C<test>
649or C<runtime>.  Values are Maps in which the keys name the type of
650prerequisite relationship such as C<requires>, C<recommends>, or
651C<suggests> and the value provides a set of prerequisite relations.  The
652set of relations B<must> be specified as a Map of package names to
653version ranges.
654
655The full definition for this field is given in the L</Prereq Spec>
656section.
657
658=head3 provides
659
660Example:
661
662  provides => {
663    'Foo::Bar' => {
664      file    => 'lib/Foo/Bar.pm',
665      version => '0.27_02',
666    },
667    'Foo::Bar::Blah' => {
668      file    => 'lib/Foo/Bar/Blah.pm',
669    },
670    'Foo::Bar::Baz' => {
671      file    => 'lib/Foo/Bar/Baz.pm',
672      version => '0.3',
673    },
674  }
675
676(Spec 1.2) [optional] {Map}
677
678This describes all packages provided by this distribution.  This
679information is used by distribution and automation mechanisms like
680PAUSE, CPAN, metacpan.org and search.cpan.org to build indexes saying in
681which distribution various packages can be found.
682
683The keys of C<provides> are package names that can be found within
684the distribution.  If a package name key is provided, it must
685have a Map with the following valid subkeys:
686
687=over
688
689=item file
690
691This field is required.  It must contain a Unix-style relative file path
692from the root of the distribution directory to a file that contains or
693generates the package.
694
695=item version
696
697If it exists, this field must contains a I<Version> String for the
698package.  If the package does not have a C<$VERSION>, this field must
699be omitted.
700
701=back
702
703=head3 resources
704
705Example:
706
707  resources => {
708    license     => [ 'http://dev.perl.org/licenses/' ],
709    homepage    => 'http://sourceforge.net/projects/module-build',
710    bugtracker  => {
711      web    => 'http://rt.cpan.org/Public/Dist/Display.html?Name=CPAN-Meta',
712      mailto => 'meta-bugs@example.com',
713    },
714    repository  => {
715      url  => 'git://github.com/dagolden/cpan-meta.git',
716      web  => 'http://github.com/dagolden/cpan-meta',
717      type => 'git',
718    },
719    x_twitter   => 'http://twitter.com/cpan_linked/',
720  }
721
722(Spec 2) [optional] {Map}
723
724This field describes resources related to this distribution.
725
726Valid subkeys include:
727
728=over
729
730=item homepage
731
732The official home of this project on the web.
733
734=item license
735
736A List of I<URL>'s that relate to this distribution's license.  As with the
737top-level C<license> field, distribution documentation should be consulted
738to clarify the interpretation of multiple licenses provided here.
739
740=item bugtracker
741
742This entry describes the bug tracking system for this distribution.  It
743is a Map with the following valid keys:
744
745  web    - a URL pointing to a web front-end for the bug tracker
746  mailto - an email address to which bugs can be sent
747
748=item repository
749
750This entry describes the source control repository for this distribution.  It
751is a Map with the following valid keys:
752
753  url  - a URL pointing to the repository itself
754  web  - a URL pointing to a web front-end for the repository
755  type - a lowercase string indicating the VCS used
756
757Because a url like C<http://myrepo.example.com/> is ambiguous as to
758type, producers should provide a C<type> whenever a C<url> key is given.
759The C<type> field should be the name of the most common program used
760to work with the repository, e.g. C<git>, C<svn>, C<cvs>, C<darcs>,
761C<bzr> or C<hg>.
762
763=back
764
765=head2 DEPRECATED FIELDS
766
767=head3 build_requires
768
769I<(Deprecated in Spec 2)> [optional] {String}
770
771Replaced by C<prereqs>
772
773=head3 configure_requires
774
775I<(Deprecated in Spec 2)> [optional] {String}
776
777Replaced by C<prereqs>
778
779=head3 conflicts
780
781I<(Deprecated in Spec 2)> [optional] {String}
782
783Replaced by C<prereqs>
784
785=head3 distribution_type
786
787I<(Deprecated in Spec 2)> [optional] {String}
788
789This field indicated 'module' or 'script' but was considered
790meaningless, since many distributions are hybrids of several kinds of
791things.
792
793=head3 license_uri
794
795I<(Deprecated in Spec 1.2)> [optional] {URL}
796
797Replaced by C<license> in C<resources>
798
799=head3 private
800
801I<(Deprecated in Spec 1.2)> [optional] {Map}
802
803This field has been renamed to L</"no_index">.
804
805=head3 recommends
806
807I<(Deprecated in Spec 2)> [optional] {String}
808
809Replaced by C<prereqs>
810
811=head3 requires
812
813I<(Deprecated in Spec 2)> [optional] {String}
814
815Replaced by C<prereqs>
816
817=head1 VERSION NUMBERS
818
819=head2 Version Formats
820
821This section defines the Version type, used by several fields in the
822CPAN Meta Spec.
823
824Version numbers must be treated as strings, not numbers.  For
825example, C<1.200> B<must not> be serialized as C<1.2>.  Version
826comparison should be delegated to the Perl L<version> module, version
8270.80 or newer.
828
829Unless otherwise specified, version numbers B<must> appear in one of two
830formats:
831
832=over
833
834=item Decimal versions
835
836Decimal versions are regular "decimal numbers", with some limitations.
837They B<must> be non-negative and B<must> begin and end with a digit.  A
838single underscore B<may> be included, but B<must> be between two digits.
839They B<must not> use exponential notation ("1.23e-2").
840
841   version => '1.234'       # OK
842   version => '1.23_04'     # OK
843
844   version => '1.23_04_05'  # Illegal
845   version => '1.'          # Illegal
846   version => '.1'          # Illegal
847
848=item Dotted-integer versions
849
850Dotted-integer (also known as dotted-decimal) versions consist of
851positive integers separated by full stop characters (i.e. "dots",
852"periods" or "decimal points").  This are equivalent in format to Perl
853"v-strings", with some additional restrictions on form.  They must be
854given in "normal" form, which has a leading "v" character and at least
855three integer components.  To retain a one-to-one mapping with decimal
856versions, all components after the first B<should> be restricted to the
857range 0 to 999.  The final component B<may> be separated by an
858underscore character instead of a period.
859
860   version => 'v1.2.3'      # OK
861   version => 'v1.2_3'      # OK
862   version => 'v1.2.3.4'    # OK
863   version => 'v1.2.3_4'    # OK
864   version => 'v2009.10.31' # OK
865
866   version => 'v1.2'          # Illegal
867   version => '1.2.3'         # Illegal
868   version => 'v1.2_3_4'      # Illegal
869   version => 'v1.2009.10.31' # Not recommended
870
871=back
872
873=head2 Version Ranges
874
875Some fields (prereq, optional_features) indicate the particular
876version(s) of some other module that may be required as a prerequisite.
877This section details the Version Range type used to provide this
878information.
879
880The simplest format for a Version Range is just the version
881number itself, e.g. C<2.4>.  This means that B<at least> version 2.4
882must be present.  To indicate that B<any> version of a prerequisite is
883okay, even if the prerequisite doesn't define a version at all, use
884the version C<0>.
885
886Alternatively, a version range B<may> use the operators E<lt> (less than),
887E<lt>= (less than or equal), E<gt> (greater than), E<gt>= (greater than
888or equal), == (equal), and != (not equal).  For example, the
889specification C<E<lt> 2.0> means that any version of the prerequisite
890less than 2.0 is suitable.
891
892For more complicated situations, version specifications B<may> be AND-ed
893together using commas.  The specification C<E<gt>= 1.2, != 1.5, E<lt>
8942.0> indicates a version that must be B<at least> 1.2, B<less than> 2.0,
895and B<not equal to> 1.5.
896
897=head1 PREREQUISITES
898
899=head2 Prereq Spec
900
901The C<prereqs> key in the top-level metadata and within
902C<optional_features> define the relationship between a distribution and
903other packages.  The prereq spec structure is a hierarchical data
904structure which divides prerequisites into I<Phases> of activity in the
905installation process and I<Relationships> that indicate how
906prerequisites should be resolved.
907
908For example, to specify that C<Data::Dumper> is C<required> during the
909C<test> phase, this entry would appear in the distribution metadata:
910
911  prereqs => {
912    test => {
913      requires => {
914        'Data::Dumper' => '2.00'
915      }
916    }
917  }
918
919=head3 Phases
920
921Requirements for regular use must be listed in the C<runtime> phase.
922Other requirements should be listed in the earliest stage in which they
923are required and consumers must accumulate and satisfy requirements
924across phases before executing the activity. For example, C<build>
925requirements must also be available during the C<test> phase.
926
927  before action       requirements that must be met
928  ----------------    --------------------------------
929  perl Build.PL       configure
930  perl Makefile.PL
931
932  make                configure, runtime, build
933  Build
934
935  make test           configure, runtime, build, test
936  Build test
937
938Consumers that install the distribution must ensure that
939I<runtime> requirements are also installed and may install
940dependencies from other phases.
941
942  after action        requirements that must be met
943  ----------------    --------------------------------
944  make install        runtime
945  Build install
946
947=over
948
949=item configure
950
951The configure phase occurs before any dynamic configuration has been
952attempted.  Libraries required by the configure phase B<must> be
953available for use before the distribution building tool has been
954executed.
955
956=item build
957
958The build phase is when the distribution's source code is compiled (if
959necessary) and otherwise made ready for installation.
960
961=item test
962
963The test phase is when the distribution's automated test suite is run.
964Any library that is needed only for testing and not for subsequent use
965should be listed here.
966
967=item runtime
968
969The runtime phase refers not only to when the distribution's contents
970are installed, but also to its continued use.  Any library that is a
971prerequisite for regular use of this distribution should be indicated
972here.
973
974=item develop
975
976The develop phase's prereqs are libraries needed to work on the
977distribution's source code as its author does.  These tools might be
978needed to build a release tarball, to run author-only tests, or to
979perform other tasks related to developing new versions of the
980distribution.
981
982=back
983
984=head3 Relationships
985
986=over
987
988=item requires
989
990These dependencies B<must> be installed for proper completion of the
991phase.
992
993=item recommends
994
995Recommended dependencies are I<strongly> encouraged and should be
996satisfied except in resource constrained environments.
997
998=item suggests
999
1000These dependencies are optional, but are suggested for enhanced operation
1001of the described distribution.
1002
1003=item conflicts
1004
1005These libraries cannot be installed when the phase is in operation.
1006This is a very rare situation, and the C<conflicts> relationship should
1007be used with great caution, or not at all.
1008
1009=back
1010
1011=head2 Merging and Resolving Prerequisites
1012
1013Whenever metadata consumers merge prerequisites, either from different
1014phases or from C<optional_features>, they should merged in a way which
1015preserves the intended semantics of the prerequisite structure.  Generally,
1016this means concatenating the version specifications using commas, as
1017described in the L<Version Ranges> section.
1018
1019Another subtle error that can occur in resolving prerequisites comes from
1020the way that modules in prerequisites are indexed to distribution files on
1021CPAN.  When a module is deleted from a distribution, prerequisites calling
1022for that module could indicate an older distribution should be installed,
1023potentially overwriting files from a newer distribution.
1024
1025For example, as of Oct 31, 2009, the CPAN index file contained these
1026module-distribution mappings:
1027
1028  Class::MOP                   0.94  D/DR/DROLSKY/Class-MOP-0.94.tar.gz
1029  Class::MOP::Class            0.94  D/DR/DROLSKY/Class-MOP-0.94.tar.gz
1030  Class::MOP::Class::Immutable 0.04  S/ST/STEVAN/Class-MOP-0.36.tar.gz
1031
1032Consider the case where "Class::MOP" 0.94 is installed.  If a
1033distribution specified "Class::MOP::Class::Immutable" as a prerequisite,
1034it could result in Class-MOP-0.36.tar.gz being installed, overwriting
1035any files from Class-MOP-0.94.tar.gz.
1036
1037Consumers of metadata B<should> test whether prerequisites would result
1038in installed module files being "downgraded" to an older version and
1039B<may> warn users or ignore the prerequisite that would cause such a
1040result.
1041
1042=head1 SERIALIZATION
1043
1044Distribution metadata should be serialized (as a hashref) as
1045JSON-encoded data and packaged with distributions as the file
1046F<META.json>.
1047
1048In the past, the distribution metadata structure had been packed with
1049distributions as F<META.yml>, a file in the YAML Tiny format (for which,
1050see L<YAML::Tiny>).  Tools that consume distribution metadata from disk
1051should be capable of loading F<META.yml>, but should prefer F<META.json>
1052if both are found.
1053
1054=head1 NOTES FOR IMPLEMENTORS
1055
1056=head2 Extracting Version Numbers from Perl Modules
1057
1058To get the version number from a Perl module, consumers should use the
1059C<< MM->parse_version($file) >> method provided by
1060L<ExtUtils::MakeMaker> or L<Module::Metadata>.  For example, for the
1061module given by C<$mod>, the version may be retrieved in one of the
1062following ways:
1063
1064  # via ExtUtils::MakeMaker
1065  my $file = MM->_installed_file_for_module($mod);
1066  my $version = MM->parse_version($file)
1067
1068The private C<_installed_file_for_module> method may be replaced with
1069other methods for locating a module in C<@INC>.
1070
1071  # via Module::Metadata
1072  my $info = Module::Metadata->new_from_module($mod);
1073  my $version = $info->version;
1074
1075If only a filename is available, the following approach may be used:
1076
1077  # via Module::Build
1078  my $info = Module::Metadata->new_from_file($file);
1079  my $version = $info->version;
1080
1081=head2 Comparing Version Numbers
1082
1083The L<version> module provides the most reliable way to compare version
1084numbers in all the various ways they might be provided or might exist
1085within modules.  Given two strings containing version numbers, C<$v1> and
1086C<$v2>, they should be converted to C<version> objects before using
1087ordinary comparison operators.  For example:
1088
1089  use version;
1090  if ( version->new($v1) <=> version->new($v2) ) {
1091    print "Versions are not equal\n";
1092  }
1093
1094If the only comparison needed is whether an installed module is of a
1095sufficiently high version, a direct test may be done using the string
1096form of C<eval> and the C<use> function.  For example, for module C<$mod>
1097and version prerequisite C<$prereq>:
1098
1099  if ( eval "use $mod $prereq (); 1" ) {
1100    print "Module $mod version is OK.\n";
1101  }
1102
1103If the values of C<$mod> and C<$prereq> have not been scrubbed, however,
1104this presents security implications.
1105
1106=head1 SEE ALSO
1107
1108=over 4
1109
1110=item *
1111
1112CPAN, L<http://www.cpan.org/>
1113
1114=item *
1115
1116JSON, L<http://json.org/>
1117
1118=item *
1119
1120YAML, L<http://www.yaml.org/>
1121
1122=item *
1123
1124L<CPAN>
1125
1126=item *
1127
1128L<CPANPLUS>
1129
1130=item *
1131
1132L<ExtUtils::MakeMaker>
1133
1134=item *
1135
1136L<Module::Build>
1137
1138=item *
1139
1140L<Module::Install>
1141
1142=back
1143
1144=head1 HISTORY
1145
1146Ken Williams wrote the original CPAN Meta Spec (also known as the
1147"META.yml spec") in 2003 and maintained it through several revisions
1148with input from various members of the community.  In 2005, Randy
1149Sims redrafted it from HTML to POD for the version 1.2 release.  Ken
1150continued to maintain the spec through version 1.4.
1151
1152In late 2009, David Golden organized the version 2 proposal review
1153process.  David and Ricardo Signes drafted the final version 2 spec
1154in April 2010 based on the version 1.4 spec and patches contributed
1155during the proposal process.
1156
1157=head1 AUTHORS
1158
1159=over 4
1160
1161=item *
1162
1163David Golden <dagolden@cpan.org>
1164
1165=item *
1166
1167Ricardo Signes <rjbs@cpan.org>
1168
1169=back
1170
1171=head1 COPYRIGHT AND LICENSE
1172
1173This software is copyright (c) 2010 by David Golden and Ricardo Signes.
1174
1175This is free software; you can redistribute it and/or modify it under
1176the same terms as the Perl 5 programming language system itself.
1177
1178=cut
1179