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.143
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   version_range_for_module
97         $req->version_range_for_module( $another_req_object );
98
99   add_requirements
100         $req->add_requirements( $another_req_object );
101
102       This method adds all the requirements in the given
103       CPAN::Meta::Requirements object to the requirements object on which it
104       was called.  If there are any conflicts, an exception is thrown.
105
106       This method returns the requirements object.
107
108   accepts_module
109         my $bool = $req->accepts_module($module => $version);
110
111       Given an module and version, this method returns true if the version
112       specification for the module accepts the provided version.  In other
113       words, given:
114
115         Module => '>= 1.00, < 2.00'
116
117       We will accept 1.00 and 1.75 but not 0.50 or 2.00.
118
119       For modules that do not appear in the requirements, this method will
120       return true.
121
122   clear_requirement
123         $req->clear_requirement( $module );
124
125       This removes the requirement for a given module from the object.
126
127       This method returns the requirements object.
128
129   requirements_for_module
130         $req->requirements_for_module( $module );
131
132       This returns a string containing the version requirements for a given
133       module in the format described in CPAN::Meta::Spec or undef if the
134       given module has no requirements. This should only be used for
135       informational purposes such as error messages and should not be
136       interpreted or used for comparison (see "accepts_module" instead).
137
138   structured_requirements_for_module
139         $req->structured_requirements_for_module( $module );
140
141       This returns a data structure containing the version requirements for a
142       given module or undef if the given module has no requirements.  This
143       should not be used for version checks (see "accepts_module" instead).
144
145       Added in version 2.134.
146
147   required_modules
148       This method returns a list of all the modules for which requirements
149       have been specified.
150
151   clone
152         $req->clone;
153
154       This method returns a clone of the invocant.  The clone and the
155       original object can then be changed independent of one another.
156
157   is_simple
158       This method returns true if and only if all requirements are inclusive
159       minimums -- that is, if their string expression is just the version
160       number.
161
162   is_finalized
163       This method returns true if the requirements have been finalized by
164       having the "finalize" method called on them.
165
166   finalize
167       This method marks the requirements finalized.  Subsequent attempts to
168       change the requirements will be fatal, if they would result in a
169       change.  If they would not alter the requirements, they have no effect.
170
171       If a finalized set of requirements is cloned, the cloned requirements
172       are not also finalized.
173
174   as_string_hash
175       This returns a reference to a hash describing the requirements using
176       the strings in the CPAN::Meta::Spec specification.
177
178       For example after the following program:
179
180         my $req = CPAN::Meta::Requirements->new;
181
182         $req->add_minimum('CPAN::Meta::Requirements' => 0.102);
183
184         $req->add_minimum('Library::Foo' => 1.208);
185
186         $req->add_maximum('Library::Foo' => 2.602);
187
188         $req->add_minimum('Module::Bar'  => 'v1.2.3');
189
190         $req->add_exclusion('Module::Bar'  => 'v1.2.8');
191
192         $req->exact_version('Xyzzy'  => '6.01');
193
194         my $hashref = $req->as_string_hash;
195
196       $hashref would contain:
197
198         {
199           'CPAN::Meta::Requirements' => '0.102',
200           'Library::Foo' => '>= 1.208, <= 2.206',
201           'Module::Bar'  => '>= v1.2.3, != v1.2.8',
202           'Xyzzy'        => '== 6.01',
203         }
204
205   add_string_requirement
206         $req->add_string_requirement('Library::Foo' => '>= 1.208, <= 2.206');
207         $req->add_string_requirement('Library::Foo' => v1.208);
208
209       This method parses the passed in string and adds the appropriate
210       requirement for the given module.  A version can be a Perl "v-string".
211       It understands version ranges as described in the "Version Ranges" in
212       CPAN::Meta::Spec. For example:
213
214       1.3
215       >= 1.3
216       <= 1.3
217       == 1.3
218       != 1.3
219       > 1.3
220       < 1.3
221       >= 1.3, != 1.5, <= 2.0
222           A version number without an operator is equivalent to specifying a
223           minimum (">=").  Extra whitespace is allowed.
224
225   from_string_hash
226         my $req = CPAN::Meta::Requirements->from_string_hash( \%hash );
227         my $req = CPAN::Meta::Requirements->from_string_hash( \%hash, \%opts );
228
229       This is an alternate constructor for a CPAN::Meta::Requirements object.
230       It takes a hash of module names and version requirement strings and
231       returns a new CPAN::Meta::Requirements object. As with
232       add_string_requirement, a version can be a Perl "v-string". Optionally,
233       you can supply a hash-reference of options, exactly as with the "new"
234       method.
235

SUPPORT

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

AUTHORS

251       •   David Golden <dagolden@cpan.org>
252
253       •   Ricardo Signes <rjbs@cpan.org>
254

CONTRIBUTORS

256       •   Ed J <mohawk2@users.noreply.github.com>
257
258       •   Graham Knop <haarg@haarg.org>
259
260       •   Karen Etheridge <ether@cpan.org>
261
262       •   Leon Timmermans <fawaka@gmail.com>
263
264       •   Paul Howarth <paul@city-fan.org>
265
266       •   Ricardo Signes <rjbs@semiotic.systems>
267
268       •   robario <webmaster@robario.com>
269
270       •   Tatsuhiko Miyagawa <miyagawa@bulknews.net>
271
272       •   Tatsuhiko Miyagawa <miyagawa@gmail.com>
273
275       This software is copyright (c) 2010 by David Golden and Ricardo Signes.
276
277       This is free software; you can redistribute it and/or modify it under
278       the same terms as the Perl 5 programming language system itself.
279
280
281
282perl v5.38.0                      2023-07-20       CPAN::Meta::Requirements(3)
Impressum