← Index
NYTProf Performance Profile   « line view »
For Makefile.PL
  Run on Sun Mar 1 16:04:44 2015
Reported on Sun Mar 1 16:09:02 2015

FilenameC:/tmp64ng/perl/lib/CPAN/Meta/Requirements.pm
StatementsExecuted 2506 statements in 0s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1110s0sCPAN::Meta::Prereqs::::BEGIN@1 CPAN::Meta::Prereqs::BEGIN@1
1110s0sCPAN::Meta::Prereqs::::BEGIN@2 CPAN::Meta::Prereqs::BEGIN@2
1110s0sCPAN::Meta::Requirements::::BEGIN@209 CPAN::Meta::Requirements::BEGIN@209
1110s0sCPAN::Meta::Requirements::::BEGIN@224 CPAN::Meta::Requirements::BEGIN@224
1110s0sCPAN::Meta::Requirements::::BEGIN@35 CPAN::Meta::Requirements::BEGIN@35
1110s0sCPAN::Meta::Requirements::::BEGIN@43 CPAN::Meta::Requirements::BEGIN@43
48210s0sCPAN::Meta::Requirements::::CORE:match CPAN::Meta::Requirements::CORE:match (opcode)
39110s0sCPAN::Meta::Requirements::::CORE:qr CPAN::Meta::Requirements::CORE:qr (opcode)
39110s0sCPAN::Meta::Requirements::::CORE:regcomp CPAN::Meta::Requirements::CORE:regcomp (opcode)
0000s0sCPAN::Meta::Requirements::_Range::Exact::::_acceptsCPAN::Meta::Requirements::_Range::Exact::_accepts
0000s0sCPAN::Meta::Requirements::_Range::Exact::::_cloneCPAN::Meta::Requirements::_Range::Exact::_clone
0000s0sCPAN::Meta::Requirements::_Range::Exact::::_newCPAN::Meta::Requirements::_Range::Exact::_new
0000s0sCPAN::Meta::Requirements::_Range::Exact::::as_modifiersCPAN::Meta::Requirements::_Range::Exact::as_modifiers
0000s0sCPAN::Meta::Requirements::_Range::Exact::::as_stringCPAN::Meta::Requirements::_Range::Exact::as_string
0000s0sCPAN::Meta::Requirements::_Range::Exact::::with_exact_versionCPAN::Meta::Requirements::_Range::Exact::with_exact_version
0000s0sCPAN::Meta::Requirements::_Range::Exact::::with_exclusionCPAN::Meta::Requirements::_Range::Exact::with_exclusion
0000s0sCPAN::Meta::Requirements::_Range::Exact::::with_maximumCPAN::Meta::Requirements::_Range::Exact::with_maximum
0000s0sCPAN::Meta::Requirements::_Range::Exact::::with_minimumCPAN::Meta::Requirements::_Range::Exact::with_minimum
0000s0sCPAN::Meta::Requirements::_Range::Range::::_acceptsCPAN::Meta::Requirements::_Range::Range::_accepts
48110s0sCPAN::Meta::Requirements::_Range::Range::::_cloneCPAN::Meta::Requirements::_Range::Range::_clone
0000s0sCPAN::Meta::Requirements::_Range::Range::::_selfCPAN::Meta::Requirements::_Range::Range::_self
48110s0sCPAN::Meta::Requirements::_Range::Range::::_simplifyCPAN::Meta::Requirements::_Range::Range::_simplify
9110s0sCPAN::Meta::Requirements::_Range::Range::::as_modifiersCPAN::Meta::Requirements::_Range::Range::as_modifiers
39110s0sCPAN::Meta::Requirements::_Range::Range::::as_stringCPAN::Meta::Requirements::_Range::Range::as_string
0000s0sCPAN::Meta::Requirements::_Range::Range::::with_exact_versionCPAN::Meta::Requirements::_Range::Range::with_exact_version
0000s0sCPAN::Meta::Requirements::_Range::Range::::with_exclusionCPAN::Meta::Requirements::_Range::Range::with_exclusion
0000s0sCPAN::Meta::Requirements::_Range::Range::::with_maximumCPAN::Meta::Requirements::_Range::Range::with_maximum
48210s0sCPAN::Meta::Requirements::_Range::Range::::with_minimumCPAN::Meta::Requirements::_Range::Range::with_minimum
0000s0sCPAN::Meta::Requirements::::__ANON__[:129] CPAN::Meta::Requirements::__ANON__[:129]
0000s0sCPAN::Meta::Requirements::::__ANON__[:222] CPAN::Meta::Requirements::__ANON__[:222]
9110s0sCPAN::Meta::Requirements::::__ANON__[:51] CPAN::Meta::Requirements::__ANON__[:51]
57310s0sCPAN::Meta::Requirements::::__entry_for CPAN::Meta::Requirements::__entry_for
9110s0sCPAN::Meta::Requirements::::__modify_entry_for CPAN::Meta::Requirements::__modify_entry_for
0000s0sCPAN::Meta::Requirements::::_blank_carp CPAN::Meta::Requirements::_blank_carp
39110s0sCPAN::Meta::Requirements::::_find_magic_vstring CPAN::Meta::Requirements::_find_magic_vstring
0000s0sCPAN::Meta::Requirements::::_isa_version CPAN::Meta::Requirements::_isa_version
9110s0sCPAN::Meta::Requirements::::_version_object CPAN::Meta::Requirements::_version_object
0000s0sCPAN::Meta::Requirements::::accepts_module CPAN::Meta::Requirements::accepts_module
48210s0sCPAN::Meta::Requirements::::add_minimum CPAN::Meta::Requirements::add_minimum
9110s0sCPAN::Meta::Requirements::::add_requirements CPAN::Meta::Requirements::add_requirements
39220s0sCPAN::Meta::Requirements::::add_string_requirement CPAN::Meta::Requirements::add_string_requirement
54210s0sCPAN::Meta::Requirements::::as_string_hash CPAN::Meta::Requirements::as_string_hash
0000s0sCPAN::Meta::Requirements::::clear_requirement CPAN::Meta::Requirements::clear_requirement
0000s0sCPAN::Meta::Requirements::::clone CPAN::Meta::Requirements::clone
0000s0sCPAN::Meta::Requirements::::finalize CPAN::Meta::Requirements::finalize
18210s0sCPAN::Meta::Requirements::::from_string_hash CPAN::Meta::Requirements::from_string_hash
48210s0sCPAN::Meta::Requirements::::is_finalized CPAN::Meta::Requirements::is_finalized
0000s0sCPAN::Meta::Requirements::::is_simple CPAN::Meta::Requirements::is_simple
63220s0sCPAN::Meta::Requirements::::new CPAN::Meta::Requirements::new
63210s0sCPAN::Meta::Requirements::::required_modules CPAN::Meta::Requirements::required_modules
0000s0sCPAN::Meta::Requirements::::requirements_for_module CPAN::Meta::Requirements::requirements_for_module
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
120s20s
# spent 0s within CPAN::Meta::Prereqs::BEGIN@1 which was called: # once (0s+0s) by CPAN::Meta::Prereqs::BEGIN@17 at line 1
use strict;
# spent 0s making 1 call to CPAN::Meta::Prereqs::BEGIN@1 # spent 0s making 1 call to strict::import
220s20s
# spent 0s within CPAN::Meta::Prereqs::BEGIN@2 which was called: # once (0s+0s) by CPAN::Meta::Prereqs::BEGIN@17 at line 2
use warnings;
# spent 0s making 1 call to CPAN::Meta::Prereqs::BEGIN@2 # spent 0s making 1 call to warnings::import
3package CPAN::Meta::Requirements;
4# ABSTRACT: a set of version requirements for a CPAN dist
5
610sour $VERSION = '2.132';
7
8#pod =head1 SYNOPSIS
9#pod
10#pod use CPAN::Meta::Requirements;
11#pod
12#pod my $build_requires = CPAN::Meta::Requirements->new;
13#pod
14#pod $build_requires->add_minimum('Library::Foo' => 1.208);
15#pod
16#pod $build_requires->add_minimum('Library::Foo' => 2.602);
17#pod
18#pod $build_requires->add_minimum('Module::Bar' => 'v1.2.3');
19#pod
20#pod $METAyml->{build_requires} = $build_requires->as_string_hash;
21#pod
22#pod =head1 DESCRIPTION
23#pod
24#pod A CPAN::Meta::Requirements object models a set of version constraints like
25#pod those specified in the F<META.yml> or F<META.json> files in CPAN distributions,
26#pod and as defined by L<CPAN::Meta::Spec>;
27#pod It can be built up by adding more and more constraints, and it will reduce them
28#pod to the simplest representation.
29#pod
30#pod Logically impossible constraints will be identified immediately by thrown
31#pod exceptions.
32#pod
33#pod =cut
34
3520s10s
# spent 0s within CPAN::Meta::Requirements::BEGIN@35 which was called: # once (0s+0s) by CPAN::Meta::Prereqs::BEGIN@17 at line 35
use Carp ();
# spent 0s making 1 call to CPAN::Meta::Requirements::BEGIN@35
36
37# To help ExtUtils::MakeMaker bootstrap CPAN::Meta::Requirements on perls
38# before 5.10, we fall back to the EUMM bundled compatibility version module if
39# that's the only thing available. This shouldn't ever happen in a normal CPAN
40# install of CPAN::Meta::Requirements, as version.pm will be picked up from
41# prereqs and be available at runtime.
42
43
# spent 0s within CPAN::Meta::Requirements::BEGIN@43 which was called: # once (0s+0s) by CPAN::Meta::Prereqs::BEGIN@17 at line 48
BEGIN {
4410s eval "use version ()"; ## no critic
# spent 0s executing statements in string eval
# includes 0s spent executing 1 call to 1 sub defined therein.
4510s if ( my $err = $@ ) {
46 eval "use ExtUtils::MakeMaker::version" or die $err; ## no critic
47 }
4810s10s}
# spent 0s making 1 call to CPAN::Meta::Requirements::BEGIN@43
49
50# Perl 5.10.0 didn't have "is_qv" in version.pm
51100s100s
# spent 0s within CPAN::Meta::Requirements::__ANON__[C:/tmp64ng/perl/lib/CPAN/Meta/Requirements.pm:51] which was called 9 times, avg 0s/call: # 9 times (0s+0s) by CPAN::Meta::Requirements::_version_object at line 150, avg 0s/call
*_is_qv = version->can('is_qv') ? sub { $_[0]->is_qv } : sub { exists $_[0]->{qv} };
# spent 0s making 1 call to UNIVERSAL::can # spent 0s making 9 calls to version::is_qv, avg 0s/call
52
53# construct once, reuse many times
5410s10smy $V0 = version->new(0);
# spent 0s making 1 call to version::vxs::new
55
56#pod =method new
57#pod
58#pod my $req = CPAN::Meta::Requirements->new;
59#pod
60#pod This returns a new CPAN::Meta::Requirements object. It takes an optional
61#pod hash reference argument. Currently, only one key is supported:
62#pod
63#pod =for :list
64#pod * C<bad_version_hook> -- if provided, when a version cannot be parsed into
65#pod a version object, this code reference will be called with the invalid
66#pod version string as first argument, and the module name as second
67#pod argument. It must return a valid version object.
68#pod
69#pod All other keys are ignored.
70#pod
71#pod =cut
72
7310smy @valid_options = qw( bad_version_hook );
74
75
# spent 0s within CPAN::Meta::Requirements::new which was called 63 times, avg 0s/call: # 45 times (0s+0s) by CPAN::Meta::Converter::_version_map at line 401 of CPAN/Meta/Converter.pm, avg 0s/call # 18 times (0s+0s) by CPAN::Meta::Requirements::from_string_hash at line 565, avg 0s/call
sub new {
76630s my ($class, $options) = @_;
77630s $options ||= {};
78630s Carp::croak "Argument to $class\->new() must be a hash reference"
79 unless ref $options eq 'HASH';
80630s my %self = map {; $_ => $options->{$_}} @valid_options;
81
82630s return bless \%self => $class;
83}
84
85# from version::vpp
86
# spent 0s within CPAN::Meta::Requirements::_find_magic_vstring which was called 39 times, avg 0s/call: # 39 times (0s+0s) by CPAN::Meta::Requirements::add_string_requirement at line 521, avg 0s/call
sub _find_magic_vstring {
87390s my $value = shift;
88390s my $tvalue = '';
89390s require B;
90390s390s my $sv = B::svref_2object(\$value);
# spent 0s making 39 calls to B::svref_2object, avg 0s/call
91390s my $magic = ref($sv) eq 'B::PVMG' ? $sv->MAGIC : undef;
92390s while ( $magic ) {
93 if ( $magic->TYPE eq 'V' ) {
94 $tvalue = $magic->PTR;
95 $tvalue =~ s/^v?(.+)$/v$1/;
96 last;
97 }
98 else {
99 $magic = $magic->MOREMAGIC;
100 }
101 }
102390s return $tvalue;
103}
104
105# safe if given an unblessed reference
106sub _isa_version {
107 UNIVERSAL::isa( $_[0], 'UNIVERSAL' ) && $_[0]->isa('version')
108}
109
110
# spent 0s within CPAN::Meta::Requirements::_version_object which was called 9 times, avg 0s/call: # 9 times (0s+0s) by CPAN::Meta::Requirements::add_minimum at line 241, avg 0s/call
sub _version_object {
11190s my ($self, $module, $version) = @_;
112
11390s my $vobj;
114
115 # hack around version::vpp not handling <3 character vstring literals
11690s if ( $INC{'version/vpp.pm'} || $INC{'ExtUtils/MakeMaker/version/vpp.pm'} ) {
117 my $magic = _find_magic_vstring( $version );
118 $version = $magic if length $magic;
119 }
120
12190s eval {
12290s if (not defined $version or (!ref($version) && $version eq '0')) {
123 $vobj = $V0;
124 }
125 elsif ( ref($version) eq 'version' || _isa_version($version) ) {
126 $vobj = $version;
127 }
128 else {
129 local $SIG{__WARN__} = sub { die "Invalid version: $_[0]" };
130 $vobj = version->new($version);
131 }
132 };
133
13490s if ( my $err = $@ ) {
135 my $hook = $self->{bad_version_hook};
136 $vobj = eval { $hook->($version, $module) }
137 if ref $hook eq 'CODE';
138 unless (eval { $vobj->isa("version") }) {
139 $err =~ s{ at .* line \d+.*$}{};
140 die "Can't convert '$version': $err";
141 }
142 }
143
144 # ensure no leading '.'
14590s180s if ( $vobj =~ m{\A\.} ) {
# spent 0s making 9 calls to CPAN::Meta::Requirements::CORE:match, avg 0s/call # spent 0s making 9 calls to version::vxs::stringify, avg 0s/call
146 $vobj = version->new("0$vobj");
147 }
148
149 # ensure normal v-string form
15090s90s if ( _is_qv($vobj) ) {
# spent 0s making 9 calls to CPAN::Meta::Requirements::__ANON__[CPAN/Meta/Requirements.pm:51], avg 0s/call
151 $vobj = version->new($vobj->normal);
152 }
153
15490s return $vobj;
155}
156
157#pod =method add_minimum
158#pod
159#pod $req->add_minimum( $module => $version );
160#pod
161#pod This adds a new minimum version requirement. If the new requirement is
162#pod redundant to the existing specification, this has no effect.
163#pod
164#pod Minimum requirements are inclusive. C<$version> is required, along with any
165#pod greater version number.
166#pod
167#pod This method returns the requirements object.
168#pod
169#pod =method add_maximum
170#pod
171#pod $req->add_maximum( $module => $version );
172#pod
173#pod This adds a new maximum version requirement. If the new requirement is
174#pod redundant to the existing specification, this has no effect.
175#pod
176#pod Maximum requirements are inclusive. No version strictly greater than the given
177#pod version is allowed.
178#pod
179#pod This method returns the requirements object.
180#pod
181#pod =method add_exclusion
182#pod
183#pod $req->add_exclusion( $module => $version );
184#pod
185#pod This adds a new excluded version. For example, you might use these three
186#pod method calls:
187#pod
188#pod $req->add_minimum( $module => '1.00' );
189#pod $req->add_maximum( $module => '1.82' );
190#pod
191#pod $req->add_exclusion( $module => '1.75' );
192#pod
193#pod Any version between 1.00 and 1.82 inclusive would be acceptable, except for
194#pod 1.75.
195#pod
196#pod This method returns the requirements object.
197#pod
198#pod =method exact_version
199#pod
200#pod $req->exact_version( $module => $version );
201#pod
202#pod This sets the version required for the given module to I<exactly> the given
203#pod version. No other version would be considered acceptable.
204#pod
205#pod This method returns the requirements object.
206#pod
207#pod =cut
208
209
# spent 0s within CPAN::Meta::Requirements::BEGIN@209 which was called: # once (0s+0s) by CPAN::Meta::Prereqs::BEGIN@17 at line 227
BEGIN {
21010s for my $type (qw(maximum exclusion exact_version)) {
21130s my $method = "with_$type";
21230s my $to_add = $type eq 'exact_version' ? $type : "add_$type";
213
214 my $code = sub {
215 my ($self, $name, $version) = @_;
216
217 $version = $self->_version_object( $name, $version );
218
219 $self->__modify_entry_for($name, $method, $version);
220
221 return $self;
22230s };
223
22420s20s
# spent 0s within CPAN::Meta::Requirements::BEGIN@224 which was called: # once (0s+0s) by CPAN::Meta::Prereqs::BEGIN@17 at line 224
no strict 'refs';
# spent 0s making 1 call to CPAN::Meta::Requirements::BEGIN@224 # spent 0s making 1 call to strict::unimport
22530s *$to_add = $code;
226 }
22710s10s}
# spent 0s making 1 call to CPAN::Meta::Requirements::BEGIN@209
228
229
# spent 0s within CPAN::Meta::Requirements::add_minimum which was called 48 times, avg 0s/call: # 39 times (0s+0s) by CPAN::Meta::Requirements::add_string_requirement at line 532, avg 0s/call # 9 times (0s+0s) by CPAN::Meta::Requirements::add_requirements at line 267, avg 0s/call
sub add_minimum {
230480s my ($self, $name, $version) = @_;
231
232480s if (not defined $version or (!ref($version) && $version eq '0')) {
233390s390s return $self if $self->__entry_for($name);
# spent 0s making 39 calls to CPAN::Meta::Requirements::__entry_for, avg 0s/call
234390s390s Carp::confess("can't add new requirements to finalized requirements")
# spent 0s making 39 calls to CPAN::Meta::Requirements::is_finalized, avg 0s/call
235 if $self->is_finalized;
236
237390s390s $self->{requirements}{ $name } =
# spent 0s making 39 calls to CPAN::Meta::Requirements::_Range::Range::with_minimum, avg 0s/call
238 CPAN::Meta::Requirements::_Range::Range->with_minimum($V0);
239 }
240 else {
24190s90s $version = $self->_version_object( $name, $version );
# spent 0s making 9 calls to CPAN::Meta::Requirements::_version_object, avg 0s/call
242
24390s90s $self->__modify_entry_for($name, 'with_minimum', $version);
# spent 0s making 9 calls to CPAN::Meta::Requirements::__modify_entry_for, avg 0s/call
244 }
245480s return $self;
246}
247
248#pod =method add_requirements
249#pod
250#pod $req->add_requirements( $another_req_object );
251#pod
252#pod This method adds all the requirements in the given CPAN::Meta::Requirements object
253#pod to the requirements object on which it was called. If there are any conflicts,
254#pod an exception is thrown.
255#pod
256#pod This method returns the requirements object.
257#pod
258#pod =cut
259
260
# spent 0s within CPAN::Meta::Requirements::add_requirements which was called 9 times, avg 0s/call: # 9 times (0s+0s) by CPAN::Meta::Converter::_get_build_requires at line 503 of CPAN/Meta/Converter.pm, avg 0s/call
sub add_requirements {
26190s my ($self, $req) = @_;
262
26390s90s for my $module ($req->required_modules) {
# spent 0s making 9 calls to CPAN::Meta::Requirements::required_modules, avg 0s/call
26490s180s my $modifiers = $req->__entry_for($module)->as_modifiers;
# spent 0s making 9 calls to CPAN::Meta::Requirements::_Range::Range::as_modifiers, avg 0s/call # spent 0s making 9 calls to CPAN::Meta::Requirements::__entry_for, avg 0s/call
26590s for my $modifier (@$modifiers) {
26690s my ($method, @args) = @$modifier;
26790s90s $self->$method($module => @args);
# spent 0s making 9 calls to CPAN::Meta::Requirements::add_minimum, avg 0s/call
268 };
269 }
270
27190s return $self;
272}
273
274#pod =method accepts_module
275#pod
276#pod my $bool = $req->accepts_module($module => $version);
277#pod
278#pod Given an module and version, this method returns true if the version
279#pod specification for the module accepts the provided version. In other words,
280#pod given:
281#pod
282#pod Module => '>= 1.00, < 2.00'
283#pod
284#pod We will accept 1.00 and 1.75 but not 0.50 or 2.00.
285#pod
286#pod For modules that do not appear in the requirements, this method will return
287#pod true.
288#pod
289#pod =cut
290
291sub accepts_module {
292 my ($self, $module, $version) = @_;
293
294 $version = $self->_version_object( $module, $version );
295
296 return 1 unless my $range = $self->__entry_for($module);
297 return $range->_accepts($version);
298}
299
300#pod =method clear_requirement
301#pod
302#pod $req->clear_requirement( $module );
303#pod
304#pod This removes the requirement for a given module from the object.
305#pod
306#pod This method returns the requirements object.
307#pod
308#pod =cut
309
310sub clear_requirement {
311 my ($self, $module) = @_;
312
313 return $self unless $self->__entry_for($module);
314
315 Carp::confess("can't clear requirements on finalized requirements")
316 if $self->is_finalized;
317
318 delete $self->{requirements}{ $module };
319
320 return $self;
321}
322
323#pod =method requirements_for_module
324#pod
325#pod $req->requirements_for_module( $module );
326#pod
327#pod This returns a string containing the version requirements for a given module in
328#pod the format described in L<CPAN::Meta::Spec> or undef if the given module has no
329#pod requirements. This should only be used for informational purposes such as error
330#pod messages and should not be interpreted or used for comparison (see
331#pod L</accepts_module> instead.)
332#pod
333#pod =cut
334
335sub requirements_for_module {
336 my ($self, $module) = @_;
337 my $entry = $self->__entry_for($module);
338 return unless $entry;
339 return $entry->as_string;
340}
341
342#pod =method required_modules
343#pod
344#pod This method returns a list of all the modules for which requirements have been
345#pod specified.
346#pod
347#pod =cut
348
349630s
# spent 0s within CPAN::Meta::Requirements::required_modules which was called 63 times, avg 0s/call: # 54 times (0s+0s) by CPAN::Meta::Requirements::as_string_hash at line 463, avg 0s/call # 9 times (0s+0s) by CPAN::Meta::Requirements::add_requirements at line 263, avg 0s/call
sub required_modules { keys %{ $_[0]{requirements} } }
350
351#pod =method clone
352#pod
353#pod $req->clone;
354#pod
355#pod This method returns a clone of the invocant. The clone and the original object
356#pod can then be changed independent of one another.
357#pod
358#pod =cut
359
360sub clone {
361 my ($self) = @_;
362 my $new = (ref $self)->new;
363
364 return $new->add_requirements($self);
365}
366
367570s
# spent 0s within CPAN::Meta::Requirements::__entry_for which was called 57 times, avg 0s/call: # 39 times (0s+0s) by CPAN::Meta::Requirements::add_minimum at line 233, avg 0s/call # 9 times (0s+0s) by CPAN::Meta::Requirements::add_requirements at line 264, avg 0s/call # 9 times (0s+0s) by CPAN::Meta::Requirements::__modify_entry_for at line 373, avg 0s/call
sub __entry_for { $_[0]{requirements}{ $_[1] } }
368
369
# spent 0s within CPAN::Meta::Requirements::__modify_entry_for which was called 9 times, avg 0s/call: # 9 times (0s+0s) by CPAN::Meta::Requirements::add_minimum at line 243, avg 0s/call
sub __modify_entry_for {
37090s my ($self, $name, $method, $version) = @_;
371
37290s90s my $fin = $self->is_finalized;
# spent 0s making 9 calls to CPAN::Meta::Requirements::is_finalized, avg 0s/call
37390s90s my $old = $self->__entry_for($name);
# spent 0s making 9 calls to CPAN::Meta::Requirements::__entry_for, avg 0s/call
374
37590s Carp::confess("can't add new requirements to finalized requirements")
376 if $fin and not $old;
377
37890s90s my $new = ($old || 'CPAN::Meta::Requirements::_Range::Range')
# spent 0s making 9 calls to CPAN::Meta::Requirements::_Range::Range::with_minimum, avg 0s/call
379 ->$method($version);
380
38190s Carp::confess("can't modify finalized requirements")
382 if $fin and $old->as_string ne $new->as_string;
383
38490s $self->{requirements}{ $name } = $new;
385}
386
387#pod =method is_simple
388#pod
389#pod This method returns true if and only if all requirements are inclusive minimums
390#pod -- that is, if their string expression is just the version number.
391#pod
392#pod =cut
393
394sub is_simple {
395 my ($self) = @_;
396 for my $module ($self->required_modules) {
397 # XXX: This is a complete hack, but also entirely correct.
398 return if $self->__entry_for($module)->as_string =~ /\s/;
399 }
400
401 return 1;
402}
403
404#pod =method is_finalized
405#pod
406#pod This method returns true if the requirements have been finalized by having the
407#pod C<finalize> method called on them.
408#pod
409#pod =cut
410
411480s
# spent 0s within CPAN::Meta::Requirements::is_finalized which was called 48 times, avg 0s/call: # 39 times (0s+0s) by CPAN::Meta::Requirements::add_minimum at line 234, avg 0s/call # 9 times (0s+0s) by CPAN::Meta::Requirements::__modify_entry_for at line 372, avg 0s/call
sub is_finalized { $_[0]{finalized} }
412
413#pod =method finalize
414#pod
415#pod This method marks the requirements finalized. Subsequent attempts to change
416#pod the requirements will be fatal, I<if> they would result in a change. If they
417#pod would not alter the requirements, they have no effect.
418#pod
419#pod If a finalized set of requirements is cloned, the cloned requirements are not
420#pod also finalized.
421#pod
422#pod =cut
423
424sub finalize { $_[0]{finalized} = 1 }
425
426#pod =method as_string_hash
427#pod
428#pod This returns a reference to a hash describing the requirements using the
429#pod strings in the L<CPAN::Meta::Spec> specification.
430#pod
431#pod For example after the following program:
432#pod
433#pod my $req = CPAN::Meta::Requirements->new;
434#pod
435#pod $req->add_minimum('CPAN::Meta::Requirements' => 0.102);
436#pod
437#pod $req->add_minimum('Library::Foo' => 1.208);
438#pod
439#pod $req->add_maximum('Library::Foo' => 2.602);
440#pod
441#pod $req->add_minimum('Module::Bar' => 'v1.2.3');
442#pod
443#pod $req->add_exclusion('Module::Bar' => 'v1.2.8');
444#pod
445#pod $req->exact_version('Xyzzy' => '6.01');
446#pod
447#pod my $hashref = $req->as_string_hash;
448#pod
449#pod C<$hashref> would contain:
450#pod
451#pod {
452#pod 'CPAN::Meta::Requirements' => '0.102',
453#pod 'Library::Foo' => '>= 1.208, <= 2.206',
454#pod 'Module::Bar' => '>= v1.2.3, != v1.2.8',
455#pod 'Xyzzy' => '== 6.01',
456#pod }
457#pod
458#pod =cut
459
460
# spent 0s within CPAN::Meta::Requirements::as_string_hash which was called 54 times, avg 0s/call: # 45 times (0s+0s) by CPAN::Meta::Converter::_version_map at line 417 of CPAN/Meta/Converter.pm, avg 0s/call # 9 times (0s+0s) by CPAN::Meta::Converter::_get_build_requires at line 503 of CPAN/Meta/Converter.pm, avg 0s/call
sub as_string_hash {
461540s my ($self) = @_;
462
463540s930s my %hash = map {; $_ => $self->{requirements}{$_}->as_string }
# spent 0s making 39 calls to CPAN::Meta::Requirements::_Range::Range::as_string, avg 0s/call # spent 0s making 54 calls to CPAN::Meta::Requirements::required_modules, avg 0s/call
464 $self->required_modules;
465
466540s return \%hash;
467}
468
469#pod =method add_string_requirement
470#pod
471#pod $req->add_string_requirement('Library::Foo' => '>= 1.208, <= 2.206');
472#pod $req->add_string_requirement('Library::Foo' => v1.208);
473#pod
474#pod This method parses the passed in string and adds the appropriate requirement
475#pod for the given module. A version can be a Perl "v-string". It understands
476#pod version ranges as described in the L<CPAN::Meta::Spec/Version Ranges>. For
477#pod example:
478#pod
479#pod =over 4
480#pod
481#pod =item 1.3
482#pod
483#pod =item >= 1.3
484#pod
485#pod =item <= 1.3
486#pod
487#pod =item == 1.3
488#pod
489#pod =item != 1.3
490#pod
491#pod =item > 1.3
492#pod
493#pod =item < 1.3
494#pod
495#pod =item >= 1.3, != 1.5, <= 2.0
496#pod
497#pod A version number without an operator is equivalent to specifying a minimum
498#pod (C<E<gt>=>). Extra whitespace is allowed.
499#pod
500#pod =back
501#pod
502#pod =cut
503
50410smy %methods_for_op = (
505 '==' => [ qw(exact_version) ],
506 '!=' => [ qw(add_exclusion) ],
507 '>=' => [ qw(add_minimum) ],
508 '<=' => [ qw(add_maximum) ],
509 '>' => [ qw(add_minimum add_exclusion) ],
510 '<' => [ qw(add_maximum add_exclusion) ],
511);
512
513
# spent 0s within CPAN::Meta::Requirements::add_string_requirement which was called 39 times, avg 0s/call: # 30 times (0s+0s) by CPAN::Meta::Converter::_version_map at line 415 of CPAN/Meta/Converter.pm, avg 0s/call # 9 times (0s+0s) by CPAN::Meta::Requirements::from_string_hash at line 573, avg 0s/call
sub add_string_requirement {
514390s my ($self, $module, $req) = @_;
515
516390s unless ( defined $req && length $req ) {
517 $req = 0;
518 $self->_blank_carp($module);
519 }
520
521390s390s my $magic = _find_magic_vstring( $req );
# spent 0s making 39 calls to CPAN::Meta::Requirements::_find_magic_vstring, avg 0s/call
522390s if (length $magic) {
523 $self->add_minimum($module => $magic);
524 return;
525 }
526
527390s780s my @parts = split qr{\s*,\s*}, $req;
# spent 0s making 39 calls to CPAN::Meta::Requirements::CORE:qr, avg 0s/call # spent 0s making 39 calls to CPAN::Meta::Requirements::CORE:regcomp, avg 0s/call
528
529390s for my $part (@parts) {
530390s390s my ($op, $ver) = $part =~ m{\A\s*(==|>=|>|<=|<|!=)\s*(.*)\z};
# spent 0s making 39 calls to CPAN::Meta::Requirements::CORE:match, avg 0s/call
531
532390s390s if (! defined $op) {
# spent 0s making 39 calls to CPAN::Meta::Requirements::add_minimum, avg 0s/call
533 $self->add_minimum($module => $part);
534 } else {
535 Carp::confess("illegal requirement string: $req")
536 unless my $methods = $methods_for_op{ $op };
537
538 $self->$_($module => $ver) for @$methods;
539 }
540 }
541}
542
543#pod =method from_string_hash
544#pod
545#pod my $req = CPAN::Meta::Requirements->from_string_hash( \%hash );
546#pod my $req = CPAN::Meta::Requirements->from_string_hash( \%hash, \%opts );
547#pod
548#pod This is an alternate constructor for a CPAN::Meta::Requirements
549#pod object. It takes a hash of module names and version requirement
550#pod strings and returns a new CPAN::Meta::Requirements object. As with
551#pod add_string_requirement, a version can be a Perl "v-string". Optionally,
552#pod you can supply a hash-reference of options, exactly as with the L</new>
553#pod method.
554#pod
555#pod =cut
556
557sub _blank_carp {
558 my ($self, $module) = @_;
559 Carp::carp("Undefined requirement for $module treated as '0'");
560}
561
562
# spent 0s within CPAN::Meta::Requirements::from_string_hash which was called 18 times, avg 0s/call: # 9 times (0s+0s) by CPAN::Meta::Converter::_get_build_requires at line 500 of CPAN/Meta/Converter.pm, avg 0s/call # 9 times (0s+0s) by CPAN::Meta::Converter::_get_build_requires at line 501 of CPAN/Meta/Converter.pm, avg 0s/call
sub from_string_hash {
563180s my ($class, $hash, $options) = @_;
564
565180s180s my $self = $class->new($options);
# spent 0s making 18 calls to CPAN::Meta::Requirements::new, avg 0s/call
566
567180s for my $module (keys %$hash) {
56890s my $req = $hash->{$module};
56990s unless ( defined $req && length $req ) {
570 $req = 0;
571 $class->_blank_carp($module);
572 }
57390s90s $self->add_string_requirement($module, $req);
# spent 0s making 9 calls to CPAN::Meta::Requirements::add_string_requirement, avg 0s/call
574 }
575
576180s return $self;
577}
578
579##############################################################
580
581{
58210s package
583 CPAN::Meta::Requirements::_Range::Exact;
584 sub _new { bless { version => $_[1] } => $_[0] }
585
586 sub _accepts { return $_[0]{version} == $_[1] }
587
588 sub as_string { return "== $_[0]{version}" }
589
590 sub as_modifiers { return [ [ exact_version => $_[0]{version} ] ] }
591
592 sub _clone {
593 (ref $_[0])->_new( version->new( $_[0]{version} ) )
594 }
595
596 sub with_exact_version {
597 my ($self, $version) = @_;
598
599 return $self->_clone if $self->_accepts($version);
600
601 Carp::confess("illegal requirements: unequal exact version specified");
602 }
603
604 sub with_minimum {
605 my ($self, $minimum) = @_;
606 return $self->_clone if $self->{version} >= $minimum;
607 Carp::confess("illegal requirements: minimum above exact specification");
608 }
609
610 sub with_maximum {
611 my ($self, $maximum) = @_;
612 return $self->_clone if $self->{version} <= $maximum;
613 Carp::confess("illegal requirements: maximum below exact specification");
614 }
615
616 sub with_exclusion {
617 my ($self, $exclusion) = @_;
618 return $self->_clone unless $exclusion == $self->{version};
619 Carp::confess("illegal requirements: excluded exact specification");
620 }
621}
622
623##############################################################
624
625{
62610s package
627 CPAN::Meta::Requirements::_Range::Range;
628
629 sub _self { ref($_[0]) ? $_[0] : (bless { } => $_[0]) }
630
631
# spent 0s within CPAN::Meta::Requirements::_Range::Range::_clone which was called 48 times, avg 0s/call: # 48 times (0s+0s) by CPAN::Meta::Requirements::_Range::Range::with_minimum at line 730, avg 0s/call
sub _clone {
632480s return (bless { } => $_[0]) unless ref $_[0];
633
634 my ($s) = @_;
635 my %guts = (
636 (exists $s->{minimum} ? (minimum => version->new($s->{minimum})) : ()),
637 (exists $s->{maximum} ? (maximum => version->new($s->{maximum})) : ()),
638
639 (exists $s->{exclusions}
640 ? (exclusions => [ map { version->new($_) } @{ $s->{exclusions} } ])
641 : ()),
642 );
643
644 bless \%guts => ref($s);
645 }
646
647
# spent 0s within CPAN::Meta::Requirements::_Range::Range::as_modifiers which was called 9 times, avg 0s/call: # 9 times (0s+0s) by CPAN::Meta::Requirements::add_requirements at line 264, avg 0s/call
sub as_modifiers {
64890s my ($self) = @_;
64990s my @mods;
65090s push @mods, [ add_minimum => $self->{minimum} ] if exists $self->{minimum};
65190s push @mods, [ add_maximum => $self->{maximum} ] if exists $self->{maximum};
65290s push @mods, map {; [ add_exclusion => $_ ] } @{$self->{exclusions} || []};
65390s return \@mods;
654 }
655
656
# spent 0s within CPAN::Meta::Requirements::_Range::Range::as_string which was called 39 times, avg 0s/call: # 39 times (0s+0s) by CPAN::Meta::Requirements::as_string_hash at line 463, avg 0s/call
sub as_string {
657390s my ($self) = @_;
658
659390s return 0 if ! keys %$self;
660
661390s390s return "$self->{minimum}" if (keys %$self) == 1 and exists $self->{minimum};
# spent 0s making 39 calls to version::vxs::stringify, avg 0s/call
662
663 my @exclusions = @{ $self->{exclusions} || [] };
664
665 my @parts;
666
667 for my $pair (
668 [ qw( >= > minimum ) ],
669 [ qw( <= < maximum ) ],
670 ) {
671 my ($op, $e_op, $k) = @$pair;
672 if (exists $self->{$k}) {
673 my @new_exclusions = grep { $_ != $self->{ $k } } @exclusions;
674 if (@new_exclusions == @exclusions) {
675 push @parts, "$op $self->{ $k }";
676 } else {
677 push @parts, "$e_op $self->{ $k }";
678 @exclusions = @new_exclusions;
679 }
680 }
681 }
682
683 push @parts, map {; "!= $_" } @exclusions;
684
685 return join q{, }, @parts;
686 }
687
688 sub with_exact_version {
689 my ($self, $version) = @_;
690 $self = $self->_clone;
691
692 Carp::confess("illegal requirements: exact specification outside of range")
693 unless $self->_accepts($version);
694
695 return CPAN::Meta::Requirements::_Range::Exact->_new($version);
696 }
697
698
# spent 0s within CPAN::Meta::Requirements::_Range::Range::_simplify which was called 48 times, avg 0s/call: # 48 times (0s+0s) by CPAN::Meta::Requirements::_Range::Range::with_minimum at line 738, avg 0s/call
sub _simplify {
699480s my ($self) = @_;
700
701480s if (defined $self->{minimum} and defined $self->{maximum}) {
702 if ($self->{minimum} == $self->{maximum}) {
703 Carp::confess("illegal requirements: excluded all values")
704 if grep { $_ == $self->{minimum} } @{ $self->{exclusions} || [] };
705
706 return CPAN::Meta::Requirements::_Range::Exact->_new($self->{minimum})
707 }
708
709 Carp::confess("illegal requirements: minimum exceeds maximum")
710 if $self->{minimum} > $self->{maximum};
711 }
712
713 # eliminate irrelevant exclusions
714480s if ($self->{exclusions}) {
715 my %seen;
716 @{ $self->{exclusions} } = grep {
717 (! defined $self->{minimum} or $_ >= $self->{minimum})
718 and
719 (! defined $self->{maximum} or $_ <= $self->{maximum})
720 and
721 ! $seen{$_}++
722 } @{ $self->{exclusions} };
723 }
724
725480s return $self;
726 }
727
728
# spent 0s within CPAN::Meta::Requirements::_Range::Range::with_minimum which was called 48 times, avg 0s/call: # 39 times (0s+0s) by CPAN::Meta::Requirements::add_minimum at line 237, avg 0s/call # 9 times (0s+0s) by CPAN::Meta::Requirements::__modify_entry_for at line 378, avg 0s/call
sub with_minimum {
729480s my ($self, $minimum) = @_;
730480s480s $self = $self->_clone;
# spent 0s making 48 calls to CPAN::Meta::Requirements::_Range::Range::_clone, avg 0s/call
731
732480s if (defined (my $old_min = $self->{minimum})) {
733 $self->{minimum} = (sort { $b cmp $a } ($minimum, $old_min))[0];
734 } else {
735480s $self->{minimum} = $minimum;
736 }
737
738480s480s return $self->_simplify;
# spent 0s making 48 calls to CPAN::Meta::Requirements::_Range::Range::_simplify, avg 0s/call
739 }
740
741 sub with_maximum {
742 my ($self, $maximum) = @_;
743 $self = $self->_clone;
744
745 if (defined (my $old_max = $self->{maximum})) {
746 $self->{maximum} = (sort { $a cmp $b } ($maximum, $old_max))[0];
747 } else {
748 $self->{maximum} = $maximum;
749 }
750
751 return $self->_simplify;
752 }
753
754 sub with_exclusion {
755 my ($self, $exclusion) = @_;
756 $self = $self->_clone;
757
758 push @{ $self->{exclusions} ||= [] }, $exclusion;
759
760 return $self->_simplify;
761 }
762
763 sub _accepts {
764 my ($self, $version) = @_;
765
766 return if defined $self->{minimum} and $version < $self->{minimum};
767 return if defined $self->{maximum} and $version > $self->{maximum};
768 return if defined $self->{exclusions}
769 and grep { $version == $_ } @{ $self->{exclusions} };
770
771 return 1;
772 }
773}
774
77510s1;
776# vim: ts=2 sts=2 sw=2 et:
777
778__END__
 
# spent 0s within CPAN::Meta::Requirements::CORE:match which was called 48 times, avg 0s/call: # 39 times (0s+0s) by CPAN::Meta::Requirements::add_string_requirement at line 530, avg 0s/call # 9 times (0s+0s) by CPAN::Meta::Requirements::_version_object at line 145, avg 0s/call
sub CPAN::Meta::Requirements::CORE:match; # opcode
# spent 0s within CPAN::Meta::Requirements::CORE:qr which was called 39 times, avg 0s/call: # 39 times (0s+0s) by CPAN::Meta::Requirements::add_string_requirement at line 527, avg 0s/call
sub CPAN::Meta::Requirements::CORE:qr; # opcode
# spent 0s within CPAN::Meta::Requirements::CORE:regcomp which was called 39 times, avg 0s/call: # 39 times (0s+0s) by CPAN::Meta::Requirements::add_string_requirement at line 527, avg 0s/call
sub CPAN::Meta::Requirements::CORE:regcomp; # opcode