lib/Skilletor/Resolver.pm

filter: Statementstmt 87.5% 415 / 474 Branchbran 76.9% 140 / 182 Conditioncond 52.0% 75 / 144 MC/DCmcdc 34.1% 28 / 82 Subroutinesub 93.5% 58 / 62 Podpod 75.0% 3 / 4 totaltotal 75.8% 719 / 948 CC 176 SCAR 38.5
CC
176
Cov
79%
_resolve_scope
155.6
__ANON__
30.0
_merge_chain_vars
15.3
CRAP 46.9
« /usr/local/lib/perl5/site_perl/5.44.0/Sub/Quote.pm ↑ Summary /usr/local/lib/perl5/site_perl/5.44.0/x86_64-linux/Class/XSAccessor.pm »
1 package Skilletor::Resolver;
2 # ABSTRACT: What each scope resolves to – a sync's steps 1–3, stopped before anything is built
3  
4 400 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 400 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 400 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 400 ▶use Skilletor::Backend;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 400 ▶use Skilletor::Bundles qw( expand_bundle entry_miss match_entry matches_pattern same_identity );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 400 ▶use Skilletor::Cache qw( cache_name git_identity );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 400 ▶use Skilletor::Catalog;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 400 ▶use Skilletor::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 400 ▶use Skilletor::Entry qw( WILDCARD name_key );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 400 ▶use Skilletor::FSUtil qw( decode_utf8_lossy encode_text path_join same_path );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 400 ▶use Skilletor::JSON qw( js_ordered js_stringify js_type );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 400 ▶use Skilletor::Lock qw( read_lock key_to_type_name );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 400 ▶use Skilletor::Source::Git;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 400 ▶use Skilletor::Source::Url;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 400 ▶use Skilletor::State;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 400 ▶use Skilletor::Targets qw( default_markers detect_harnesses detect_project_harnesses select_targets );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 400 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 400 our $VERSION = '0.008000';
23  
24 400 my %TYPE_DIR = ( skill => 'skills', agent => 'agents', rule => 'rules' );
25 400 my %FETCH = map { $_ => 1 } qw( always missing never );
26  
27 400 has home => (
28 is => 'ro',
29 required => 1,
30 );
31  
32 400 has project_dir => (
33 is => 'ro',
34 );
35  
36 # `CLAUDE_CONFIG_DIR` (k145): Claude Code's config dir, which is the user scope's `.claude` –
37 # config, lock, state, roots – and where its plugin state lives. Empty means unset.
38 has claude_config_dir => (
39 is => 'lazy',
40 1417 ▶ builder => sub { defined $ENV{CLAUDE_CONFIG_DIR} ? decode_utf8_lossy( $ENV{CLAUDE_CONFIG_DIR} ) : undef },
Subroutine _build_claude_config_dir: called CC=2 SCAR=6.9
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 2 branches
BranchTrueFalseTotal
defined $ENV{'CLAUDE_CONFIG_DIR'} ? : 6 1411 1417
defined $ENV{'CLAUDE_CONFIG_DIR'} ? : 2 476 478
41 400 );
42  
43 has state_root => (
44 is => 'lazy',
45 1333 ▶ builder => sub { Skilletor::State->default_root( $_[0]->home, $_[0]->claude_config_dir ) },
Subroutine _build_state_root: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
46 400 );
47  
48 has cache_root => (
49 is => 'lazy',
50 2417 ▶ builder => sub { path_join( $_[0]->state_root, 'cache' ) },
Subroutine _build_cache_root: called CC=1 SCAR=0.0
51 400 );
52  
53 # `$CODEX_HOME`, for the harness markers; empty means unset.
54 has codex_home => (
55 is => 'lazy',
56 398 ▶ builder => sub { defined $ENV{CODEX_HOME} ? decode_utf8_lossy( $ENV{CODEX_HOME} ) : undef },
Subroutine _build_codex_home: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'CODEX_HOME'} ? : 21 377 398
57 400 );
58  
59 has markers => (
60 is => 'lazy',
61 1622 ▶ builder => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
Subroutine _build_markers: called CC=5 SCAR=16.1
62 1622 my ( $self ) = @_;
63 1622 my $cx = $self->codex_home;
64 1622 my $cd = $self->claude_config_dir;
65 1622 ▶ return default_markers( $self->home, ( defined $cx && length $cx ) ? $cx : undef, ( defined $cd && length $cd ) ? $cd : undef );
Branch: 2 branches
BranchTrueFalseTotal
defined $cx && length $cx ? : 1370 252 1622
defined $cd && length $cd ? : 1 1621 1622
Condition83%5/6
defined $cx and length $cx
!ll&&!rl&&r
25201370
defined $cd and length $cd
!ll&&!rl&&r
13782431
MC/DC50%1/2
defined $cx and length $cx
defined $cx length $cx
MC/DC100%2/2
defined $cd and length $cd
defined $cd length $cd
Truth table66%2/3
A and B
A= defined $cxB= length $cx
ABresult
0X0
100
111
Truth table100%3/3
A and B
A= defined $cdB= length $cd
ABresult
0X0
100
111
66 },
67 400 );
68  
69 has require_harness => (
70 is => 'ro',
71 4281 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
72 400 );
73  
74 has fetch => (
75 is => 'ro',
76 4281 ▶ default => sub { 'always' },
Subroutine __ANON__: called CC=1 SCAR=0.0
77 4575 ▶ isa => sub { croak 'fetch must be always, missing or never' unless defined $_[0] && $FETCH{ $_[0] } },
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] and $FETCH{$_[0]} 1 4574 4575
Condition66%2/3
defined $_[0] and $FETCH{$_[0]}
!ll&&!rl&&r
014574
MC/DC50%1/2
defined $_[0] and $FETCH{$_[0]}
defined $_[0] $FETCH{$_[0]}
Truth table66%2/3
A and B
A= defined $_[0]B= $FETCH{$_[0]}
ABresult
0X0
100
111
78 400 );
79  
80 400 has timeout_ms => (
81 is => 'ro',
82 );
83  
84 has lock_timeout_ms => (
85 is => 'ro',
86 4479 ▶ default => sub { 5_000 },
Subroutine __ANON__: called CC=1 SCAR=0.0
87 400 );
88  
89 128 ▶sub _message {
Subroutine _message: called CC=3 SCAR=14.2
90 128 my ( $err ) = @_;
91 128 ▶ return $err->message if blessed $err && $err->can('message');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($err) and $err->can("message") 128 0 128
Condition33%1/3
builtin::blessed($err) and $err->can("message")
!ll&&!rl&&r
00128
MC/DC0%0/2
builtin::blessed($err) and $err->can("message")
builtin::blessed($err) $err->can("message")
Truth table33%1/3
A and B
A= builtin::blessed($err)B= $err->can("message")
ABresult
0X0
100
111
92 0 return ( "$err" =~ s/ at \S+ line \d+\.?\n?\z//r );
93 }
94  
95 # The project dir, unless it is the home dir itself: then there is no project scope (spec §6.1).
96 70763 ▶sub project_dir_of {
Subroutine project_dir_of: called CC=4 SCAR=13.9
Pod documented
97 70763 my ( $self ) = @_;
98 70763 my $p = $self->project_dir;
99 70763 ▶ return undef if !defined $p || !length $p || same_path( $p, $self->home );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $p && length $p or same_path($p, $self->home) 517 70246 70763
Condition83%5/6
not defined $p && length $p or same_path($p, $self->home)
l!l&&r!l&&!r
5061170246
defined $p && length $p
!ll&&!rl&&r
506070257
MC/DC66%2/3
not defined $p && length $p or same_path($p, $self->home)
defined $p length $p same_path($p, $self->home)
Truth table75%3/4
not(A && B) or C
A= defined $pB= length $pC= same_path($p, $self->home)
ABCresult
0XX1
10X1
1111
1100
100 70246 return $p;
101 }
102  
103 # Claude Code's config dir: the explicit one, else `<home>/.claude`.
104 32849 ▶sub claude_dir {
Subroutine claude_dir: called CC=3 SCAR=11.0
Pod undocumented
105 32849 my ( $self ) = @_;
106 32849 my $cd = $self->claude_config_dir;
107 32849 ▶ return ( defined $cd && length $cd ) ? $cd : path_join( $self->home, '.claude' );
Branch: 1 branch
BranchTrueFalseTotal
defined $cd && length $cd ? : 3976 28873 32849
Condition100%3/3
defined $cd and length $cd
!ll&&!rl&&r
2565632173976
MC/DC100%2/2
defined $cd and length $cd
defined $cd length $cd
Truth table100%3/3
A and B
A= defined $cdB= length $cd
ABresult
0X0
100
111
108 }
109  
110 # The scope's `.claude` directory: config, lock and the claude target root.
111 35961 ▶sub _target_dir {
Subroutine _target_dir: called CC=2 SCAR=6.9
112 35961 my ( $self, $scope ) = @_;
113 35961 ▶ return $scope eq 'user' ? $self->claude_dir : path_join( $self->_base_of($scope), '.claude' );
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'user' ? : 7702 28259 35961
114 }
115  
116 50022 ▶sub _base_of {
Subroutine _base_of: called CC=2 SCAR=6.9
117 50022 my ( $self, $scope ) = @_;
118 50022 ▶ return $scope eq 'user' ? $self->home : $self->project_dir_of;
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'user' ? : 8314 41708 50022
119 }
120  
121 # Config and targets. A harness is only needed with require_harness (the reference's sync
122 # needs one); without it a machine with none resolves all the same, with no targets warnings.
123 389 ▶sub _load {
Subroutine _load: called CC=10 SCAR=23.2
124 389 my ( $self, $include_project ) = @_;
125 389 ▶ $include_project //= 1;
Condition50%1/2
$include_project //= 1
l!l
3890
MC/DC0%0/1
$include_project //= 1
$include_project
Truth table50%1/2
A
A= $include_project
Aresult
11
00
126 389 my $config = Skilletor::Config->load( home => $self->home, claude_config_dir => $self->claude_config_dir, project_dir => $self->project_dir_of );
127 341 my $markers = $self->markers;
128 341 ▶ my $wanted = { user => $config->user->{targets}, project => $config->project ? $config->project->{targets} : undef };
Branch: 1 branch
BranchTrueFalseTotal
$config->project ? : 121 220 341
129 341 ▶ if ( $include_project && $config->project && !exists $config->project->{targets} && defined $self->project_dir_of ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($include_project and $config->project and not exists $config->project->{"targets"} and defined $self->project_dir_of) 121 220 341
Condition66%6/9
$include_project and $config->project and not exists $config->project->{"targets"} and defined $self->project_dir_of
!ll&&!rl&&r
2200121
$include_project and $config->project and not exists $config->project->{"targets"}
!ll&&!rl&&r
2200121
$include_project and $config->project
!ll&&!rl&&r
0220121
MC/DC25%1/4
$include_project and $config->project and not exists $config->project->{"targets"} and defined $self->project_dir_of
$include_project $config->project not exists $config->project->{"targets"} defined $self->project_dir_of
Truth table40%2/5
A and B and not(C) and D
A= $include_projectB= $config->projectC= not exists $config->project->{"targets"}D= defined $self->project_dir_of
ABCDresult
0XXX0
10XX0
110X0
11100
11111
130 121 my $target_dir = $self->_target_dir('project');
131 121 my $lock_path = path_join( $target_dir, 'skilletor.lock.json' );
132 121 my $in_use = grep { -e encode_text($_) } map { path_join( $target_dir, $_ ) } qw( skilletor.json skilletor.local.json skilletor.lock.json );
133 121 ▶ $wanted->{project_evidence} = detect_project_harnesses( $self->project_dir_of, read_lock($lock_path) ) if $in_use;
Branch: 1 branch
BranchTrueFalseTotal
if $in_use 121 0 121
134 }
135 341 my $targets = eval { select_targets( $wanted, detect_harnesses($markers), $markers ) };
136 341 ▶ unless ($targets) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($targets) 261 80 341
137 261 ▶ die $@ if $self->require_harness;
Branch: 1 branch
BranchTrueFalseTotal
if $self->require_harness 24 237 261
138 237 $targets = { user => [], project => [], warnings => [] };
139 }
140 317 return ( $config, $targets );
141 }
142  
143 389 ▶sub resolve {
Subroutine resolve: called CC=3 SCAR=11.1
Pod documented
144 389 my ( $self, %opts ) = @_;
145 389 ▶ my $sel = $opts{scope} // 'all';
Condition100%2/2
$opts{"scope"} // "all"
l!l
30683
MC/DC100%1/1
$opts{"scope"} // "all"
$opts{"scope"}
Truth table100%2/2
A
A= $opts{"scope"}
Aresult
11
00
146 389 ▶ croak 'scope must be user, project or all' unless $sel =~ /\A(?:user|project|all)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $sel =~ /\A(?:user|project|all)\z/ 0 389 389
147 389 my $state = Skilletor::State->new( root => $self->state_root, read_once => 1 );
148 return $state->with_lock(
149 389 ▶ sub {
Subroutine __ANON__: called CC=10 SCAR=23.3
150 389 Skilletor::Source::Url->sweep_cache( $self->cache_root );
151 389 Skilletor::Source::Git->sweep_cache( $self->cache_root );
152 389 my ( $config, $targets );
153 389 ▶ unless ( eval { ( $config, $targets ) = $self->_load( $sel ne 'user' ); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { () = $self->_load($sel ne "user"); 1 } }) 72 317 389
154 72 my $err = $@;
155 72 ▶ die $err if $opts{throw};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"throw"} 24 48 72
156 48 return { scopes => [], error => _message($err) };
157 }
158 317 my $run = {}; # each backend resolved once per run, for both scopes
159 317 my @scopes;
160 317 ▶ push @scopes, [ user => $config->user ] if $sel eq 'user' || $sel eq 'all';
Branch: 1 branch
BranchTrueFalseTotal
if $sel eq "user" or $sel eq "all" 317 0 317
Condition33%1/3
$sel eq "user" or $sel eq "all"
l!l&&r!l&&!r
03170
MC/DC0%0/2
$sel eq "user" or $sel eq "all"
$sel eq "user" $sel eq "all"
Truth table33%1/3
A or B
A= $sel eq "user"B= $sel eq "all"
ABresult
1X1
011
000
161 317 ▶ push @scopes, [ project => $config->project ] if ( $sel eq 'project' || $sel eq 'all' ) && $config->project;
Branch: 1 branch
BranchTrueFalseTotal
if $sel eq "project" || $sel eq "all" and $config->project 97 220 317
Condition50%3/6
$sel eq "project" || $sel eq "all" and $config->project
!ll&&!rl&&r
022097
$sel eq "project" or $sel eq "all"
l!l&&r!l&&!r
03170
MC/DC33%1/3
$sel eq "project" || $sel eq "all" and $config->project
$sel eq "project" $sel eq "all" $config->project
Truth table40%2/5
A or B and C
A= $sel eq "project"B= $sel eq "all"C= $config->project
ABCresult
00X0
1X00
0100
1X11
0111
162 317 my $out = { scopes => [] };
163 317 for my $s (@scopes) {
164 414 my ( $scope, $scope_cfg ) = @$s;
165 414 my $rep = $self->_resolve_scope( $config, $scope_cfg, $scope, $state, $run );
166 391 ▶ unshift @{ $rep->{warnings} }, @{ $targets->{warnings} } if $scope eq 'project';
Branch: 1 branch
BranchTrueFalseTotal
if $scope eq "project" 97 294 391
167 391 push @{ $out->{scopes} }, $rep;
168 }
169 294 return $out;
170 },
171 389 timeout_ms => $self->lock_timeout_ms,
172 );
173 }
174  
175 # Every source a scope references, through explicit entries, wildcards or bundles.
176 5399 ▶sub _scope_sources {
Subroutine _scope_sources: called CC=3 SCAR=11.0
177 5399 my ( $scope_cfg ) = @_;
178 5399 my ( %seen, @out );
179 5399 for my $i ( @{ $scope_cfg->{install} }, @{ $scope_cfg->{wildcards} }, @{ $scope_cfg->{bundles} } ) {
180 6058 ▶ push @out, $i->{source} unless $seen{ $i->{source} }++;
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$i->{"source"}}++ 4765 1293 6058
181 }
182 5399 return @out;
183 }
184  
185 883 ▶sub bundle_label {
Subroutine bundle_label: called CC=1 SCAR=0.0
Pod documented
186 883 my ( $class, $b ) = @_;
187 883 return 'bundle:'.$b->{name}.'@'.$b->{source};
188 }
189  
190 # The configured source serving a bundle entry of another source (spec §15.6): the first, in
191 # config order, whose `git`/`url` identity is $url.
192 602 ▶sub _serving_source {
Subroutine _serving_source: called CC=5 SCAR=16.1
193 602 my ( $config, $scope, $url ) = @_;
194 602 for my $src ( @{ $config->sources_of($scope) } ) {
195 1042 ▶ my $id = $src->{git} // $src->{url};
Condition66%2/3
$src->{"git"} // $src->{"url"}
l!l&&r!l&&!r
4590583
MC/DC50%1/2
$src->{"git"} // $src->{"url"}
$src->{"git"} $src->{"url"}
Truth table66%2/3
A // B
A= $src->{"git"}B= $src->{"url"}
ABresult
1X1
011
000
196 1042 ▶ return $src->{name} if defined $id && same_identity( $id, $url );
Branch: 1 branch
BranchTrueFalseTotal
if defined $id and same_identity($id, $url) 297 745 1042
Condition100%3/3
defined $id and same_identity($id, $url)
!ll&&!rl&&r
583162297
MC/DC100%2/2
defined $id and same_identity($id, $url)
defined $id same_identity($id, $url)
Truth table100%3/3
A and B
A= defined $idB= same_identity($id, $url)
ABresult
0X0
100
111
197 }
198 305 return undef;
199 }
200  
201 # A backend through the run's one resolve of it, under the fetch policy.
202 4880 ▶sub _resolve_backend {
Subroutine _resolve_backend: called CC=4 SCAR=13.9
203 4880 my ( $self, $run, $backend ) = @_;
204 4880 my $key = Skilletor::Backend->identity($backend);
205 4880 ▶ $run->{$key} //= do {
Condition100%3/3
$run->{$key} //= do { my $loc; eval { do { $loc = $self->_fetch($backend); 1 } } ? {"ok", $loc} : {"err", $@} }
l!l&&r!l&&!r
6064150124
MC/DC100%2/2
$run->{$key} //= do { my $loc; eval { do { $loc = $self->_fetch($backend); 1 } } ? {"ok", $loc} : {"err", $@} }
$run->{$key} do { my $loc; eval { do { $loc = $self->_fetch($backend); 1 } } ? {"ok", $loc} : {"err", $@} }
Truth table100%3/3
A //= B
A= $run->{$key}B= do { my $loc; eval { do { $loc = $self->_fetch($backend); 1 } } ? {"ok", $loc} : {"err", $@} }
ABresult
1X1
011
000
206 4274 my $loc;
207 4274 ▶ eval { $loc = $self->_fetch($backend); 1 } ? { ok => $loc } : { err => $@ };
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $loc = $self->_fetch($backend); 1 } } ? : 4070 80 4150
208 };
209 4756 ▶ die $run->{$key}{err} if exists $run->{$key}{err};
Branch: 1 branch
BranchTrueFalseTotal
if exists $run->{$key}{"err"} 80 4676 4756
210 4676 return $run->{$key}{ok};
211 }
212  
213 4274 ▶sub _fetch {
Subroutine _fetch: called CC=6 SCAR=18.0
214 4274 my ( $self, $backend ) = @_;
215 4274 my $src = Skilletor::Backend->make( $backend, $self->cache_root, $self->timeout_ms );
216 4274 my $fetch = $self->fetch;
217 4274 ▶ return $src->resolve if $fetch eq 'always' || $backend->{kind} eq 'local';
Branch: 1 branch
BranchTrueFalseTotal
if $fetch eq "always" or $backend->{"kind"} eq "local" 4155 119 4274
Condition66%2/3
$fetch eq "always" or $backend->{"kind"} eq "local"
l!l&&r!l&&!r
41550119
MC/DC50%1/2
$fetch eq "always" or $backend->{"kind"} eq "local"
$fetch eq "always" $backend->{"kind"} eq "local"
Truth table66%2/3
A or B
A= $fetch eq "always"B= $backend->{"kind"} eq "local"
ABresult
1X1
011
000
218 119 ▶ return $src->cached if $fetch eq 'never';
Branch: 1 branch
BranchTrueFalseTotal
if $fetch eq "never" 77 42 119
219 42 my $loc = eval { $src->cached };
220 40 ▶ return $loc if $loc && $loc->{version} ne 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
if $loc and $loc->{"version"} ne "unknown" 16 24 40
Condition66%2/3
$loc and $loc->{"version"} ne "unknown"
!ll&&!rl&&r
24016
MC/DC50%1/2
$loc and $loc->{"version"} ne "unknown"
$loc $loc->{"version"} ne "unknown"
Truth table66%2/3
A and B
A= $locB= $loc->{"version"} ne "unknown"
ABresult
0X0
100
111
221 24 return $src->resolve;
222 }
223  
224 1418 ▶sub _item_vars {
Subroutine _item_vars: called CC=5 SCAR=16.5
225 1418 my ( @layers ) = @_;
226 1418 my $out = js_ordered();
227 1418 for my $l ( grep { defined } @layers ) {
228 0 ▶ if ( ref $l eq 'ARRAY' ) { $out->{$_} = $l->[$_] for 0 .. $#$l } # { ...array }: by index
Branch: 1 branch
BranchTrueFalseTotal
if (ref $l eq 'ARRAY') { } 0 1973 1973
229 1973 else { $out->{$_} = $l->{$_} for keys %$l }
230 }
231 1418 return $out;
232 }
233  
234 1233 ▶sub _uniq {
Subroutine _uniq: called CC=3 SCAR=11.0
235 1233 my ( %seen, @out );
236 1233 ▶ for (@_) { push @out, $_ unless $seen{$_}++ }
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$_}++ 1235 4 1239
237 1233 return @out;
238 }
239  
240 250 ▶sub _str_eq { defined $_[0] && defined $_[1] && !ref $_[0] && $_[0] eq $_[1] }
Subroutine _str_eq: called CC=4 SCAR=19.1
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] and defined $_[1] and not ref $_[0] and $_[0] eq $_[1] 250 0 250
Condition33%2/6
defined $_[0] and defined $_[1] and not ref $_[0]
!ll&&!rl&&r
00250
defined $_[0] and defined $_[1]
!ll&&!rl&&r
00250
MC/DC0%0/3
defined $_[0] and defined $_[1] and not ref $_[0]
defined $_[0] defined $_[1] not ref $_[0]
Truth table25%1/4
A and B and not(C)
A= defined $_[0]B= defined $_[1]C= not ref $_[0]
ABCresult
0XX0
10X0
1100
1111
241  
242 # `entry.via?.includes(label)`: the array holds exactly the label (read_lock refuses any other `via`).
243 258 ▶sub _via_has {
Subroutine _via_has: called CC=3 SCAR=11.0
244 258 my ( $via, $label ) = @_;
245 258 ▶ return 0 unless ref $via eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $via eq "ARRAY" 20 238 258
246 238 ▶ return ( grep { _str_eq( $_, $label ) } @$via ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({_str_eq($_, $label);} @$via) ? : 238 0 238
247 }
248  
249 411 ▶sub _valid_item_name { $_[0] =~ /\A[A-Za-z0-9._\-]+\z/ ? 1 : 0 }
Subroutine _valid_item_name: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /\A[A-Za-z0-9._\-]+\z/ ? : 411 0 411
250  
251 # Bundle vars of one item from every chain it was reached through (spec §15.3): a key every
252 # setting chain agrees on applies; one set to different values applies from none.
253 411 ▶sub _merge_chain_vars {
Subroutine _merge_chain_vars: called CC=6 SCAR=27.3
254 411 my ( $chains, $source, $conflict ) = @_;
255 411 my ( %values, @order );
256 411 for my $c (@$chains) {
257 236 for my $key ( keys %{ $c->{vars} } ) {
258 0 my $setter = __PACKAGE__->bundle_label( { name => $c->{setters}{$key}, source => $source } );
259 0 ▶ push @order, $key unless $values{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $values{$key} 0 0 0
260 0 push @{ $values{$key} }, { value => $c->{vars}{$key}, setter => $setter };
261 }
262 }
263 411 my $out = js_ordered();
264 411 for my $key (@order) {
265 0 my $list = $values{$key};
266 0 ▶ if ( _uniq( map { js_stringify( $_->{value} ) } @$list ) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_uniq(map({js_stringify($_->{'value'});} @$list)) == 1) { } 0 0 0
267 0 $out->{$key} = $list->[0]{value};
268 }
269 else {
270 0 $conflict->( $key, [ _uniq( map { $_->{setter} } @$list ) ] );
271 }
272 }
273 411 return $out;
274 }
275  
276 # One scope, as the reference's syncScopeRun runs it: without $hooks with `collect` (the items
277 # into the report), with them for a sync (Skilletor::Engine) – `declare` sees each declared item
278 # before its lookup (false: no target gets it, nothing is looked up), `build` each one found,
279 # `keep` the target and type of each one a sync must leave as it is installed. In list context
280 # also what the sync needs of the run: { resolved, resolved_order, catalogs, served, old_lock }.
281 5399 ▶sub _resolve_scope {
Subroutine _resolve_scope: called CC=65 SCAR=50.5
282 5399 my ( $self, $config, $scope_cfg, $scope, $state, $run, $hooks ) = @_;
283 5399 ▶ my $keep_if_locked = $hooks ? $hooks->{keep} : sub { };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$hooks ? : 4985 414 5399
284 5399 my $rep = { scope => $scope, warnings => [], trustRequests => [], items => [], sources => [] };
285 5399 my $warnings = $rep->{warnings};
286 5399 my $target_dir = $self->_target_dir($scope);
287 5399 my $old_lock = read_lock( path_join( $target_dir, 'skilletor.lock.json' ) );
288  
289 # Every needed source, trust checked and resolved against the one chosen backend.
290 5399 my ( %resolved, @resolved_order );
291 4905 ▶ my $set = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
292 4905 my ( $name, $value ) = @_;
293 4905 ▶ push @resolved_order, $name unless exists $resolved{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $resolved{$name} 4905 0 4905
294 4905 $resolved{$name} = $value;
295 5399 };
296 10715 ▶ my $resolve_all = sub {
Subroutine __ANON__: called CC=8 SCAR=21.6
297 # The names not resolved yet, each once, decided up front, as the reference starts them all at once.
298 10715 my %once;
299 10715 ▶ for my $name ( grep { !exists $resolved{$_} && !$once{$_}++ } @_ ) {
Condition33%1/3
exists $resolved{$_} || $once{$_}++
l!l&&r!l&&!r
005034
MC/DC0%0/2
exists $resolved{$_} || $once{$_}++
exists $resolved{$_} $once{$_}++
Truth table33%1/3
A || B
A= exists $resolved{$_}B= $once{$_}++
ABresult
1X1
011
000
300 5029 my $src = $config->source_of( $scope, $name );
301 5029 ▶ unless ($src) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($src) 0 5029 5029
302 0 push @$warnings, 'unknown source: '.$name;
303 0 $set->( $name, undef );
304 0 next;
305 }
306 5029 my $ok = eval {
307 5029 my $backend = Skilletor::Backend->resolve( $src, $self->home );
308 5029 ▶ if ( !$state->is_trusted( $name, $backend ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state->is_trusted($name, $backend)) 149 4880 5029
309 149 push @{ $rep->{trustRequests} }, Skilletor::Backend->trust_request( $name, $backend );
310 149 $set->( $name, undef );
311 149 return 1;
312 }
313 4880 my $loc = $self->_resolve_backend( $run, $backend );
314 # A shared resolve's warning (a fetch that fell back to the cache) is named once.
315 0 ▶ push @$warnings, $loc->{warning} if defined $loc->{warning} && !grep { $_ eq $loc->{warning} } @$warnings;
Branch: 1 branch
BranchTrueFalseTotal
if defined $loc->{"warning"} and not grep({$_ eq $loc->{"warning"};} @$warnings) 3 4673 4676
Condition66%2/3
defined $loc->{"warning"} and not grep({$_ eq $loc->{"warning"};} @$warnings)
!ll&&!rl&&r
467303
MC/DC50%1/2
defined $loc->{"warning"} and not grep({$_ eq $loc->{"warning"};} @$warnings)
defined $loc->{"warning"} not grep({$_ eq $loc->{"warning"};} @$warnings)
Truth table66%2/3
A and not(B)
A= defined $loc->{"warning"}B= not grep({$_ eq $loc->{"warning"};} @$warnings)
ABresult
0X0
100
111
316 4676 $set->( $name, { dir => $loc->{dir}, version => $loc->{version}, backend => $backend } );
317 4676 1;
318 };
319 4905 ▶ next if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 4825 80 4905
320 80 push @$warnings, 'source '.$name.': '._message($@);
321 80 $set->( $name, undef );
322 }
323 5399 };
324 5399 $resolve_all->( _scope_sources($scope_cfg) );
325  
326 5316 my %catalogs;
327 6528 ▶ my $catalog_of = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
328 6528 my ( $source ) = @_;
329 6528 ▶ return $catalogs{$source} if exists $catalogs{$source};
Branch: 1 branch
BranchTrueFalseTotal
if exists $catalogs{$source} 1689 4839 6528
330 4839 my $r = $resolved{$source};
331 4839 my $cat;
332 4839 ▶ if ($r) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r) 4610 229 4839
333 4610 $cat = eval { Skilletor::Catalog->scan( $r->{dir}, $r->{backend}{path} ) };
334 4610 ▶ push @$warnings, 'source '.$source.': '._message($@) unless $cat;
Branch: 1 branch
BranchTrueFalseTotal
unless $cat 0 4610 4610
335 }
336 4839 return $catalogs{$source} = $cat;
337 5316 };
338  
339 5844 ▶ my $lookup = sub {
Subroutine __ANON__: called CC=6 SCAR=18.2
340 5844 my ( $item ) = @_;
341 5844 my $r = $resolved{ $item->{source} };
342 5844 my $cat = $catalog_of->( $item->{source} );
343 5844 ▶ unless ( $r && $cat ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r and $cat) 229 5615 5844
Condition66%2/3
$r and $cat
!ll&&!rl&&r
22905615
MC/DC50%1/2
$r and $cat
$r $cat
Truth table66%2/3
A and B
A= $rB= $cat
ABresult
0X0
100
111
344 229 $keep_if_locked->( $item->{target}, $item->{type} );
345 229 return undef;
346 }
347 5615 ▶ my ($ci) = grep { $_->{type} eq $item->{type} && $_->{name} eq $item->{name} } @{ $cat->{items} };
Condition100%3/3
$_->{'type'} eq $item->{'type'} && $_->{'name'} eq $item->{'name'}
!ll&&!rl&&r
348928505572
MC/DC100%2/2
$_->{'type'} eq $item->{'type'} && $_->{'name'} eq $item->{'name'}
$_->{'type'} eq $item->{'type'} $_->{'name'} eq $item->{'name'}
Truth table100%3/3
A && B
A= $_->{'type'} eq $item->{'type'}B= $_->{'name'} eq $item->{'name'}
ABresult
0X0
100
111
348 5615 ▶ unless ($ci) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ci) 43 5572 5615
349 43 push @$warnings, 'item not found in source '.$item->{source}.': '.$item->{type}.' '.$item->{name};
350 43 $keep_if_locked->( $item->{target}, $item->{type} );
351 43 return undef;
352 }
353 5572 ▶ if ( defined $ci->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ci->{"error"}) 0 5572 5572
354 # An error of the item itself (spec §4.1): it is not built, what it installed stays.
355 0 push @$warnings, $item->{type}.' '.$item->{name}.'@'.$item->{source}.': '.$ci->{error}.'; an installed copy stays';
356 0 $keep_if_locked->( $item->{target}, $item->{type} );
357 0 return undef;
358 }
359 5572 return { r => $r, cat => $cat, item => $ci };
360 5316 };
361  
362 5866 ▶ my $build_item = sub {
Subroutine __ANON__: called CC=9 SCAR=22.4
363 5866 my ( $item, $extra ) = @_;
364 5866 ▶ if ($hooks) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hooks) 4884 982 5866
365 4884 ▶ $hooks->{declare}->($item) or return;
Branch: 1 branch
BranchTrueFalseTotal
$hooks->{"declare"}->($item) or return 4862 22 4884
366 4862 ▶ my $found = $lookup->($item) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $found = &$lookup($item) or return 4639 223 4862
367 4639 ▶ $hooks->{build}->( $item, $extra // {}, $found, $warnings );
Condition50%1/2
$extra // {}
l!l
46390
MC/DC0%0/1
$extra // {}
$extra
Truth table50%1/2
A
A= $extra
Aresult
11
00
368 4638 return;
369 }
370 982 ▶ my $found = $lookup->($item) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $found = &$lookup($item) or return 933 49 982
371 my $ri = {
372 type => $item->{type},
373 name => $item->{name},
374 source => $item->{source},
375 declaredBy => $extra->{declaredBy} // [],
376 sourceDir => $found->{r}{dir},
377 item => $found->{item},
378 933 ▶ vars => _item_vars( $found->{cat}{meta}{vars}, $extra->{bundleVars}, $scope_cfg->{vars} ),
Condition50%1/2
$extra->{"declaredBy"} // []
l!l
9330
MC/DC0%0/1
$extra->{"declaredBy"} // []
$extra->{"declaredBy"}
Truth table50%1/2
A
A= $extra->{"declaredBy"}
Aresult
11
00
379 };
380 933 ▶ $ri->{via} = $extra->{via} if $extra->{via} && @{ $extra->{via} };
Branch: 1 branch
BranchTrueFalseTotal
if $extra->{"via"} and @{$extra->{"via"};} 0 933 933
Condition33%1/3
$extra->{"via"} and @{$extra->{"via"};}
!ll&&!rl&&r
09330
MC/DC0%0/2
$extra->{"via"} and @{$extra->{"via"};}
$extra->{"via"} @{$extra->{"via"};}
Truth table33%1/3
A and B
A= $extra->{"via"}B= @{$extra->{"via"};}
ABresult
0X0
100
111
381 933 push @{ $rep->{items} }, $ri;
382 5316 };
383  
384 # Wildcards and bundles as offers per target, by name ignoring case (k135). An unresolvable
385 # source (or a bundle that cannot be expanded) offers what it installed before.
386 5316 my ( %offers, @offer_order );
387 5316 ▶ my $target_key = sub { $TYPE_DIR{ $_[0] }.'/'.name_key( $_[1] ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
388 421 ▶ my $offer = sub {
Subroutine __ANON__: called CC=4 SCAR=14.1
389 421 my ( $type, $name, $o ) = @_;
390 421 my $key = $target_key->( $type, $name );
391 421 ▶ unless ( $offers{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($offers{$key}) 417 4 421
392 417 $offers{$key} = { type => $type, offers => [] };
393 417 push @offer_order, $key;
394 }
395 421 my $entry = $offers{$key};
396 421 ▶ push @{ $entry->{offers} }, { %$o, name => $name } unless grep { $_->{from} eq $o->{from} && $_->{name} eq $name } @{ $entry->{offers} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_->{"from"} eq $o->{"from"} and $_->{"name"} eq $name;} @{$$entry{"offers"};} 421 0 421
Condition33%1/3
$_->{'from'} eq $o->{'from'} && $_->{'name'} eq $name
!ll&&!rl&&r
400
MC/DC0%0/2
$_->{'from'} eq $o->{'from'} && $_->{'name'} eq $name
$_->{'from'} eq $o->{'from'} $_->{'name'} eq $name
Truth table33%1/3
A && B
A= $_->{'from'} eq $o->{'from'}B= $_->{'name'} eq $name
ABresult
0X0
100
111
397 5316 };
398 5316 my @locked = map { +{ %{ key_to_type_name($_) }, entry => $old_lock->{$_} } } keys %$old_lock;
399 0 ▶ my $entry_source = sub { my $e = $_[0]{entry}; return js_type($e) eq 'object' ? $e->{source} : undef };
Subroutine __ANON__: not called CC=2 SCAR=14.0
Branch: 1 branch
BranchTrueFalseTotal
js_type($e) eq 'object' ? : 0 0 0
400  
401 5316 for my $w ( @{ $scope_cfg->{wildcards} } ) {
402 123 ▶ if ( my $cat = $catalog_of->( $w->{source} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cat = &$catalog_of($w->{'source'})) { } 123 0 123
403 123 ▶ my @hits = grep { $_->{type} eq $w->{type} && matches_pattern( $w->{pattern}, $_->{name} ) } @{ $cat->{items} };
Condition66%2/3
$_->{'type'} eq $w->{'type'} && matches_pattern($w->{'pattern'}, $_->{'name'})
!ll&&!rl&&r
4190181
MC/DC50%1/2
$_->{'type'} eq $w->{'type'} && matches_pattern($w->{'pattern'}, $_->{'name'})
$_->{'type'} eq $w->{'type'} matches_pattern($w->{'pattern'}, $_->{'name'})
Truth table66%2/3
A && B
A= $_->{'type'} eq $w->{'type'}B= matches_pattern($w->{'pattern'}, $_->{'name'})
ABresult
0X0
100
111
404 # A bare `*` may legitimately match nothing (a source without rules): silent (spec §3).
405 123 ▶ if ( !@hits && $w->{pattern} ne WILDCARD ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @hits and $w->{"pattern"} ne "*") 0 123 123
Condition33%1/3
not @hits and $w->{"pattern"} ne "*"
!ll&&!rl&&r
12300
MC/DC0%0/2
not @hits and $w->{"pattern"} ne "*"
not @hits $w->{"pattern"} ne "*"
Truth table33%1/3
not(A) and B
A= not @hitsB= $w->{"pattern"} ne "*"
ABresult
0X0
100
111
406 0 push @$warnings, $w->{type}.' wildcard '.$w->{raw}.' matches nothing in source '.$w->{source};
407 }
408 123 $offer->( $w->{type}, $_->{name}, { from => $w->{raw}, source => $w->{source}, live => 1 } ) for @hits;
409 }
410 else {
411 0 for my $l (@locked) {
412 0 ▶ next unless _str_eq( $entry_source->($l), $w->{source} ) && $l->{type} eq $w->{type} && matches_pattern( $w->{pattern}, $l->{name} );
Branch: 1 branch
BranchTrueFalseTotal
unless _str_eq(&$entry_source($l), $w->{"source"}) and $l->{"type"} eq $w->{"type"} and matches_pattern($w->{"pattern"}, $l->{"name"}) 0 0 0
Condition0%0/6
_str_eq(&$entry_source($l), $w->{"source"}) and $l->{"type"} eq $w->{"type"} and matches_pattern($w->{"pattern"}, $l->{"name"})
!ll&&!rl&&r
000
_str_eq(&$entry_source($l), $w->{"source"}) and $l->{"type"} eq $w->{"type"}
!ll&&!rl&&r
000
MC/DC0%0/3
_str_eq(&$entry_source($l), $w->{"source"}) and $l->{"type"} eq $w->{"type"} and matches_pattern($w->{"pattern"}, $l->{"name"})
_str_eq(&$entry_source($l), $w->{"source"}) $l->{"type"} eq $w->{"type"} matches_pattern($w->{"pattern"}, $l->{"name"})
Truth table0%0/4
A and B and C
A= _str_eq(&$entry_source($l), $w->{"source"})B= $l->{"type"} eq $w->{"type"}C= matches_pattern($w->{"pattern"}, $l->{"name"})
ABCresult
0XX0
10X0
1100
1111
413 0 $offer->( $l->{type}, $l->{name}, { from => $w->{raw}, source => $w->{source}, live => 0 } );
414 }
415 }
416 }
417  
418 # Bundles: expanded against their own source first; entries of other sources (spec §15.6)
419 # are served by a configured source with the same identity, resolved next.
420 my @expansions = map {
421 333 my $b = $_;
422 333 my $label = __PACKAGE__->bundle_label($b);
423 333 my $cat = $catalog_of->( $b->{source} );
424 333 my $expanded;
425 333 ▶ if ($cat) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cat) 333 0 333
426 333 ▶ unless ( eval { $expanded = expand_bundle( $cat, $b->{name} ); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $expanded = expand_bundle($cat, $b->{"name"}); 1 } }) 0 333 333
427 0 my $err = $@;
428 0 ▶ die $err unless blessed $err && $err->isa('Skilletor::Error::Bundle');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($err) and $err->isa("Skilletor::Error::Bundle") 0 0 0
Condition0%0/3
builtin::blessed($err) and $err->isa("Skilletor::Error::Bundle")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($err) and $err->isa("Skilletor::Error::Bundle")
builtin::blessed($err) $err->isa("Skilletor::Error::Bundle")
Truth table0%0/3
A and B
A= builtin::blessed($err)B= $err->isa("Skilletor::Error::Bundle")
ABresult
0X0
100
111
429 0 push @$warnings, $label.': '.$err->message.'; its installed items are kept';
430 }
431 }
432 333 ▶ my @foreign = map { +{ f => $_, served => _serving_source( $config, $scope, $_->{url} ) } } @{ $expanded ? $expanded->{foreign} : [] };
Branch: 1 branch
BranchTrueFalseTotal
$expanded ? : 333 0 333
433 333 +{ b => $b, label => $label, expanded => $expanded, foreign => \@foreign };
434 5316 } @{ $scope_cfg->{bundles} };
435 5316 ▶ $resolve_all->( map { map { defined $_->{served} ? $_->{served} : () } @{ $_->{foreign} } } @expansions );
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{'served'} ? : 269 52 321
436  
437 5275 for my $x (@expansions) {
438 292 my ( $b, $label, $expanded ) = @{$x}{qw( b label expanded )};
439 52 ▶ my $keep_from_lock = sub {
Subroutine __ANON__: called CC=5 SCAR=20.9
440 52 my ( $match ) = @_;
441 52 for my $l (@locked) {
442 6 ▶ next unless js_type( $l->{entry} ) eq 'object' && _via_has( $l->{entry}{via}, $label ) && $match->($l);
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($l->{"entry"}) eq "object" and _via_has($l->{"entry"}{"via"}, $label) and &$match($l) 6 0 6
Condition33%2/6
js_type($l->{"entry"}) eq "object" and _via_has($l->{"entry"}{"via"}, $label) and &$match($l)
!ll&&!rl&&r
600
js_type($l->{"entry"}) eq "object" and _via_has($l->{"entry"}{"via"}, $label)
!ll&&!rl&&r
060
MC/DC0%0/3
js_type($l->{"entry"}) eq "object" and _via_has($l->{"entry"}{"via"}, $label) and &$match($l)
js_type($l->{"entry"}) eq "object" _via_has($l->{"entry"}{"via"}, $label) &$match($l)
Truth table25%1/4
A and B and C
A= js_type($l->{"entry"}) eq "object"B= _via_has($l->{"entry"}{"via"}, $label)C= &$match($l)
ABCresult
0XX0
10X0
1100
1111
443 0 $offer->( $l->{type}, $l->{name}, { from => $label, source => $l->{entry}{source}, live => 0, via => $label } );
444 }
445 292 };
446 292 ▶ unless ($expanded) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($expanded) 0 292 292
447 0 ▶ $keep_from_lock->( sub { 1 } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
448 0 next;
449 }
450 292 push @$warnings, 'bundle '.$_->{bundle}.'@'.$b->{source}.': '.$_->{message} for @{ $expanded->{warnings} };
451 292 for my $m ( @{ $expanded->{items} } ) {
452 12 $offer->( $m->{type}, $m->{name}, { from => $label, source => $b->{source}, live => 1, via => $label, chains => $m->{chains} } );
453 }
454 292 my @missing; # identities already warned about for this bundle
455 292 for my $fs ( @{ $x->{foreign} } ) {
456 280 my ( $f, $served ) = @{$fs}{qw( f served )};
457 280 ▶ my $cat = defined $served ? $catalog_of->($served) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $served ? : 228 52 280
458 0 ▶ if ( !defined $served && !grep { same_identity( $_, $f->{url} ) } @missing ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $served or grep {same_identity($_, $f->{"url"});} @missing) 52 228 280
Condition66%2/3
defined $served or grep {same_identity($_, $f->{"url"});} @missing
l!l&&r!l&&!r
228052
MC/DC50%1/2
defined $served or grep {same_identity($_, $f->{"url"});} @missing
defined $served grep {same_identity($_, $f->{"url"});} @missing
Truth table66%2/3
A or B
A= defined $servedB= grep {same_identity($_, $f->{"url"});} @missing
ABresult
1X1
011
000
459 52 push @missing, $f->{url};
460 52 push @$warnings, 'bundle '.$b->{name}.'@'.$b->{source}.' needs '.$f->{spec}.' ('.$f->{url}.'): run skilletor install '.$label;
461 }
462 280 ▶ unless ($cat) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cat) 52 228 280
463 # Missing, untrusted or unresolvable: installed copies stay (spec §15.6).
464 $keep_from_lock->(
465 0 ▶ sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
466 0 my ( $l ) = @_;
467 0 my $ls = $l->{entry}{source};
468 return $l->{type} eq $f->{type} && !_str_eq( $ls, $b->{source} ) && matches_pattern( $f->{name}, $l->{name} )
469 0 ▶ && ( !defined $served || _str_eq( $ls, $served ) );
Condition0%0/12
$l->{'type'} eq $f->{'type'} && !_str_eq($ls, $b->{'source'}) && matches_pattern($f->{'name'}, $l->{'name'}) && (!defined($served) || _str_eq($ls, $served))
!ll&&!rl&&r
000
$l->{"type"} eq $f->{"type"} and not _str_eq($ls, $b->{"source"}) and matches_pattern($f->{"name"}, $l->{"name"})
!ll&&!rl&&r
000
$l->{"type"} eq $f->{"type"} and not _str_eq($ls, $b->{"source"})
!ll&&!rl&&r
000
not defined $served or _str_eq($ls, $served)
l!l&&r!l&&!r
000
MC/DC0%0/5
$l->{'type'} eq $f->{'type'} && !_str_eq($ls, $b->{'source'}) && matches_pattern($f->{'name'}, $l->{'name'}) && (!defined($served) || _str_eq($ls, $served))
$l->{"type"} eq $f->{"type"} not _str_eq($ls, $b->{"source"}) matches_pattern($f->{"name"}, $l->{"name"}) not defined $served _str_eq($ls, $served)
Truth table0%0/6
A and not(B) and C && not(D) or E
A= $l->{"type"} eq $f->{"type"}B= not _str_eq($ls, $b->{"source"})C= matches_pattern($f->{"name"}, $l->{"name"})D= not defined $servedE= _str_eq($ls, $served)
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
470 }
471 52 );
472 52 next;
473 }
474 228 my $hits = match_entry( $cat, $f->{type}, $f->{name} );
475 228 ▶ if ( defined( my $miss = entry_miss( $f->{type}, $f->{name}, scalar @$hits ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $miss = entry_miss($f->{"type"}, $f->{"name"}, scalar @$hits))) 0 228 228
476 0 push @$warnings, 'bundle '.$f->{chain}{path}[-1].'@'.$b->{source}.': '.( $miss =~ s/ in the source\z//r ).' in '.$served;
477 }
478 228 for my $ci (@$hits) {
479 228 $offer->( $ci->{type}, $ci->{name}, { from => $label, source => $served, live => 1, via => $label, chains => [ $f->{chain} ] } );
480 }
481 }
482 }
483  
484 # Explicit entries win over every offer; they get no bundle vars (spec §15.3), but record the
485 # same-source bundles that also yield them.
486 5275 my %explicit;
487 5275 for my $item ( @{ $scope_cfg->{install} } ) {
488 5455 my $key = $target_key->( $item->{type}, $item->{name} );
489 5455 $explicit{$key} = { source => $item->{source}, raw => $item->{raw} };
490 4 ▶ my @via = map { $_->{via} } grep { defined $_->{via} && _str_eq( $_->{source}, $item->{source} ) && $_->{name} eq $item->{name} }
Condition66%4/6
defined $_->{'via'} && _str_eq($_->{'source'}, $item->{'source'}) && $_->{'name'} eq $item->{'name'}
!ll&&!rl&&r
404
defined $_->{"via"} and _str_eq($_->{"source"}, $item->{"source"})
!ll&&!rl&&r
404
MC/DC33%1/3
defined $_->{'via'} && _str_eq($_->{'source'}, $item->{'source'}) && $_->{'name'} eq $item->{'name'}
defined $_->{"via"} _str_eq($_->{"source"}, $item->{"source"}) $_->{'name'} eq $item->{'name'}
Truth table50%2/4
A and B && C
A= defined $_->{"via"}B= _str_eq($_->{"source"}, $item->{"source"})C= $_->{'name'} eq $item->{'name'}
ABCresult
0XX0
10X0
1100
1111
491 5455 ▶ @{ $offers{$key} ? $offers{$key}{offers} : [] };
Branch: 1 branch
BranchTrueFalseTotal
$offers{$key} ? : 6 5449 5455
492 5455 $build_item->( $item, { via => \@via, declaredBy => [ $item->{raw} ] } );
493 }
494  
495 # Bundle var conflicts (spec §15.3), reported once per key and pair of bundles.
496 5274 my ( %conflicts, @conflict_order );
497 5274 for my $key (@offer_order) {
498 417 my $o = $offers{$key};
499 417 ▶ if ( my $claim = $explicit{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $claim = $explicit{$key}) 6 411 417
500 6 for my $x ( @{ $o->{offers} } ) {
501 8 ▶ next if _str_eq( $x->{source}, $claim->{source} );
Branch: 1 branch
BranchTrueFalseTotal
if _str_eq($x->{"source"}, $claim->{"source"}) 8 0 8
502 0 push @$warnings, $o->{type}.' "'.$x->{name}.'" from '.$x->{from}.' ignored: explicitly declared as '.$claim->{raw};
503 }
504 6 next;
505 }
506 411 my @names = _uniq( map { $_->{name} } @{ $o->{offers} } );
507 411 ▶ if ( _uniq( map { $_->{source} // '' } @{ $o->{offers} } ) > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_uniq(map({$_->{"source"} // "";} @{$$o{"offers"};})) > 1) 0 411 411
Condition50%1/2
$_->{"source"} // ""
l!l
4130
MC/DC0%0/1
$_->{"source"} // ""
$_->{"source"}
Truth table50%1/2
A
A= $_->{"source"}
Aresult
11
00
508 0 my @from = _uniq( map { $_->{from} } @{ $o->{offers} } );
509 0 push @$warnings, $o->{type}.' '.join( ' and ', map { '"'.$_.'"' } @names ).' offered by '.join( ' and ', @from ).'; skipped';
510 0 $keep_if_locked->( $TYPE_DIR{ $o->{type} }.'/'.$_, $o->{type} ) for @names;
511 0 next;
512 }
513 # One source: installed once, however many of its wildcards and bundles yield it.
514 411 my $source = $o->{offers}[0]{source};
515 411 for my $name (@names) {
516 411 my @mine = grep { $_->{name} eq $name } @{ $o->{offers} };
517 411 my @live = grep { $_->{live} } @mine;
518 411 ▶ unless (@live) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@live) 0 411 411
519 0 $keep_if_locked->( $TYPE_DIR{ $o->{type} }.'/'.$name, $o->{type} );
520 0 next;
521 }
522 411 ▶ unless ( _valid_item_name($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_valid_item_name($name)) 0 411 411
523 0 push @$warnings, $o->{type}.' "'.$name.'" from '.$live[0]{from}.' skipped: invalid item name';
524 0 next;
525 }
526 411 ▶ my @via = map { defined $_->{via} ? $_->{via} : () } @mine;
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{'via'} ? : 236 177 413
527 411 ▶ my @chains = map { @{ $_->{chains} // [] } } @live;
Condition100%2/2
$_->{"chains"} // []
l!l
236177
MC/DC100%1/1
$_->{"chains"} // []
$_->{"chains"}
Truth table100%2/2
A
A= $_->{"chains"}
Aresult
11
00
528 my $bundle_vars = _merge_chain_vars(
529 \@chains, $source,
530 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
531 0 my ( $var, $setters ) = @_;
532 0 my $k = '"'.$var.'": '.join( ' and ', @$setters );
533 0 ▶ push @conflict_order, $k unless $conflicts{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless $conflicts{$k} 0 0 0
534 0 push @{ $conflicts{$k} }, $o->{type}.' '.$name;
535 }
536 411 );
537 $build_item->(
538 { type => $o->{type}, name => $name, source => $source, target => $TYPE_DIR{ $o->{type} }.'/'.$name },
539 411 { bundleVars => $bundle_vars, via => \@via, declaredBy => [ _uniq( map { $_->{from} } @live ) ] },
540 );
541 }
542 }
543 5274 for my $k (@conflict_order) {
544 0 push @$warnings, 'bundle vars conflict on '.$k.' set different values; neither applies to '.join( ', ', @{ $conflicts{$k} } );
545 }
546  
547 5274 ▶ if ($hooks) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hooks) 4883 391 5274
548 my $run_info = {
549 resolved => \%resolved,
550 resolved_order => \@resolved_order,
551 catalogs => \%catalogs,
552 old_lock => $old_lock,
553 # Per bundle label, the other sources its entries are served by (spec §15.6).
554 4883 ▶ served => { map { ( $_->{label} => [ map { defined $_->{served} ? $_->{served} : () } @{ $_->{foreign} } ] ) } @expansions },
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{'served'} ? : 228 52 280
555 };
556 4883 undef $_ for $resolve_all, $catalog_of, $lookup, $build_item, $offer, $set;
557 4883 ▶ return wantarray ? ( $rep, $run_info ) : $rep;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4883 0 4883
558 }
559  
560 # The sources the scope needed, and what became of them.
561 391 for my $name (@resolved_order) {
562 367 my $r = $resolved{$name};
563 367 my $src = $config->source_of( $scope, $name );
564 367 ▶ my $backend = $r ? $r->{backend} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 318 49 367
565 367 ▶ $backend = eval { Skilletor::Backend->resolve( $src, $self->home ) } if !$backend && $src;
Branch: 1 branch
BranchTrueFalseTotal
if not $backend and $src 49 318 367
Condition66%2/3
not $backend and $src
!ll&&!rl&&r
318049
MC/DC50%1/2
not $backend and $src
not $backend $src
Truth table66%2/3
not(A) and B
A= not $backendB= $src
ABresult
0X0
100
111
566 367 my $info = { name => $name, state => 'failed' };
567 0 ▶ if ( !$src ) { $info->{state} = 'unknown' }
Branch: 3 branches
BranchTrueFalseTotal
if (not $src) { } 0 367 367
elsif ($r and not exists $catalogs{$name} && !defined($catalogs{$name})) { } 318 49 367
elsif (not $r and grep {$_->{'name'} eq $name;} @{$$rep{'trustRequests'};}) { } 0 49 49
568 318 ▶ elsif ( $r && !( exists $catalogs{$name} && !defined $catalogs{$name} ) ) { $info->{state} = 'resolved' }
Condition50%3/6
$r and not exists $catalogs{$name} && !defined($catalogs{$name})
!ll&&!rl&&r
490318
exists $catalogs{$name} && !defined($catalogs{$name})
!ll&&!rl&&r
03180
MC/DC33%1/3
$r and not exists $catalogs{$name} && !defined($catalogs{$name})
$r exists $catalogs{$name} !defined($catalogs{$name})
Truth table50%2/4
A and not(B && not(C))
A= $rB= exists $catalogs{$name}C= !defined($catalogs{$name})
ABCresult
0XX0
1110
10X1
1101
569 0 ▶ elsif ( !$r && grep { $_->{name} eq $name } @{ $rep->{trustRequests} } ) { $info->{state} = 'untrusted' }
Condition33%1/3
not $r and grep {$_->{"name"} eq $name;} @{$$rep{"trustRequests"};}
!ll&&!rl&&r
0490
MC/DC0%0/2
not $r and grep {$_->{"name"} eq $name;} @{$$rep{"trustRequests"};}
not $r grep {$_->{"name"} eq $name;} @{$$rep{"trustRequests"};}
Truth table33%1/3
not(A) and B
A= not $rB= grep {$_->{"name"} eq $name;} @{$$rep{"trustRequests"};}
ABresult
0X0
100
111
570 367 ▶ if ($backend) {
Branch: 1 branch
BranchTrueFalseTotal
if ($backend) 367 0 367
571 367 $info->{backend} = $backend;
572 367 ▶ $info->{cache} = cache_name( git_identity( $backend->{address}, $backend->{ref} ) ) if $backend->{kind} eq 'git';
Branch: 1 branch
BranchTrueFalseTotal
if $backend->{"kind"} eq "git" 116 251 367
573 367 ▶ $info->{cache} = cache_name( $backend->{address} ) if $backend->{kind} eq 'url';
Branch: 1 branch
BranchTrueFalseTotal
if $backend->{"kind"} eq "url" 1 366 367
574 }
575 367 ▶ if ($r) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r) 318 49 367
576 318 $info->{dir} = $r->{dir};
577 318 $info->{version} = $r->{version};
578 }
579 367 push @{ $rep->{sources} }, $info;
580 }
581 # The closures above refer to each other through these; break the cycles.
582 391 undef $_ for $resolve_all, $catalog_of, $lookup, $build_item, $offer, $set;
583 391 return $rep;
584 }
585  
586 400 1;
587  
588 __END__
« /usr/local/lib/perl5/site_perl/5.44.0/Sub/Quote.pm ↑ Summary /usr/local/lib/perl5/site_perl/5.44.0/x86_64-linux/Class/XSAccessor.pm »