1CPAN::Meta::RequirementUss(e3r)Contributed Perl DocumentCaPtAiNo:n:Meta::Requirements(3)
2
3
4

NAME

6       CPAN::Meta::Requirements - a set of version requirements for a CPAN
7       dist
8

VERSION

10       version 2.122
11

SYNOPSIS

13         use CPAN::Meta::Requirements;
14
15         my $build_requires = CPAN::Meta::Requirements->new;
16
17         $build_requires->add_minimum('Library::Foo' => 1.208);
18
19         $build_requires->add_minimum('Library::Foo' => 2.602);
20
21         $build_requires->add_minimum('Module::Bar'  => 'v1.2.3');
22
23         $METAyml->{build_requires} = $build_requires->as_string_hash;
24

DESCRIPTION

26       A CPAN::Meta::Requirements object models a set of version constraints
27       like those specified in the META.yml or META.json files in CPAN
28       distributions.  It can be built up by adding more and more constraints,
29       and it will reduce them to the simplest representation.
30
31       Logically impossible constraints will be identified immediately by
32       thrown exceptions.
33

METHODS

35   new
36         my $req = CPAN::Meta::Requirements->new;
37
38       This returns a new CPAN::Meta::Requirements object.  It takes an
39       optional hash reference argument.  The following keys are supported:
40
41       ·   <bad_version_hook> -- if provided, when a version cannot be parsed
42           into
43
44           a version object, this code reference will be called with the
45           invalid version string as an argument.  It must return a valid
46           version object.
47
48       All other keys are ignored.
49
50   add_minimum
51         $req->add_minimum( $module => $version );
52
53       This adds a new minimum version requirement.  If the new requirement is
54       redundant to the existing specification, this has no effect.
55
56       Minimum requirements are inclusive.  $version is required, along with
57       any greater version number.
58
59       This method returns the requirements object.
60
61   add_maximum
62         $req->add_maximum( $module => $version );
63
64       This adds a new maximum version requirement.  If the new requirement is
65       redundant to the existing specification, this has no effect.
66
67       Maximum requirements are inclusive.  No version strictly greater than
68       the given version is allowed.
69
70       This method returns the requirements object.
71
72   add_exclusion
73         $req->add_exclusion( $module => $version );
74
75       This adds a new excluded version.  For example, you might use these
76       three method calls:
77
78         $req->add_minimum( $module => '1.00' );
79         $req->add_maximum( $module => '1.82' );
80
81         $req->add_exclusion( $module => '1.75' );
82
83       Any version between 1.00 and 1.82 inclusive would be acceptable, except
84       for 1.75.
85
86       This method returns the requirements object.
87
88   exact_version
89         $req->exact_version( $module => $version );
90
91       This sets the version required for the given module to exactly the
92       given version.  No other version would be considered acceptable.
93
94       This method returns the requirements object.
95
96   add_requirements
97         $req->add_requirements( $another_req_object );
98
99       This method adds all the requirements in the given
100       CPAN::Meta::Requirements object to the requirements object on which it
101       was called.  If there are any conflicts, an exception is thrown.
102
103       This method returns the requirements object.
104
105   accepts_module
106         my $bool = $req->accepts_modules($module => $version);
107
108       Given an module and version, this method returns true if the version
109       specification for the module accepts the provided version.  In other
110       words, given:
111
112         Module => '>= 1.00, < 2.00'
113
114       We will accept 1.00 and 1.75 but not 0.50 or 2.00.
115
116       For modules that do not appear in the requirements, this method will
117       return true.
118
119   clear_requirement
120         $req->clear_requirement( $module );
121
122       This removes the requirement for a given module from the object.
123
124       This method returns the requirements object.
125
126   requirements_for_module
127         $req->requirements_for_module( $module );
128
129       This returns a string containing the version requirements for a given
130       module in the format described in CPAN::Meta::Spec or undef if the
131       given module has no requirements. This should only be used for
132       informational purposes such as error messages and should not be
133       interpreted or used for comparison (see "accepts_module" instead.)
134
135   required_modules
136       This method returns a list of all the modules for which requirements
137       have been specified.
138
139   clone
140         $req->clone;
141
142       This method returns a clone of the invocant.  The clone and the
143       original object can then be changed independent of one another.
144
145   is_simple
146       This method returns true if and only if all requirements are inclusive
147       minimums -- that is, if their string expression is just the version
148       number.
149
150   is_finalized
151       This method returns true if the requirements have been finalized by
152       having the "finalize" method called on them.
153
154   finalize
155       This method marks the requirements finalized.  Subsequent attempts to
156       change the requirements will be fatal, if they would result in a
157       change.  If they would not alter the requirements, they have no effect.
158
159       If a finalized set of requirements is cloned, the cloned requirements
160       are not also finalized.
161
162   as_string_hash
163       This returns a reference to a hash describing the requirements using
164       the strings in the META.yml specification.
165
166       For example after the following program:
167
168         my $req = CPAN::Meta::Requirements->new;
169
170         $req->add_minimum('CPAN::Meta::Requirements' => 0.102);
171
172         $req->add_minimum('Library::Foo' => 1.208);
173
174         $req->add_maximum('Library::Foo' => 2.602);
175
176         $req->add_minimum('Module::Bar'  => 'v1.2.3');
177
178         $req->add_exclusion('Module::Bar'  => 'v1.2.8');
179
180         $req->exact_version('Xyzzy'  => '6.01');
181
182         my $hashref = $req->as_string_hash;
183
184       $hashref would contain:
185
186         {
187           'CPAN::Meta::Requirements' => '0.102',
188           'Library::Foo' => '>= 1.208, <= 2.206',
189           'Module::Bar'  => '>= v1.2.3, != v1.2.8',
190           'Xyzzy'        => '== 6.01',
191         }
192
193   add_string_requirement
194         $req->add_string_requirement('Library::Foo' => '>= 1.208, <= 2.206');
195
196       This method parses the passed in string and adds the appropriate
197       requirement for the given module.  It understands version ranges as
198       described in the "Version Ranges" in CPAN::Meta::Spec. For example:
199
200       1.3
201       >= 1.3
202       <= 1.3
203       == 1.3
204       != 1.3
205       > 1.3
206       < 1.3
207       >= 1.3, != 1.5, <= 2.0
208           A version number without an operator is equivalent to specifying a
209           minimum (">=").  Extra whitespace is allowed.
210
211   from_string_hash
212         my $req = CPAN::Meta::Requirements->from_string_hash( \%hash );
213
214       This is an alternate constructor for a CPAN::Meta::Requirements object.
215       It takes a hash of module names and version requirement strings and
216       returns a new CPAN::Meta::Requirements object.
217

SUPPORT

219   Bugs / Feature Requests
220       Please report any bugs or feature requests through the issue tracker at
221       <http://rt.cpan.org/Public/Dist/Display.html?Name=CPAN-Meta-Requirements>.
222       You will be notified automatically of any progress on your issue.
223
224   Source Code
225       This is open source software.  The code repository is available for
226       public review and contribution under the terms of the license.
227
228       <https://github.com/dagolden/cpan-meta-requirements>
229
230         git clone https://github.com/dagolden/cpan-meta-requirements.git
231

AUTHORS

233       ·   David Golden <dagolden@cpan.org>
234
235       ·   Ricardo Signes <rjbs@cpan.org>
236
238       This software is copyright (c) 2010 by David Golden and Ricardo Signes.
239
240       This is free software; you can redistribute it and/or modify it under
241       the same terms as the Perl 5 programming language system itself.
242
243
244
245perl v5.16.3                      2012-05-02       CPAN::Meta::Requirements(3)
Impressum