| 1 | package Carmel::Resolver; | ||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use Class::Tiny qw( repo snapshot root seen found missing ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | ▶ | use Module::CoreList; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 0 | ▶ | sub resolve { | ||||||||||||||||||
|
Subroutine
resolve: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 10 | 0 | my $self = shift; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 0 | my $clone = $self->root->clone; | |||||||||||||||||||
| 13 | 0 | my $seen = {}; | |||||||||||||||||||
| 14 | 0 | my $depth = 0; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 0 | $self->resolve_recurse($clone, $seen, $depth); | |||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 0 | ▶ | sub resolve_recurse { | ||||||||||||||||||
|
Subroutine
resolve_recurse: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||
| 20 | 0 | my($self, $requirements, $seen, $depth) = @_; | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 0 | for my $module (sort $requirements->required_modules) { | |||||||||||||||||||
| 23 | 0 | ▶ | next if $module eq 'perl'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 0 | my $want_version = $self->root->requirements_for_module($module); | |||||||||||||||||||
| 26 | 0 | my $dist = $self->find_in_snapshot($module); | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | $self->should_handle($module, $want_version, $dist) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | or next; | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | my $artifact; | |||||||||||||||||||
| 32 | 0 | ▶ | if ($dist) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 0 | $artifact = $self->repo->find_dist($module, $dist->name); | |||||||||||||||||||
| 34 | } else { | ||||||||||||||||||||
| 35 | 0 | ▶ | $artifact = $self->repo->find_match($module, sub { $self->accepts_all($self->root, $_[0]) }); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | # FIXME there's a chance different version of the same module can be loaded here | ||||||||||||||||||||
| 39 | 0 | ▶ | if ($artifact) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 0 | ▶ | warn sprintf " %s (%s) in %s\n", $module, $artifact->version_for($module), $artifact->path if $Carmel::DEBUG; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 0 | ▶ | next if $seen->{$artifact->path}++; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | $self->found->($artifact, $depth); | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | my $reqs = $artifact->requirements; | |||||||||||||||||||
| 45 | 0 | $self->merge_requirements($self->root, $reqs, $artifact->distname); | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | $self->resolve_recurse($reqs, $seen, $depth + 1); | |||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||
| 49 | 0 | ▶ | if ($dist) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | # TODO pass $dist->distfile to cpanfile | ||||||||||||||||||||
| 51 | 0 | $want_version = $dist->version_for($module); | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | 0 | $self->missing->($module, $want_version, $depth); | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | ▶ | sub should_handle { | ||||||||||||||||||
|
Subroutine
should_handle: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 59 | 0 | my($self, $module, $version, $dist) = @_; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | # not in core | ||||||||||||||||||||
| 62 | 0 | ▶ | return 1 unless $self->is_core($module); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | # core version doesn't satisfy the version | ||||||||||||||||||||
| 65 | 0 | ▶ | return 1 unless $self->core_satisfies($module, $version); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | # core, pinned, and the pinned version is lower than the core version: | ||||||||||||||||||||
| 68 | # remove it from the snapshot and upgrade (#47) | ||||||||||||||||||||
| 69 | 0 | ▶ | return $dist && | ||||||||||||||||||
|
Condition0%0/3
$dist && 'version'->parse($dist->version_for($module)) > 'version'->parse($self->core_version($module))
MC/DC0%0/2
$dist && 'version'->parse($dist->version_for($module)) > 'version'->parse($self->core_version($module))
$dist
'version'->parse($dist->version_for($module)) > 'version'->parse($self->core_version($module))
Truth table0%0/3
A && B
A= $distB= 'version'->parse($dist->version_for($module)) > 'version'->parse($self->core_version($module))
| |||||||||||||||||||||
| 70 | version::->parse($dist->version_for($module)) | ||||||||||||||||||||
| 71 | > version::->parse($self->core_version($module)); | ||||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 0 | ▶ | sub core_version { | ||||||||||||||||||
|
Subroutine
core_version: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 75 | 0 | my($self, $module) = @_; | |||||||||||||||||||
| 76 | 0 | ▶ | return $Module::CoreList::version{$]+0}{$module} || '0'; | ||||||||||||||||||
|
Condition0%0/2
$Module::CoreList::version{$] + 0}{$module} || '0'
MC/DC0%0/1
$Module::CoreList::version{$] + 0}{$module} || '0'
$Module::CoreList::version{$] + 0}{$module}
Truth table0%0/2
A
A= $Module::CoreList::version{$] + 0}{$module}
| |||||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | ▶ | sub is_core { | ||||||||||||||||||
|
Subroutine
is_core: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 80 | 0 | my($self, $module) = @_; | |||||||||||||||||||
| 81 | 0 | return exists $Module::CoreList::version{$]+0}{$module}; | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 0 | ▶ | sub core_satisfies { | ||||||||||||||||||
|
Subroutine
core_satisfies: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 85 | 0 | my($self, $module, $want_version) = @_; | |||||||||||||||||||
| 86 | 0 | ▶ | return unless exists $Module::CoreList::version{$]+0}{$module}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | ▶ | my $version = $Module::CoreList::version{$]+0}{$module} || '0'; | ||||||||||||||||||
|
Condition0%0/2
$Module::CoreList::version{$] + 0}{$module} || '0'
MC/DC0%0/1
$Module::CoreList::version{$] + 0}{$module} || '0'
$Module::CoreList::version{$] + 0}{$module}
Truth table0%0/2
A
A= $Module::CoreList::version{$] + 0}{$module}
| |||||||||||||||||||||
| 89 | 0 | CPAN::Meta::Requirements->from_string_hash({ $module => $want_version }) | |||||||||||||||||||
| 90 | ->accepts_module($module, $version); | ||||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | ▶ | sub find_in_snapshot { | ||||||||||||||||||
|
Subroutine
find_in_snapshot: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||
| 94 | 0 | my($self, $module) = @_; | |||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 0 | ▶ | my $snapshot = $self->snapshot or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | ▶ | if (my $dist = $snapshot->find($module)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | 0 | ▶ | warn "@{[$dist->name]} found in snapshot for $module\n" if $Carmel::DEBUG; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | 0 | ▶ | if ($self->accepts_all($self->root, $dist)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | 0 | return $dist; | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | ▶ | warn "$module not found in snapshot\n" if $Carmel::DEBUG; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 106 | 0 | return; | |||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 0 | ▶ | sub accepts_all { | ||||||||||||||||||
|
Subroutine
accepts_all: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 110 | 0 | my($self, $reqs, $dist) = @_; | |||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 0 | for my $pkg (keys %{$dist->provides}) { | |||||||||||||||||||
| 113 | 0 | ▶ | my $version = $dist->provides->{$pkg}{version} || '0'; | ||||||||||||||||||
|
Condition0%0/2
$dist->provides->{$pkg}{'version'} || '0'
MC/DC0%0/1
$dist->provides->{$pkg}{'version'} || '0'
$dist->provides->{$pkg}{'version'}
Truth table0%0/2
A
A= $dist->provides->{$pkg}{'version'}
| |||||||||||||||||||||
| 114 | 0 | ▶ | return unless $reqs->accepts_module($pkg, $version); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 0 | return 1; | |||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 0 | ▶ | sub merge_requirements { | ||||||||||||||||||
|
Subroutine
merge_requirements: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 121 | 0 | my($self, $reqs, $new_reqs, $where) = @_; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 0 | for my $module ($new_reqs->required_modules) { | |||||||||||||||||||
| 124 | 0 | my $new = $new_reqs->requirements_for_module($module); | |||||||||||||||||||
| 125 | 0 | ▶ | try { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 126 | 0 | $reqs->add_string_requirement($module, $new); | |||||||||||||||||||
| 127 | 0 | ▶ | } catch { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 128 | 0 | my($err) = /illegal requirements(?: .*?): (.*) at/; | |||||||||||||||||||
| 129 | 0 | my $old = $reqs->requirements_for_module($module); | |||||||||||||||||||
| 130 | 0 | die "Found conflicting requirement for $module: '$old' <=> '$new' ($where): $err\n"; | |||||||||||||||||||
| 131 | 0 | }; | |||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | 1 | 1; | |||||||||||||||||||