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.140
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, and as defined by CPAN::Meta::Spec; It can be built up
29       by adding more and more constraints, and it will reduce them to the
30       simplest representation.
31
32       Logically impossible constraints will be identified immediately by
33       thrown exceptions.
34

METHODS

36   new
37         my $req = CPAN::Meta::Requirements->new;
38
39       This returns a new CPAN::Meta::Requirements object.  It takes an
40       optional hash reference argument.  Currently, only one key is
41       supported:
42
43       ·   "bad_version_hook" -- if provided, when a version cannot be parsed
44           into a version object, this code reference will be called with the
45           invalid version string as first argument, and the module name as
46           second argument.  It must return a valid 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_module($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   structured_requirements_for_module
136         $req->structured_requirements_for_module( $module );
137
138       This returns a data structure containing the version requirements for a
139       given module or undef if the given module has no requirements.  This
140       should not be used for version checks (see "accepts_module" instead).
141
142       Added in version 2.134.
143
144   required_modules
145       This method returns a list of all the modules for which requirements
146       have been specified.
147
148   clone
149         $req->clone;
150
151       This method returns a clone of the invocant.  The clone and the
152       original object can then be changed independent of one another.
153
154   is_simple
155       This method returns true if and only if all requirements are inclusive
156       minimums -- that is, if their string expression is just the version
157       number.
158
159   is_finalized
160       This method returns true if the requirements have been finalized by
161       having the "finalize" method called on them.
162
163   finalize
164       This method marks the requirements finalized.  Subsequent attempts to
165       change the requirements will be fatal, if they would result in a
166       change.  If they would not alter the requirements, they have no effect.
167
168       If a finalized set of requirements is cloned, the cloned requirements
169       are not also finalized.
170
171   as_string_hash
172       This returns a reference to a hash describing the requirements using
173       the strings in the CPAN::Meta::Spec specification.
174
175       For example after the following program:
176
177         my $req = CPAN::Meta::Requirements->new;
178
179         $req->add_minimum('CPAN::Meta::Requirements' => 0.102);
180
181         $req->add_minimum('Library::Foo' => 1.208);
182
183         $req->add_maximum('Library::Foo' => 2.602);
184
185         $req->add_minimum('Module::Bar'  => 'v1.2.3');
186
187         $req->add_exclusion('Module::Bar'  => 'v1.2.8');
188
189         $req->exact_version('Xyzzy'  => '6.01');
190
191         my $hashref = $req->as_string_hash;
192
193       $hashref would contain:
194
195         {
196           'CPAN::Meta::Requirements' => '0.102',
197           'Library::Foo' => '>= 1.208, <= 2.206',
198           'Module::Bar'  => '>= v1.2.3, != v1.2.8',
199           'Xyzzy'        => '== 6.01',
200         }
201
202   add_string_requirement
203         $req->add_string_requirement('Library::Foo' => '>= 1.208, <= 2.206');
204         $req->add_string_requirement('Library::Foo' => v1.208);
205
206       This method parses the passed in string and adds the appropriate
207       requirement for the given module.  A version can be a Perl "v-string".
208       It understands version ranges as described in the "Version Ranges" in
209       CPAN::Meta::Spec. For example:
210
211       1.3
212       >= 1.3
213       <= 1.3
214       == 1.3
215       != 1.3
216       > 1.3
217       < 1.3
218       >= 1.3, != 1.5, <= 2.0
219           A version number without an operator is equivalent to specifying a
220           minimum (">=").  Extra whitespace is allowed.
221
222   from_string_hash
223         my $req = CPAN::Meta::Requirements->from_string_hash( \%hash );
224         my $req = CPAN::Meta::Requirements->from_string_hash( \%hash, \%opts );
225
226       This is an alternate constructor for a CPAN::Meta::Requirements object.
227       It takes a hash of module names and version requirement strings and
228       returns a new CPAN::Meta::Requirements object. As with
229       add_string_requirement, a version can be a Perl "v-string". Optionally,
230       you can supply a hash-reference of options, exactly as with the "new"
231       method.
232

SUPPORT

234   Bugs / Feature Requests
235       Please report any bugs or feature requests through the issue tracker at
236       <https://github.com/Perl-Toolchain-Gang/CPAN-Meta-Requirements/issues>.
237       You will be notified automatically of any progress on your issue.
238
239   Source Code
240       This is open source software.  The code repository is available for
241       public review and contribution under the terms of the license.
242
243       <https://github.com/Perl-Toolchain-Gang/CPAN-Meta-Requirements>
244
245         git clone https://github.com/Perl-Toolchain-Gang/CPAN-Meta-Requirements.git
246

AUTHORS

248       ·   David Golden <dagolden@cpan.org>
249
250       ·   Ricardo Signes <rjbs@cpan.org>
251

CONTRIBUTORS

253       ·   Ed J <mohawk2@users.noreply.github.com>
254
255       ·   Karen Etheridge <ether@cpan.org>
256
257       ·   Leon Timmermans <fawaka@gmail.com>
258
259       ·   robario <webmaster@robario.com>
260
262       This software is copyright (c) 2010 by David Golden and Ricardo Signes.
263
264       This is free software; you can redistribute it and/or modify it under
265       the same terms as the Perl 5 programming language system itself.
266
267
268
269perl v5.30.0                      2019-07-26       CPAN::Meta::Requirements(3)
Impressum