# perldoc > CPAN::Meta::Requirements

---
type: CommandReference
command: CPAN::Meta::Requirements
mode: perldoc
section: ""
source: perldoc
---

## Quick Reference
- `my $req = CPAN::Meta::Requirements->new;` — Create a new requirements object
- `$req->add_minimum('Module' => '1.0');` — Add a minimum version requirement
- `$req->as_string_hash;` — Export requirements as a hash for META files
- `CPAN::Meta::Requirements->from_string_hash(\%hash);` — Build an object from a requirements hash
- `$req->accepts_module('Module' => '1.2');` — Check if a version satisfies the constraints
- `$req->finalize;` — Lock the requirements set; any change that would alter it becomes fatal
- `$req->clone;` — Create an independent copy of the object
- `$req->required_modules;` — List all modules that have requirements

## Name
[CPAN::Meta::Requirements](https://metacpan.org/pod/CPAN::Meta::Requirements) - a set of version requirements for a CPAN dist

## Synopsis
perl
use CPAN::Meta::Requirements;

my $build_requires = CPAN::Meta::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;
## Methods
- `new( \%opts )` — Returns a new CPAN::Meta::Requirements object. Accepts optional hash with `bad_version_hook` (code ref called for unparseable versions; must return a valid version object).
- `add_minimum( $module, $version )` — Adds an inclusive minimum version requirement. Redundant additions are ignored. Returns the object.
- `add_maximum( $module, $version )` — Adds an inclusive maximum version requirement. Returns the object.
- `add_exclusion( $module, $version )` — Excludes a specific version. Returns the object.
- `exact_version( $module, $version )` — Requires exactly the given version. Returns the object.
- `add_requirements( $another_req )` — Merges all requirements from another CPAN::Meta::Requirements object. Throws an exception on conflicts. Returns the object.
- `accepts_module( $module, $version )` — Returns true if the provided version satisfies the current constraints. Returns true for modules without requirements.
- `clear_requirement( $module )` — Removes all requirements for the specified module. Returns the object.
- `requirements_for_module( $module )` — Returns a string describing the version requirements (for informational messages). Returns undef if none.
- `structured_requirements_for_module( $module )` — Returns a data structure of version requirements (since v2.134). Do not use for version checks.
- `required_modules` — Returns a list of all modules with requirements.
- `clone` — Returns a deep clone of the object.
- `is_simple` — Returns true if all requirements are inclusive minimums (i.e., the string form is just a version number).
- `is_finalized` — Returns true if the object has been finalized.
- `finalize` — Locks the requirements set. Subsequent attempts to change requirements will die unless the change is a no-op. Cloning a finalized object does not finalize the clone.
- `as_string_hash` — Returns a hashref mapping module names to their requirement strings as defined in [CPAN::Meta::Spec](https://metacpan.org/pod/CPAN::Meta::Spec).
- `add_string_requirement( $module, $string )` — Parses a version range string (e.g., `>= 1.208, <= 2.206`, `v1.2.3`, `!= 1.5`) and adds the appropriate constraints. Supports the full CPAN::Meta::Spec range syntax.
- `from_string_hash( \%hash, \%opts )` — Class method; creates a new object from a hash of module names to requirement strings. Accepts the same options as `new`.

## Examples
perl
my $req = CPAN::Meta::Requirements->new;

$req->add_minimum('CPAN::Meta::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;
# {
#   'CPAN::Meta::Requirements' => '0.102',
#   'Library::Foo'             => '>= 1.208, <= 2.206',
#   'Module::Bar'              => '>= v1.2.3, != v1.2.8',
#   'Xyzzy'                    => '== 6.01',
# }

# Check a version
if ($req->accepts_module('Library::Foo' => '2.0')) {
    print "OK\n";
}
## See Also
- [CPAN::Meta::Spec](https://metacpan.org/pod/CPAN::Meta::Spec) — CPAN distribution metadata specification
- [version](https://metacpan.org/pod/version) — Perl extension for version objects