| 1 | 7 | ▶ | use v5.10; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | package CPAN::Meta::Requirements; | ||||||||||||||||||||||||||||
| 5 | # ABSTRACT: a set of version requirements for a CPAN dist | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 7 | our $VERSION = '2.145'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use CPAN::Meta::Requirements::Range; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | #pod =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 12 | #pod | ||||||||||||||||||||||||||||
| 13 | #pod use CPAN::Meta::Requirements; | ||||||||||||||||||||||||||||
| 14 | #pod | ||||||||||||||||||||||||||||
| 15 | #pod my $build_requires = CPAN::Meta::Requirements->new; | ||||||||||||||||||||||||||||
| 16 | #pod | ||||||||||||||||||||||||||||
| 17 | #pod $build_requires->add_minimum('Library::Foo' => 1.208); | ||||||||||||||||||||||||||||
| 18 | #pod | ||||||||||||||||||||||||||||
| 19 | #pod $build_requires->add_minimum('Library::Foo' => 2.602); | ||||||||||||||||||||||||||||
| 20 | #pod | ||||||||||||||||||||||||||||
| 21 | #pod $build_requires->add_minimum('Module::Bar' => 'v1.2.3'); | ||||||||||||||||||||||||||||
| 22 | #pod | ||||||||||||||||||||||||||||
| 23 | #pod $METAyml->{build_requires} = $build_requires->as_string_hash; | ||||||||||||||||||||||||||||
| 24 | #pod | ||||||||||||||||||||||||||||
| 25 | #pod =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 26 | #pod | ||||||||||||||||||||||||||||
| 27 | #pod A CPAN::Meta::Requirements object models a set of version constraints like | ||||||||||||||||||||||||||||
| 28 | #pod those specified in the F<META.yml> or F<META.json> files in CPAN distributions, | ||||||||||||||||||||||||||||
| 29 | #pod and as defined by L<CPAN::Meta::Spec>. | ||||||||||||||||||||||||||||
| 30 | #pod It can be built up by adding more and more constraints, and it will reduce them | ||||||||||||||||||||||||||||
| 31 | #pod to the simplest representation. | ||||||||||||||||||||||||||||
| 32 | #pod | ||||||||||||||||||||||||||||
| 33 | #pod Logically impossible constraints will be identified immediately by thrown | ||||||||||||||||||||||||||||
| 34 | #pod exceptions. | ||||||||||||||||||||||||||||
| 35 | #pod | ||||||||||||||||||||||||||||
| 36 | #pod =cut | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 7 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | #pod =method new | ||||||||||||||||||||||||||||
| 41 | #pod | ||||||||||||||||||||||||||||
| 42 | #pod my $req = CPAN::Meta::Requirements->new; | ||||||||||||||||||||||||||||
| 43 | #pod | ||||||||||||||||||||||||||||
| 44 | #pod This returns a new CPAN::Meta::Requirements object. It takes an optional | ||||||||||||||||||||||||||||
| 45 | #pod hash reference argument. Currently, only one key is supported: | ||||||||||||||||||||||||||||
| 46 | #pod | ||||||||||||||||||||||||||||
| 47 | #pod =for :list | ||||||||||||||||||||||||||||
| 48 | #pod * C<bad_version_hook> -- if provided, when a version cannot be parsed into | ||||||||||||||||||||||||||||
| 49 | #pod a version object, this code reference will be called with the invalid | ||||||||||||||||||||||||||||
| 50 | #pod version string as first argument, and the module name as second | ||||||||||||||||||||||||||||
| 51 | #pod argument. It must return a valid version object. | ||||||||||||||||||||||||||||
| 52 | #pod | ||||||||||||||||||||||||||||
| 53 | #pod All other keys are ignored. | ||||||||||||||||||||||||||||
| 54 | #pod | ||||||||||||||||||||||||||||
| 55 | #pod =cut | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 7 | my @valid_options = qw( bad_version_hook ); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 42 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 42 | my ($class, $options) = @_; | |||||||||||||||||||||||||||
| 61 | 42 | ▶ | $options ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$options ||= {}
MC/DC0%0/1
$options ||= {}
$options
Truth table50%1/2
A
A= $options
| |||||||||||||||||||||||||||||
| 62 | 42 | ▶ | Carp::croak "Argument to $class\->new() must be a hash reference" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | unless ref $options eq 'HASH'; | ||||||||||||||||||||||||||||
| 64 | 42 | my %self = map {; $_ => $options->{$_}} @valid_options; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 42 | return bless \%self => $class; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | #pod =method add_minimum | ||||||||||||||||||||||||||||
| 70 | #pod | ||||||||||||||||||||||||||||
| 71 | #pod $req->add_minimum( $module => $version ); | ||||||||||||||||||||||||||||
| 72 | #pod | ||||||||||||||||||||||||||||
| 73 | #pod This adds a new minimum version requirement. If the new requirement is | ||||||||||||||||||||||||||||
| 74 | #pod redundant to the existing specification, this has no effect. | ||||||||||||||||||||||||||||
| 75 | #pod | ||||||||||||||||||||||||||||
| 76 | #pod Minimum requirements are inclusive. C<$version> is required, along with any | ||||||||||||||||||||||||||||
| 77 | #pod greater version number. | ||||||||||||||||||||||||||||
| 78 | #pod | ||||||||||||||||||||||||||||
| 79 | #pod This method returns the requirements object. | ||||||||||||||||||||||||||||
| 80 | #pod | ||||||||||||||||||||||||||||
| 81 | #pod =method add_maximum | ||||||||||||||||||||||||||||
| 82 | #pod | ||||||||||||||||||||||||||||
| 83 | #pod $req->add_maximum( $module => $version ); | ||||||||||||||||||||||||||||
| 84 | #pod | ||||||||||||||||||||||||||||
| 85 | #pod This adds a new maximum version requirement. If the new requirement is | ||||||||||||||||||||||||||||
| 86 | #pod redundant to the existing specification, this has no effect. | ||||||||||||||||||||||||||||
| 87 | #pod | ||||||||||||||||||||||||||||
| 88 | #pod Maximum requirements are inclusive. No version strictly greater than the given | ||||||||||||||||||||||||||||
| 89 | #pod version is allowed. | ||||||||||||||||||||||||||||
| 90 | #pod | ||||||||||||||||||||||||||||
| 91 | #pod This method returns the requirements object. | ||||||||||||||||||||||||||||
| 92 | #pod | ||||||||||||||||||||||||||||
| 93 | #pod =method add_exclusion | ||||||||||||||||||||||||||||
| 94 | #pod | ||||||||||||||||||||||||||||
| 95 | #pod $req->add_exclusion( $module => $version ); | ||||||||||||||||||||||||||||
| 96 | #pod | ||||||||||||||||||||||||||||
| 97 | #pod This adds a new excluded version. For example, you might use these three | ||||||||||||||||||||||||||||
| 98 | #pod method calls: | ||||||||||||||||||||||||||||
| 99 | #pod | ||||||||||||||||||||||||||||
| 100 | #pod $req->add_minimum( $module => '1.00' ); | ||||||||||||||||||||||||||||
| 101 | #pod $req->add_maximum( $module => '1.82' ); | ||||||||||||||||||||||||||||
| 102 | #pod | ||||||||||||||||||||||||||||
| 103 | #pod $req->add_exclusion( $module => '1.75' ); | ||||||||||||||||||||||||||||
| 104 | #pod | ||||||||||||||||||||||||||||
| 105 | #pod Any version between 1.00 and 1.82 inclusive would be acceptable, except for | ||||||||||||||||||||||||||||
| 106 | #pod 1.75. | ||||||||||||||||||||||||||||
| 107 | #pod | ||||||||||||||||||||||||||||
| 108 | #pod This method returns the requirements object. | ||||||||||||||||||||||||||||
| 109 | #pod | ||||||||||||||||||||||||||||
| 110 | #pod =method exact_version | ||||||||||||||||||||||||||||
| 111 | #pod | ||||||||||||||||||||||||||||
| 112 | #pod $req->exact_version( $module => $version ); | ||||||||||||||||||||||||||||
| 113 | #pod | ||||||||||||||||||||||||||||
| 114 | #pod This sets the version required for the given module to I<exactly> the given | ||||||||||||||||||||||||||||
| 115 | #pod version. No other version would be considered acceptable. | ||||||||||||||||||||||||||||
| 116 | #pod | ||||||||||||||||||||||||||||
| 117 | #pod This method returns the requirements object. | ||||||||||||||||||||||||||||
| 118 | #pod | ||||||||||||||||||||||||||||
| 119 | #pod =cut | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 7 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||
| 122 | 7 | for my $type (qw(maximum exclusion exact_version)) { | |||||||||||||||||||||||||||
| 123 | 21 | my $method = "with_$type"; | |||||||||||||||||||||||||||
| 124 | 21 | ▶ | my $to_add = $type eq 'exact_version' ? $type : "add_$type"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my $code = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 127 | 0 | my ($self, $name, $version) = @_; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | $self->__modify_entry_for($name, $method, $version); | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | return $self; | |||||||||||||||||||||||||||
| 132 | 21 | }; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 135 | 21 | *$to_add = $code; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | # add_minimum is optimized compared to generated subs above because | ||||||||||||||||||||||||||||
| 140 | # it is called frequently and with "0" or equivalent input | ||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub add_minimum { | ||||||||||||||||||||||||||
|
Subroutine
add_minimum: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 0 | my ($self, $name, $version) = @_; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | # stringify $version so that version->new("0.00")->stringify ne "0" | ||||||||||||||||||||||||||||
| 145 | # which preserves the user's choice of "0.00" as the requirement | ||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if (not defined $version or "$version" eq '0') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $version or "$version" eq 0
MC/DC0%0/2
not defined $version or "$version" eq 0
not defined $version
"$version" eq 0
Truth table0%0/3
not(A) or B
A= not defined $versionB= "$version" eq 0
| |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | return $self if $self->__entry_for($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | Carp::croak("can't add new requirements to finalized requirements") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | if $self->is_finalized; | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | $self->{requirements}{ $name } = | |||||||||||||||||||||||||||
| 152 | CPAN::Meta::Requirements::Range->with_minimum('0', $name); | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | else { | ||||||||||||||||||||||||||||
| 155 | 0 | $self->__modify_entry_for($name, 'with_minimum', $version); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | 0 | return $self; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | #pod =method version_range_for_module | ||||||||||||||||||||||||||||
| 161 | #pod | ||||||||||||||||||||||||||||
| 162 | #pod $req->version_range_for_module( $another_req_object ); | ||||||||||||||||||||||||||||
| 163 | #pod | ||||||||||||||||||||||||||||
| 164 | #pod =cut | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub version_range_for_module { | ||||||||||||||||||||||||||
|
Subroutine
version_range_for_module: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | 0 | my ($self, $module) = @_; | |||||||||||||||||||||||||||
| 168 | 0 | return $self->{requirements}{$module}; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | #pod =method add_requirements | ||||||||||||||||||||||||||||
| 172 | #pod | ||||||||||||||||||||||||||||
| 173 | #pod $req->add_requirements( $another_req_object ); | ||||||||||||||||||||||||||||
| 174 | #pod | ||||||||||||||||||||||||||||
| 175 | #pod This method adds all the requirements in the given CPAN::Meta::Requirements | ||||||||||||||||||||||||||||
| 176 | #pod object to the requirements object on which it was called. If there are any | ||||||||||||||||||||||||||||
| 177 | #pod conflicts, an exception is thrown. | ||||||||||||||||||||||||||||
| 178 | #pod | ||||||||||||||||||||||||||||
| 179 | #pod This method returns the requirements object. | ||||||||||||||||||||||||||||
| 180 | #pod | ||||||||||||||||||||||||||||
| 181 | #pod =cut | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | sub add_requirements { | ||||||||||||||||||||||||||
|
Subroutine
add_requirements: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 184 | 0 | my ($self, $req) = @_; | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | for my $module ($req->required_modules) { | |||||||||||||||||||||||||||
| 187 | 0 | my $new_range = $req->version_range_for_module($module); | |||||||||||||||||||||||||||
| 188 | 0 | $self->__modify_entry_for($module, 'with_range', $new_range); | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | return $self; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | #pod =method accepts_module | ||||||||||||||||||||||||||||
| 195 | #pod | ||||||||||||||||||||||||||||
| 196 | #pod my $bool = $req->accepts_module($module => $version); | ||||||||||||||||||||||||||||
| 197 | #pod | ||||||||||||||||||||||||||||
| 198 | #pod Given an module and version, this method returns true if the version | ||||||||||||||||||||||||||||
| 199 | #pod specification for the module accepts the provided version. In other words, | ||||||||||||||||||||||||||||
| 200 | #pod given: | ||||||||||||||||||||||||||||
| 201 | #pod | ||||||||||||||||||||||||||||
| 202 | #pod Module => '>= 1.00, < 2.00' | ||||||||||||||||||||||||||||
| 203 | #pod | ||||||||||||||||||||||||||||
| 204 | #pod We will accept 1.00 and 1.75 but not 0.50 or 2.00. | ||||||||||||||||||||||||||||
| 205 | #pod | ||||||||||||||||||||||||||||
| 206 | #pod For modules that do not appear in the requirements, this method will return | ||||||||||||||||||||||||||||
| 207 | #pod true. | ||||||||||||||||||||||||||||
| 208 | #pod | ||||||||||||||||||||||||||||
| 209 | #pod =cut | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | ▶ | sub accepts_module { | ||||||||||||||||||||||||||
|
Subroutine
accepts_module: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 212 | 0 | my ($self, $module, $version) = @_; | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | ▶ | return 1 unless my $range = $self->__entry_for($module); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 0 | return $range->accepts($version); | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | #pod =method clear_requirement | ||||||||||||||||||||||||||||
| 219 | #pod | ||||||||||||||||||||||||||||
| 220 | #pod $req->clear_requirement( $module ); | ||||||||||||||||||||||||||||
| 221 | #pod | ||||||||||||||||||||||||||||
| 222 | #pod This removes the requirement for a given module from the object. | ||||||||||||||||||||||||||||
| 223 | #pod | ||||||||||||||||||||||||||||
| 224 | #pod This method returns the requirements object. | ||||||||||||||||||||||||||||
| 225 | #pod | ||||||||||||||||||||||||||||
| 226 | #pod =cut | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 0 | ▶ | sub clear_requirement { | ||||||||||||||||||||||||||
|
Subroutine
clear_requirement: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 229 | 0 | my ($self, $module) = @_; | |||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 0 | ▶ | return $self unless $self->__entry_for($module); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | ▶ | Carp::croak("can't clear requirements on finalized requirements") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | if $self->is_finalized; | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 0 | delete $self->{requirements}{ $module }; | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | return $self; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | #pod =method requirements_for_module | ||||||||||||||||||||||||||||
| 242 | #pod | ||||||||||||||||||||||||||||
| 243 | #pod $req->requirements_for_module( $module ); | ||||||||||||||||||||||||||||
| 244 | #pod | ||||||||||||||||||||||||||||
| 245 | #pod This returns a string containing the version requirements for a given module in | ||||||||||||||||||||||||||||
| 246 | #pod the format described in L<CPAN::Meta::Spec> or undef if the given module has no | ||||||||||||||||||||||||||||
| 247 | #pod requirements. This should only be used for informational purposes such as error | ||||||||||||||||||||||||||||
| 248 | #pod messages and should not be interpreted or used for comparison (see | ||||||||||||||||||||||||||||
| 249 | #pod L</accepts_module> instead). | ||||||||||||||||||||||||||||
| 250 | #pod | ||||||||||||||||||||||||||||
| 251 | #pod =cut | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 0 | ▶ | sub requirements_for_module { | ||||||||||||||||||||||||||
|
Subroutine
requirements_for_module: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 254 | 0 | my ($self, $module) = @_; | |||||||||||||||||||||||||||
| 255 | 0 | my $entry = $self->__entry_for($module); | |||||||||||||||||||||||||||
| 256 | 0 | ▶ | return unless $entry; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | 0 | return $entry->as_string; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | #pod =method structured_requirements_for_module | ||||||||||||||||||||||||||||
| 261 | #pod | ||||||||||||||||||||||||||||
| 262 | #pod $req->structured_requirements_for_module( $module ); | ||||||||||||||||||||||||||||
| 263 | #pod | ||||||||||||||||||||||||||||
| 264 | #pod This returns a data structure containing the version requirements for a given | ||||||||||||||||||||||||||||
| 265 | #pod module or undef if the given module has no requirements. This should | ||||||||||||||||||||||||||||
| 266 | #pod not be used for version checks (see L</accepts_module> instead). | ||||||||||||||||||||||||||||
| 267 | #pod | ||||||||||||||||||||||||||||
| 268 | #pod Added in version 2.134. | ||||||||||||||||||||||||||||
| 269 | #pod | ||||||||||||||||||||||||||||
| 270 | #pod =cut | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 0 | ▶ | sub structured_requirements_for_module { | ||||||||||||||||||||||||||
|
Subroutine
structured_requirements_for_module: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 273 | 0 | my ($self, $module) = @_; | |||||||||||||||||||||||||||
| 274 | 0 | my $entry = $self->__entry_for($module); | |||||||||||||||||||||||||||
| 275 | 0 | ▶ | return unless $entry; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | 0 | return $entry->as_struct; | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | #pod =method required_modules | ||||||||||||||||||||||||||||
| 280 | #pod | ||||||||||||||||||||||||||||
| 281 | #pod This method returns a list of all the modules for which requirements have been | ||||||||||||||||||||||||||||
| 282 | #pod specified. | ||||||||||||||||||||||||||||
| 283 | #pod | ||||||||||||||||||||||||||||
| 284 | #pod =cut | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 42 | ▶ | sub required_modules { keys %{ $_[0]{requirements} } } | ||||||||||||||||||||||||||
|
Subroutine
required_modules: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | #pod =method clone | ||||||||||||||||||||||||||||
| 289 | #pod | ||||||||||||||||||||||||||||
| 290 | #pod $req->clone; | ||||||||||||||||||||||||||||
| 291 | #pod | ||||||||||||||||||||||||||||
| 292 | #pod This method returns a clone of the invocant. The clone and the original object | ||||||||||||||||||||||||||||
| 293 | #pod can then be changed independent of one another. | ||||||||||||||||||||||||||||
| 294 | #pod | ||||||||||||||||||||||||||||
| 295 | #pod =cut | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 0 | ▶ | sub clone { | ||||||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 298 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 299 | 0 | my $new = (ref $self)->new; | |||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 0 | return $new->add_requirements($self); | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | 266 | ▶ | sub __entry_for { $_[0]{requirements}{ $_[1] } } | ||||||||||||||||||||||||||
|
Subroutine
__entry_for: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 266 | ▶ | sub __modify_entry_for { | ||||||||||||||||||||||||||
|
Subroutine
__modify_entry_for: called CC=6 SCAR=20.5
| |||||||||||||||||||||||||||||
| 307 | 266 | my ($self, $name, $method, $version) = @_; | |||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 266 | my $fin = $self->is_finalized; | |||||||||||||||||||||||||||
| 310 | 266 | my $old = $self->__entry_for($name); | |||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 266 | ▶ | Carp::croak("can't add new requirements to finalized requirements") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$fin and not $old
MC/DC0%0/2
$fin and not $old
$fin
not $old
Truth table33%1/3
A and not(B)
A= $finB= not $old
| |||||||||||||||||||||||||||||
| 313 | if $fin and not $old; | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | my $new = ($old || 'CPAN::Meta::Requirements::Range') | ||||||||||||||||||||||||||||
| 316 | 266 | ▶ | ->$method($version, $name, $self->{bad_version_hook}); | ||||||||||||||||||||||||||
|
Condition50%1/2
$old || 'CPAN::Meta::Requirements::Range'
MC/DC0%0/1
$old || 'CPAN::Meta::Requirements::Range'
$old
Truth table50%1/2
A
A= $old
| |||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 266 | ▶ | Carp::croak("can't modify finalized requirements") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$fin and $old->as_string ne $new->as_string
MC/DC0%0/2
$fin and $old->as_string ne $new->as_string
$fin
$old->as_string ne $new->as_string
Truth table33%1/3
A and B
A= $finB= $old->as_string ne $new->as_string
| |||||||||||||||||||||||||||||
| 319 | if $fin and $old->as_string ne $new->as_string; | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 266 | $self->{requirements}{ $name } = $new; | |||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | #pod =method is_simple | ||||||||||||||||||||||||||||
| 325 | #pod | ||||||||||||||||||||||||||||
| 326 | #pod This method returns true if and only if all requirements are inclusive minimums | ||||||||||||||||||||||||||||
| 327 | #pod -- that is, if their string expression is just the version number. | ||||||||||||||||||||||||||||
| 328 | #pod | ||||||||||||||||||||||||||||
| 329 | #pod =cut | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 0 | ▶ | sub is_simple { | ||||||||||||||||||||||||||
|
Subroutine
is_simple: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 332 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 333 | 0 | for my $module ($self->required_modules) { | |||||||||||||||||||||||||||
| 334 | # XXX: This is a complete hack, but also entirely correct. | ||||||||||||||||||||||||||||
| 335 | 0 | ▶ | return if not $self->__entry_for($module)->is_simple; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 0 | return 1; | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | #pod =method is_finalized | ||||||||||||||||||||||||||||
| 342 | #pod | ||||||||||||||||||||||||||||
| 343 | #pod This method returns true if the requirements have been finalized by having the | ||||||||||||||||||||||||||||
| 344 | #pod C<finalize> method called on them. | ||||||||||||||||||||||||||||
| 345 | #pod | ||||||||||||||||||||||||||||
| 346 | #pod =cut | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 266 | ▶ | sub is_finalized { $_[0]{finalized} } | ||||||||||||||||||||||||||
|
Subroutine
is_finalized: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | #pod =method finalize | ||||||||||||||||||||||||||||
| 351 | #pod | ||||||||||||||||||||||||||||
| 352 | #pod This method marks the requirements finalized. Subsequent attempts to change | ||||||||||||||||||||||||||||
| 353 | #pod the requirements will be fatal, I<if> they would result in a change. If they | ||||||||||||||||||||||||||||
| 354 | #pod would not alter the requirements, they have no effect. | ||||||||||||||||||||||||||||
| 355 | #pod | ||||||||||||||||||||||||||||
| 356 | #pod If a finalized set of requirements is cloned, the cloned requirements are not | ||||||||||||||||||||||||||||
| 357 | #pod also finalized. | ||||||||||||||||||||||||||||
| 358 | #pod | ||||||||||||||||||||||||||||
| 359 | #pod =cut | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 0 | ▶ | sub finalize { $_[0]{finalized} = 1 } | ||||||||||||||||||||||||||
|
Subroutine
finalize: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | #pod =method as_string_hash | ||||||||||||||||||||||||||||
| 364 | #pod | ||||||||||||||||||||||||||||
| 365 | #pod This returns a reference to a hash describing the requirements using the | ||||||||||||||||||||||||||||
| 366 | #pod strings in the L<CPAN::Meta::Spec> specification. | ||||||||||||||||||||||||||||
| 367 | #pod | ||||||||||||||||||||||||||||
| 368 | #pod For example after the following program: | ||||||||||||||||||||||||||||
| 369 | #pod | ||||||||||||||||||||||||||||
| 370 | #pod my $req = CPAN::Meta::Requirements->new; | ||||||||||||||||||||||||||||
| 371 | #pod | ||||||||||||||||||||||||||||
| 372 | #pod $req->add_minimum('CPAN::Meta::Requirements' => 0.102); | ||||||||||||||||||||||||||||
| 373 | #pod | ||||||||||||||||||||||||||||
| 374 | #pod $req->add_minimum('Library::Foo' => 1.208); | ||||||||||||||||||||||||||||
| 375 | #pod | ||||||||||||||||||||||||||||
| 376 | #pod $req->add_maximum('Library::Foo' => 2.602); | ||||||||||||||||||||||||||||
| 377 | #pod | ||||||||||||||||||||||||||||
| 378 | #pod $req->add_minimum('Module::Bar' => 'v1.2.3'); | ||||||||||||||||||||||||||||
| 379 | #pod | ||||||||||||||||||||||||||||
| 380 | #pod $req->add_exclusion('Module::Bar' => 'v1.2.8'); | ||||||||||||||||||||||||||||
| 381 | #pod | ||||||||||||||||||||||||||||
| 382 | #pod $req->exact_version('Xyzzy' => '6.01'); | ||||||||||||||||||||||||||||
| 383 | #pod | ||||||||||||||||||||||||||||
| 384 | #pod my $hashref = $req->as_string_hash; | ||||||||||||||||||||||||||||
| 385 | #pod | ||||||||||||||||||||||||||||
| 386 | #pod C<$hashref> would contain: | ||||||||||||||||||||||||||||
| 387 | #pod | ||||||||||||||||||||||||||||
| 388 | #pod { | ||||||||||||||||||||||||||||
| 389 | #pod 'CPAN::Meta::Requirements' => '0.102', | ||||||||||||||||||||||||||||
| 390 | #pod 'Library::Foo' => '>= 1.208, <= 2.206', | ||||||||||||||||||||||||||||
| 391 | #pod 'Module::Bar' => '>= v1.2.3, != v1.2.8', | ||||||||||||||||||||||||||||
| 392 | #pod 'Xyzzy' => '== 6.01', | ||||||||||||||||||||||||||||
| 393 | #pod } | ||||||||||||||||||||||||||||
| 394 | #pod | ||||||||||||||||||||||||||||
| 395 | #pod =cut | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 42 | ▶ | sub as_string_hash { | ||||||||||||||||||||||||||
|
Subroutine
as_string_hash: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 398 | 42 | my ($self) = @_; | |||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | 42 | my %hash = map {; $_ => $self->{requirements}{$_}->as_string } | |||||||||||||||||||||||||||
| 401 | $self->required_modules; | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | 42 | return \%hash; | |||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | #pod =method add_string_requirement | ||||||||||||||||||||||||||||
| 407 | #pod | ||||||||||||||||||||||||||||
| 408 | #pod $req->add_string_requirement('Library::Foo' => '>= 1.208, <= 2.206'); | ||||||||||||||||||||||||||||
| 409 | #pod $req->add_string_requirement('Library::Foo' => v1.208); | ||||||||||||||||||||||||||||
| 410 | #pod | ||||||||||||||||||||||||||||
| 411 | #pod This method parses the passed in string and adds the appropriate requirement | ||||||||||||||||||||||||||||
| 412 | #pod for the given module. A version can be a Perl "v-string". It understands | ||||||||||||||||||||||||||||
| 413 | #pod version ranges as described in the L<CPAN::Meta::Spec/Version Ranges>. For | ||||||||||||||||||||||||||||
| 414 | #pod example: | ||||||||||||||||||||||||||||
| 415 | #pod | ||||||||||||||||||||||||||||
| 416 | #pod =over 4 | ||||||||||||||||||||||||||||
| 417 | #pod | ||||||||||||||||||||||||||||
| 418 | #pod =item 1.3 | ||||||||||||||||||||||||||||
| 419 | #pod | ||||||||||||||||||||||||||||
| 420 | #pod =item >= 1.3 | ||||||||||||||||||||||||||||
| 421 | #pod | ||||||||||||||||||||||||||||
| 422 | #pod =item <= 1.3 | ||||||||||||||||||||||||||||
| 423 | #pod | ||||||||||||||||||||||||||||
| 424 | #pod =item == 1.3 | ||||||||||||||||||||||||||||
| 425 | #pod | ||||||||||||||||||||||||||||
| 426 | #pod =item != 1.3 | ||||||||||||||||||||||||||||
| 427 | #pod | ||||||||||||||||||||||||||||
| 428 | #pod =item > 1.3 | ||||||||||||||||||||||||||||
| 429 | #pod | ||||||||||||||||||||||||||||
| 430 | #pod =item < 1.3 | ||||||||||||||||||||||||||||
| 431 | #pod | ||||||||||||||||||||||||||||
| 432 | #pod =item >= 1.3, != 1.5, <= 2.0 | ||||||||||||||||||||||||||||
| 433 | #pod | ||||||||||||||||||||||||||||
| 434 | #pod A version number without an operator is equivalent to specifying a minimum | ||||||||||||||||||||||||||||
| 435 | #pod (C<E<gt>=>). Extra whitespace is allowed. | ||||||||||||||||||||||||||||
| 436 | #pod | ||||||||||||||||||||||||||||
| 437 | #pod =back | ||||||||||||||||||||||||||||
| 438 | #pod | ||||||||||||||||||||||||||||
| 439 | #pod =cut | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 266 | ▶ | sub add_string_requirement { | ||||||||||||||||||||||||||
|
Subroutine
add_string_requirement: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 442 | 266 | my ($self, $module, $req) = @_; | |||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 266 | $self->__modify_entry_for($module, 'with_string_requirement', $req); | |||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | #pod =method from_string_hash | ||||||||||||||||||||||||||||
| 448 | #pod | ||||||||||||||||||||||||||||
| 449 | #pod my $req = CPAN::Meta::Requirements->from_string_hash( \%hash ); | ||||||||||||||||||||||||||||
| 450 | #pod my $req = CPAN::Meta::Requirements->from_string_hash( \%hash, \%opts ); | ||||||||||||||||||||||||||||
| 451 | #pod | ||||||||||||||||||||||||||||
| 452 | #pod This is an alternate constructor for a CPAN::Meta::Requirements | ||||||||||||||||||||||||||||
| 453 | #pod object. It takes a hash of module names and version requirement | ||||||||||||||||||||||||||||
| 454 | #pod strings and returns a new CPAN::Meta::Requirements object. As with | ||||||||||||||||||||||||||||
| 455 | #pod add_string_requirement, a version can be a Perl "v-string". Optionally, | ||||||||||||||||||||||||||||
| 456 | #pod you can supply a hash-reference of options, exactly as with the L</new> | ||||||||||||||||||||||||||||
| 457 | #pod method. | ||||||||||||||||||||||||||||
| 458 | #pod | ||||||||||||||||||||||||||||
| 459 | #pod =cut | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | 0 | ▶ | sub from_string_hash { | ||||||||||||||||||||||||||
|
Subroutine
from_string_hash: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 462 | 0 | my ($class, $hash, $options) = @_; | |||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | 0 | my $self = $class->new($options); | |||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 0 | for my $module (keys %$hash) { | |||||||||||||||||||||||||||
| 467 | 0 | my $req = $hash->{$module}; | |||||||||||||||||||||||||||
| 468 | 0 | $self->add_string_requirement($module, $req); | |||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | 0 | return $self; | |||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | 7 | 1; | |||||||||||||||||||||||||||
| 475 | # vim: ts=2 sts=2 sw=2 et: | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | __END__ | ||||||||||||||||||||||||||||