Version...irements(3)
π NAME π
Version::Requirements β a whole lil set of version requirements for a CPAN dist πβ¨
(and yes, the manual page itself is filed under Version...irements(3), the title is literally truncated like that, that's not me being lazy, that's just how the page is named π
)
π VERSION π
version 0.101023 β iconic, no notes π
π SYNOPSIS π
okay bestie, look at this:
use Version::Requirements;
my $build_requires = Version::Requirements->new;
$build_requires->add_minimum('Library::Foo' => 1.208);
$build_requires->add_minimum('Library::Foo' => 2.602);
$build_requires->add_minimum('Module::Bar' => 'v1.2.3');
$METAyml->{build_requires} = $build_requires->as_string_hash;
that's it. that's the whole vibe. π¦
π«Ά DESCRIPTION π«Ά
so a Version::Requirements object is literally just a model of a set of version constraints β the exact same kind of thing you'd see spelled out in the META.yml or META.json files inside CPAN distributions. it's giving "requirements list, but make it an object". π
the way that it works is you keep piling on more and more constraints, and it does the work of reducing them all down to the simplest possible representation. so clean, so tidy, main character energy β¨
and if you hand it constraints that are logically impossible? it doesn't sit there and pretend. it identifies them immediately by throwing exceptions. it's honest. it's blunt. we love her for it. π
π§ METHODS π§
β¨ new β¨
my $req = Version::Requirements->new;
returns you a brand new Version::Requirements object. and here's the tea: it ignores any arguments given. you can pass it stuff if you want, it simply will not care. π
β¨ add_minimum β¨
$req->add_minimum( $module => $version );
adds a new minimum version requirement. if this new requirement is redundant next to whatever you already specified, it just has no effect β no drama, no change. π
minimum requirements are inclusive, so $version is required, along with any greater version number. yes, equal counts. yes, higher counts.
this method returns the requirements object (so you can chain, iykyk π).
β¨ add_maximum β¨
$req->add_maximum( $module => $version );
adds a new maximum version requirement. redundant requirement? no effect. moving on. π
maximum requirements are inclusive too, so no version strictly greater than the given version is allowed. strictly. the one you named is fine, anything above it is not.
this method returns the requirements object. π«Ά
β¨ add_exclusion β¨
$req->add_exclusion( $module => $version );
this one adds a new excluded version. like, everything's chill except THIS one. for example, you might do these three method calls:
$req->add_minimum( $module => '1.00' );
$req->add_maximum( $module => '1.82' );
$req->add_exclusion( $module => '1.75' );
so any version between 1.00 and 1.82 inclusive would be acceptable β except for 1.75. she's banned. blocked. not invited. π
this method returns the requirements object. β¨
β¨ exact_version β¨
$req->exact_version( $module => $version );
sets the version required for the given module to exactly the given version. no other version would be considered acceptable. it's giving "this one or nothing". π
this method returns the requirements object. πΈ
β¨ add_requirements β¨
$req->add_requirements( $another_req_object );
takes all the requirements in the Version::Requirements object you pass in and adds them to the object you called it on. and if there are any conflicts? an exception gets thrown. no cap, it will not let that slide. π€
this method returns the requirements object. π
β¨ accepts_module β¨
my $bool = $req->accepts_modules($module => $version);
give it a module and a version, and it returns true if the version specification for that module accepts the version you provided. in other words, given:
Module => '>= 1.00, < 2.00'
we will accept 1.00 and 1.75 but not 0.50 or 2.00. 1.00 and 1.75, you're in. 0.50 and 2.00, respectfully, no. π
and for modules that do not appear in the requirements at all? this method will return true. generous queen behavior honestly. π«Ά
β¨ clear_requirement β¨
$req->clear_requirement( $module );
removes the requirement for a given module from the object. gone. deleted. we don't know her. π
this method returns the requirements object. β¨
β¨ required_modules β¨
returns a list of all the modules for which requirements have been specified. the whole guest list. π
β¨ clone β¨
$req->clone;
returns a clone of the invocant. and the best part: the clone and the original object can then be changed independent of one another. they're twins but they live their own lives. π
β¨ is_simple β¨
returns true if and only if all requirements are inclusive minimums β that is, if their string expression is just the version number. simple. clean. unbothered. πΈ
β¨ is_finalized β¨
returns true if the requirements have been finalized by having the finalize method called on them. β¨
β¨ finalize β¨
marks the requirements finalized. and bestie, listen: subsequent attempts to change the requirements will be fatal β if they would result in a change. if they would not alter the requirements, they have no effect. so like, a no-op change is fine, but a real change is over. π¨
also, if a finalized set of requirements is cloned, the cloned requirements are not also finalized. the clone is free. the clone is unbothered. the clone is in her own era. π¦
β¨ as_string_hash β¨
returns a reference to a hash describing the requirements using the strings in the META.yml specification. π
for example, after the following program:
my $req = Version::Requirements->new;
$req->add_minimum('Version::Requirements' => 0.102);
$req->add_minimum('Library::Foo' => 1.208);
$req->add_maximum('Library::Foo' => 2.602);
$req->add_minimum('Module::Bar' => 'v1.2.3');
$req->add_exclusion('Module::Bar' => 'v1.2.8');
$req->exact_version('Xyzzy' => '6.01');
my $hashref = $req->as_string_hash;
$hashref would contain:
{
'Version::Requirements' => '0.102',
'Library::Foo' => '>= 1.208, <= 2.206',
'Module::Bar' => '>= v1.2.3, != v1.2.8',
'Xyzzy' => '== 6.01',
}
(yes, copy it character for character, that's exactly how it's written in the docs π )
β¨ from_string_hash β¨
my $req = Version::Requirements->from_string_hash( \%hash );
this is an alternate constructor for a Version::Requirements object. it takes a hash of module names and version requirement strings, and returns a brand new Version::Requirements object. built different, built from a hash. π
π AUTHOR π
Ricardo Signes <rjbs@cpan.org> β the icon, the legend, the moment. π
πΈ CONTRIBUTOR πΈ
Karen Etheridge <ether@cpan.org> β also iconic, also slaying. π«Ά
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2010 by Ricardo Signes. β
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. periodt. π
and that's the whole page, bestie β filed under Version...irements(3), running under perl v5.42.0, dated 2025-07-25. go forth and constrain those versions responsibly. slay. π
β¨π
π¦ where this page comes from
- fedora 43: perl-Version-Requirements 0.101023-31.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms