You are viewing the version of this documentation from Perl 5.41.5. This is a development version of Perl.

CONTENTS

NAME

CPAN::Meta::Requirements::Range - a set of version requirements for a CPAN dist

VERSION

version 2.143

SYNOPSIS

use CPAN::Meta::Requirements::Range;

my $range = CPAN::Meta::Requirements::Range->with_minimum(1);

$range = $range->with_maximum('v2.2');

my $stringified = $range->as_string;

DESCRIPTION

A CPAN::Meta::Requirements::Range object models a set of version constraints like those specified in the META.yml or META.json files in CPAN distributions, and as defined by CPAN::Meta::Spec; It can be built up by adding more and more constraints, and it will reduce them to the simplest representation.

Logically impossible constraints will be identified immediately by thrown exceptions.

METHODS

with_string_requirement

$req->with_string_requirement('>= 1.208, <= 2.206');
$req->with_string_requirement(v1.208);

This method parses the passed in string and adds the appropriate requirement. A version can be a Perl "v-string". It understands version ranges as described in the "Version Ranges" in CPAN::Meta::Spec. For example:

1.3
>= 1.3
<= 1.3
== 1.3
!= 1.3
> 1.3
< 1.3
>= 1.3, != 1.5, <= 2.0

A version number without an operator is equivalent to specifying a minimum (>=). Extra whitespace is allowed.

with_range

$range->with_range($other_range)

This creates a new range object that is a merge two others.

with_exact_version

$range->with_exact_version( $version );

This sets the version required to exactly the given version. No other version would be considered acceptable.

This method returns the version range object.

with_minimum

$range->with_minimum( $version );

This adds a new minimum version requirement. If the new requirement is redundant to the existing specification, this has no effect.

Minimum requirements are inclusive. $version is required, along with any greater version number.

This method returns the version range object.

with_maximum

$range->with_maximum( $version );

This adds a new maximum version requirement. If the new requirement is redundant to the existing specification, this has no effect.

Maximum requirements are inclusive. No version strictly greater than the given version is allowed.

This method returns the version range object.

with_exclusion

$range->with_exclusion( $version );

This adds a new excluded version. For example, you might use these three method calls:

$range->with_minimum( '1.00' );
$range->with_maximum( '1.82' );

$range->with_exclusion( '1.75' );

Any version between 1.00 and 1.82 inclusive would be acceptable, except for 1.75.

This method returns the requirements object.

as_struct

$range->as_struct( $module );

This returns a data structure containing the version requirements. This should not be used for version checks (see "accepts_module" instead).

as_string

$range->as_string;

This returns a string containing the version requirements in the format described in CPAN::Meta::Spec. This should only be used for informational purposes such as error messages and should not be interpreted or used for comparison (see "accepts" instead).

accepts

my $bool = $range->accepts($version);

Given a version, this method returns true if the version specification accepts the provided version. In other words, given:

'>= 1.00, < 2.00'

We will accept 1.00 and 1.75 but not 0.50 or 2.00.

is_simple

This method returns true if and only if the range is an inclusive minimum -- that is, if their string expression is just the version number.

AUTHORS

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by David Golden and 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.