Skilletor/Config.pm

filter: Statementstmt 98.2% 513 / 522 Branchbran 84.9% 260 / 306 Conditioncond 72.0% 108 / 150 MC/DCmcdc 53.4% 47 / 88 Subroutinesub 98.6% 75 / 76 Podpod 96.3% 26 / 27 totaltotal 88.0% 1029 / 1169 CC 232 SCAR 22.9
CC
232
Cov
90%
_build__loaded
30.2
source_fields
15.1
_read_error
14.9
CRAP 9.9
« Skilletor/Bundles.pm ↑ Summary Skilletor/Catalog.pm »
1 package Skilletor::Config;
2 # ABSTRACT: Load, merge and validate the user, project and local skilletor config
3  
4 37 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 37 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 37 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 37 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 37 ▶use Skilletor::Entry qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
9 HARNESSES WILDCARD SOURCE_NAME_RULE INSTALL_KEYS INSTALL_KEY_OF BUNDLES_KEY ITEM_TYPES
10 name_key is_source_name is_pattern parse_entry parse_bundle_entry seen_key
11 37 );
12 37 ▶use Skilletor::Error::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 37 ▶use Skilletor::Error::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 37 ▶use Skilletor::FSUtil qw( read_text inner_segments path_join write_text );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 37 ▶use Skilletor::JSON qw( js_parse js_stringify js_ordered js_type );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 37 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 37 our $VERSION = '0.001';
19  
20 37 my @ALLOWED_KEYS = qw( sources install vars gitignore claudeSettings checkInterval targets );
21 37 my %ALLOWED_KEY = map { $_ => 1 } @ALLOWED_KEYS;
22 37 my %SOURCE_KEY = map { $_ => 1 } qw( git ref url local path );
23 37 my @BACKEND_KINDS = qw( git url local );
24 # The order the reference writes a source definition's fields in (commands.ts pickDef).
25 37 my @SOURCE_FIELD_ORDER = qw( git ref url local path );
26 # What `git check-ref-format` forbids character by character.
27 37 my $NOT_IN_REF = qr/[\x00-\x20\x7f~^:?*[\\]|\.\.|\@\{/;
28  
29 37 has home => (
30 is => 'ro',
31 required => 1,
32 );
33  
34 # `CLAUDE_CONFIG_DIR` (k145): the user config's dir; unset or empty means `<home>/.claude`.
35 37 has claude_config_dir => (
36 is => 'ro',
37 );
38  
39 37 has project_dir => (
40 is => 'ro',
41 );
42  
43 37 has unchecked => (
44 is => 'ro',
45 );
46  
47 37 has user_path => (
48 is => 'lazy',
49 init_arg => undef,
50 );
51  
52 536 ▶sub _build_user_path {
Subroutine _build_user_path: called CC=3 SCAR=11.0
53 536 my ( $self ) = @_;
54 536 my $cd = $self->claude_config_dir;
55 536 ▶ return path_join( ( defined $cd && length $cd ) ? $cd : path_join( $self->home, '.claude' ), 'skilletor.json' );
Branch: 1 branch
BranchTrueFalseTotal
defined $cd && length $cd ? : 2 534 536
Condition66%2/3
defined $cd and length $cd
!ll&&!rl&&r
53402
MC/DC50%1/2
defined $cd and length $cd
defined $cd length $cd
Truth table66%2/3
A and B
A= defined $cdB= length $cd
ABresult
0X0
100
111
56 }
57  
58 37 has project_path => (
59 is => 'lazy',
60 init_arg => undef,
61 );
62  
63 374 ▶sub _build_project_path {
Subroutine _build_project_path: called CC=2 SCAR=6.9
64 374 my ( $self ) = @_;
65 374 ▶ return defined $self->project_dir ? path_join( $self->project_dir, '.claude', 'skilletor.json' ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->project_dir ? : 373 1 374
66 }
67  
68 37 has local_path => (
69 is => 'lazy',
70 init_arg => undef,
71 );
72  
73 373 ▶sub _build_local_path {
Subroutine _build_local_path: called CC=2 SCAR=7.2
74 373 my ( $self ) = @_;
75 373 ▶ return defined $self->project_dir ? path_join( $self->project_dir, '.claude', 'skilletor.local.json' ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->project_dir ? : 373 0 373
76 }
77  
78 37 has _loaded => (
79 is => 'lazy',
80 init_arg => undef,
81 );
82  
83 536 ▶sub BUILD { $_[0]->_loaded }
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
84  
85 384 ▶sub load {
Subroutine load: called CC=1 SCAR=0.0
Pod documented
86 384 my ( $class, %args ) = @_;
87 384 return $class->new(%args);
88 }
89  
90 538 ▶sub has_project { defined $_[0]->project_dir ? 1 : 0 }
Subroutine has_project: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]->project_dir ? : 374 164 538
91 1 ▶sub check_interval { $_[0]->_loaded->{checkInterval} }
Subroutine check_interval: called CC=1 SCAR=0.0
Pod documented
92 634 ▶sub user { $_[0]->_loaded->{user} }
Subroutine user: called CC=1 SCAR=0.0
Pod documented
93 891 ▶sub project { $_[0]->_loaded->{project} }
Subroutine project: called CC=1 SCAR=0.0
Pod documented
94 1 ▶sub sources { [ _map_values( $_[0]->_loaded->{sources} ) ] }
Subroutine sources: called CC=1 SCAR=0.0
Pod documented
95 1 ▶sub source_names { _map_names( $_[0]->_loaded->{sources} ) }
Subroutine source_names: called CC=1 SCAR=0.0
Pod documented
96 0 ▶sub user_sources { [ _map_values( $_[0]->_loaded->{userSources} ) ] }
Subroutine user_sources: not called CC=1 SCAR=6.9
Pod documented
97 1 ▶sub user_source_names { _map_names( $_[0]->_loaded->{userSources} ) }
Subroutine user_source_names: called CC=1 SCAR=0.0
Pod documented
98  
99 196 ▶sub source {
Subroutine source: called CC=1 SCAR=0.0
Pod documented
100 196 my ( $self, $name ) = @_;
101 196 return _map_get( $self->_loaded->{sources}, $name );
102 }
103  
104 472 ▶sub user_source {
Subroutine user_source: called CC=1 SCAR=0.0
Pod documented
105 472 my ( $self, $name ) = @_;
106 472 return _map_get( $self->_loaded->{userSources}, $name );
107 }
108  
109 # The sources a scope resolves against: the user config's alone for the user scope, the
110 # merged map for the project scope (spec ยง3).
111 1 ▶sub sources_of {
Subroutine sources_of: called CC=2 SCAR=7.2
Pod documented
112 1 my ( $self, $scope ) = @_;
113 1 ▶ return $scope eq 'user' ? $self->user_sources : $self->sources;
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'user' ? : 0 1 1
114 }
115  
116 663 ▶sub source_of {
Subroutine source_of: called CC=2 SCAR=6.9
Pod documented
117 663 my ( $self, $scope, $name ) = @_;
118 663 ▶ return $scope eq 'user' ? $self->user_source($name) : $self->source($name);
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'user' ? : 471 192 663
119 }
120  
121 1 ▶sub scope {
Subroutine scope: called CC=2 SCAR=7.2
Pod documented
122 1 my ( $self, $scope ) = @_;
123 1 ▶ return $scope eq 'user' ? $self->user : $self->project;
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'user' ? : 0 1 1
124 }
125  
126 # The reference's LoadedConfig as one JSON-shaped value; its Maps as objects in Map order.
127 46 ▶sub to_data {
Subroutine to_data: called CC=2 SCAR=6.9
Pod documented
128 46 my ( $self ) = @_;
129 46 my $l = $self->_loaded;
130 92 ▶ my $map = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
131 92 my ( $m ) = @_;
132 # A Map keeps insertion order; an object would move index keys first. Pairs keep it.
133 92 return [ map { [ $_, _map_get( $m, $_ ) ] } _map_names($m) ];
134 46 };
135 return {
136 sources => $map->( $l->{sources} ),
137 checkInterval => $l->{checkInterval},
138 user => $l->{user},
139 ( $l->{project} ? ( project => $l->{project} ) : () ),
140 46 ▶ userSources => $map->( $l->{userSources} ),
Branch: 1 branch
BranchTrueFalseTotal
$l->{'project'} ? : 45 1 46
141 };
142 }
143  
144 #### Insertion-ordered maps (JavaScript Map) ###########################
145  
146 1794 ▶sub _map_new { { order => [], by => {} } }
Subroutine _map_new: called CC=1 SCAR=0.0
147 1281 ▶sub _map_has { exists $_[0]{by}{ $_[1] } }
Subroutine _map_has: called CC=1 SCAR=0.0
148 2809 ▶sub _map_get { $_[0]{by}{ $_[1] } }
Subroutine _map_get: called CC=1 SCAR=0.0
149 2284 ▶sub _map_names { @{ $_[0]{order} } }
Subroutine _map_names: called CC=1 SCAR=0.0
150 1 ▶sub _map_values { map { $_[0]{by}{$_} } @{ $_[0]{order} } }
Subroutine _map_values: called CC=1 SCAR=0.0
151  
152 1130 ▶sub _map_set {
Subroutine _map_set: called CC=2 SCAR=6.9
153 1130 my ( $m, $k, $v ) = @_;
154 1130 ▶ push @{ $m->{order} }, $k unless exists $m->{by}{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $m->{"by"}{$k} 1109 21 1130
155 1130 $m->{by}{$k} = $v;
156 }
157  
158 4 ▶sub _map_delete {
Subroutine _map_delete: called CC=2 SCAR=7.0
159 4 my ( $m, $k ) = @_;
160 4 ▶ return unless exists $m->{by}{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $m->{"by"}{$k} 0 4 4
161 4 delete $m->{by}{$k};
162 4 $m->{order} = [ grep { $_ ne $k } @{ $m->{order} } ];
163 }
164  
165 #### Reading ###########################################################
166  
167 148 ▶sub _fail { Skilletor::Error::Config->throw( $_[1] ) }
Subroutine _fail: called CC=1 SCAR=0.0
168  
169 # Node's message for a failed readFileSync, for the reasons a config file meets.
170 1 ▶sub _read_error {
Subroutine _read_error: called CC=5 SCAR=27.0
171 1 my ( $self, $file, $errno ) = @_;
172 1 local $! = $errno;
173 1 ▶ return 'EACCES: permission denied, open \''.$file.'\'' if $!{EACCES};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"EACCES"} 1 0 1
174 0 ▶ return 'ENOTDIR: not a directory, open \''.$file.'\'' if $!{ENOTDIR};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"ENOTDIR"} 0 0 0
175 0 ▶ return 'EISDIR: illegal operation on a directory, read' if $!{EISDIR};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"EISDIR"} 0 0 0
176 0 ▶ return 'ELOOP: too many symbolic links encountered, open \''.$file.'\'' if $!{ELOOP};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"ELOOP"} 0 0 0
177 0 return "$!";
178 }
179  
180 # One config file: parsed and its top-level keys checked; a missing file is an empty object.
181 1173 ▶sub _read_config_file {
Subroutine _read_config_file: called CC=11 SCAR=24.1
182 1173 my ( $self, $file ) = @_;
183 1173 my $text;
184 1173 ▶ if ( -d $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $file) 1 1172 1173
185 1 $self->_fail( $file.': cannot read config (EISDIR: illegal operation on a directory, read)' );
186 }
187 1172 ▶ if ( open my $fh, '<:raw', $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, '<:raw', $file) { } 694 478 1172
188 694 local $/;
189 694 my $bytes = <$fh>;
190 694 close $fh;
191 694 ▶ $text = Skilletor::FSUtil::decode_utf8_lossy( $bytes // '' );
Condition50%1/2
$bytes // ""
l!l
6940
MC/DC0%0/1
$bytes // ""
$bytes
Truth table50%1/2
A
A= $bytes
Aresult
11
00
192 }
193 else {
194 478 ▶ return js_ordered() if $!{ENOENT};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"ENOENT"} 477 1 478
195 1 $self->_fail( $file.': cannot read config ('.$self->_read_error( $file, 0 + $! ).')' );
196 }
197 694 my $value;
198 694 ▶ unless ( eval { $value = js_parse($text); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $value = js_parse($text); 1 } }) 53 641 694
199 53 my $err = $@;
200 53 ▶ $self->_fail( $file.': invalid JSON ('.( ref $err && $err->can('message') ? $err->message : "$err" ).')' );
Branch: 1 branch
BranchTrueFalseTotal
ref $err && $err->can('message') ? : 53 0 53
Condition33%1/3
ref $err and $err->can("message")
!ll&&!rl&&r
0053
MC/DC0%0/2
ref $err and $err->can("message")
ref $err $err->can("message")
Truth table33%1/3
A and B
A= ref $errB= $err->can("message")
ABresult
0X0
100
111
201 }
202 641 ▶ $self->_fail( $file.': top level must be a JSON object' ) unless js_type($value) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($value) eq "object" 3 638 641
203 638 for my $key ( keys %$value ) {
204 1370 ▶ next if $ALLOWED_KEY{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $ALLOWED_KEY{$key} 1368 2 1370
205 2 $self->_fail( $file.': unknown key "'.$key.'" (allowed: '.join( ', ', @ALLOWED_KEYS ).')' );
206 }
207 636 return $value;
208 }
209  
210 3021 ▶sub _as_object {
Subroutine _as_object: called CC=3 SCAR=11.0
211 3021 my ( $self, $obj, $key, $file, $where ) = @_;
212 3021 ▶ return js_ordered() unless exists $obj->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $obj->{$key} 1602 1419 3021
213 1419 my $value = $obj->{$key};
214 1419 ▶ $self->_fail( $file.': '.$where.' must be an object' ) unless js_type($value) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($value) eq "object" 6 1413 1419
215 1413 return $value;
216 }
217  
218 966 ▶sub _has_backend {
Subroutine _has_backend: called CC=4 SCAR=13.9
219 966 my ( $src ) = @_;
220 966 ▶ return ( exists $src->{git} || exists $src->{url} || exists $src->{local} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $src->{'git'} || exists $src->{'url'} || exists $src->{'local'} ? : 951 15 966
Condition100%6/6
exists $src->{"git"} or exists $src->{"url"} or exists $src->{"local"}
l!l&&r!l&&!r
44450715
exists $src->{"git"} or exists $src->{"url"}
l!l&&r!l&&!r
4395522
MC/DC100%3/3
exists $src->{"git"} or exists $src->{"url"} or exists $src->{"local"}
exists $src->{"git"} exists $src->{"url"} exists $src->{"local"}
Truth table100%4/4
A or B or C
A= exists $src->{"git"}B= exists $src->{"url"}C= exists $src->{"local"}
ABCresult
1XX1
01X1
0011
0000
221 }
222  
223 1033 ▶sub _parse_sources {
Subroutine _parse_sources: called CC=7 SCAR=19.5
224 1033 my ( $self, $obj, $file, $origin, $unchecked ) = @_;
225 1033 my $sources = _map_new();
226 1033 my $raw = $self->_as_object( $obj, 'sources', $file, 'sources' );
227 1031 for my $name ( keys %$raw ) {
228 598 ▶ if ( defined $unchecked && $name eq $unchecked ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $unchecked and $name eq $unchecked) 4 594 598
Condition100%3/3
defined $unchecked and $name eq $unchecked
!ll&&!rl&&r
59314
MC/DC100%2/2
defined $unchecked and $name eq $unchecked
defined $unchecked $name eq $unchecked
Truth table100%3/3
A and B
A= defined $uncheckedB= $name eq $unchecked
ABresult
0X0
100
111
229 4 _map_set( $sources, $name, { name => $name, origins => {} } );
230 4 next;
231 }
232 594 ▶ unless ( is_source_name($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_source_name($name)) 3 591 594
233 3 $self->_fail( $file.': source name '.js_stringify($name).' is not valid ('.SOURCE_NAME_RULE.')' );
234 }
235 # A backend may come from another file of the merge: the loader checks that.
236 591 my $fields = $self->source_fields( $raw->{$name}, $file.': sources.'.$name, 0 );
237 561 my $src = { name => $name, origins => {}, %$fields };
238 561 for my $kind (@BACKEND_KINDS) {
239 1683 ▶ $src->{origins}{$kind} = $origin if exists $src->{$kind};
Branch: 1 branch
BranchTrueFalseTotal
if exists $src->{$kind} 545 1138 1683
240 }
241 561 _map_set( $sources, $name, $src );
242 }
243 998 return $sources;
244 }
245  
246 608 ▶sub source_fields {
Subroutine source_fields: called CC=15 SCAR=27.1
Pod documented
247 608 my ( $self, $def, $at, $needs_backend ) = @_;
248 608 ▶ $needs_backend //= 1;
Condition100%2/2
$needs_backend //= 1
l!l
59117
MC/DC100%1/1
$needs_backend //= 1
$needs_backend
Truth table100%2/2
A
A= $needs_backend
Aresult
11
00
249 608 ▶ $self->_fail( $at.' must be an object' ) unless js_type($def) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($def) eq "object" 1 607 608
250 607 for my $key ( keys %$def ) {
251 645 ▶ $self->_fail( $at.': unknown key "'.$key.'"' ) unless $SOURCE_KEY{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $SOURCE_KEY{$key} 1 644 645
252 }
253 606 my %src;
254 606 ▶ $src{git} = $self->_git_field( $self->_string_field( $def->{git}, 'git', $at ), 'git', $at ) if exists $def->{git};
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"git"} 264 342 606
255 # "ref": null is no ref: in a file of the merge it unsets a lower file's.
256 602 ▶ if ( exists $def->{ref} && defined $def->{ref} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"ref"} and defined $def->{"ref"}) 30 572 602
Condition100%3/3
exists $def->{"ref"} and defined $def->{"ref"}
!ll&&!rl&&r
568430
MC/DC100%2/2
exists $def->{"ref"} and defined $def->{"ref"}
exists $def->{"ref"} defined $def->{"ref"}
Truth table100%3/3
A and B
A= exists $def->{"ref"}B= defined $def->{"ref"}
ABresult
0X0
100
111
257 30 $src{ref} = $self->_git_field( $self->_string_field( $def->{ref}, 'ref', $at ), 'ref', $at );
258 }
259 595 ▶ $src{local} = $self->_string_field( $def->{local}, 'local', $at ) if exists $def->{local};
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"local"} 318 277 595
260 593 ▶ if ( exists $def->{url} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"url"}) 8 585 593
261 8 my $url = $def->{url};
262 8 ▶ unless ( js_type($url) eq 'string' && $url =~ m{\Ahttps://} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (js_type($url) eq "string" and $url =~ m[\Ahttps://]) 4 4 8
Condition100%3/3
js_type($url) eq "string" and $url =~ m[\Ahttps://]
!ll&&!rl&&r
224
MC/DC100%2/2
js_type($url) eq "string" and $url =~ m[\Ahttps://]
js_type($url) eq "string" $url =~ m[\Ahttps://]
Truth table100%3/3
A and B
A= js_type($url) eq "string"B= $url =~ m[\Ahttps://]
ABresult
0X0
100
111
263 4 $self->_fail( $at.'.url '.js_stringify($url).' must be an https:// URL' );
264 }
265 4 $src{url} = $url;
266 }
267 589 ▶ $src{path} = $self->_path_field( $def->{path}, $at ) if exists $def->{path};
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"path"} 19 570 589
268 577 ▶ if ( $needs_backend && !_has_backend( \%src ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($needs_backend and not _has_backend(\%src)) 0 577 577
Condition66%2/3
$needs_backend and not _has_backend(\%src)
!ll&&!rl&&r
561160
MC/DC0%0/2
$needs_backend and not _has_backend(\%src)
$needs_backend not _has_backend(\%src)
Truth table66%2/3
A and not(B)
A= $needs_backendB= not _has_backend(\%src)
ABresult
0X0
100
111
269 0 $self->_fail( $at.' needs one of "git", "url" or "local"' );
270 }
271 577 return \%src;
272 }
273  
274 612 ▶sub _string_field {
Subroutine _string_field: called CC=4 SCAR=13.9
275 612 my ( $self, $value, $key, $at ) = @_;
276 612 my $where = $at.'.'.$key.' '.js_stringify($value);
277 612 ▶ $self->_fail( $where.' must be a string' ) unless js_type($value) eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($value) eq "string" 4 608 612
278 608 ▶ if ( $value eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq "") 3 605 608
279 3 ▶ $self->_fail( $where.' must not be empty'.( $key eq 'ref' ? ' (omit "ref" for the remote\'s HEAD)' : '' ) );
Branch: 1 branch
BranchTrueFalseTotal
$key eq 'ref' ? : 1 2 3
280 }
281 605 return $value;
282 }
283  
284 289 ▶sub _git_field {
Subroutine _git_field: called CC=4 SCAR=13.9
285 289 my ( $self, $value, $key, $at ) = @_;
286 289 my $where = $at.'.'.$key.' '.js_stringify($value);
287 289 ▶ $self->_fail( $where.' must not start with "-" (git would read it as an option)' ) if $value =~ /\A-/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /\A-/ 2 287 289
288 287 ▶ if ( $key eq 'ref' && $value =~ $NOT_IN_REF ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "ref" and $value =~ /$NOT_IN_REF/) 4 283 287
Condition100%3/3
$key eq "ref" and $value =~ /$NOT_IN_REF/
!ll&&!rl&&r
260234
MC/DC100%2/2
$key eq "ref" and $value =~ /$NOT_IN_REF/
$key eq "ref" $value =~ /$NOT_IN_REF/
Truth table100%3/3
A and B
A= $key eq "ref"B= $value =~ /$NOT_IN_REF/
ABresult
0X0
100
111
289 4 $self->_fail( $where.' is not a git ref name (no whitespace, control characters, ~ ^ : ? * [ \\, ".." or "@{")' );
290 }
291 283 return $value;
292 }
293  
294 19 ▶sub _path_field {
Subroutine _path_field: called CC=13 SCAR=25.6
295 19 my ( $self, $value, $at ) = @_;
296 19 my $where = $at.'.path';
297 19 my $omit = ' (omit "path" for the default layout)';
298 19 my $type = js_type($value);
299 19 ▶ unless ( $type eq 'string' || $type eq 'array' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type eq "string" or $type eq "array") 2 17 19
Condition100%3/3
$type eq "string" or $type eq "array"
l!l&&r!l&&!r
892
MC/DC100%2/2
$type eq "string" or $type eq "array"
$type eq "string" $type eq "array"
Truth table100%3/3
A or B
A= $type eq "string"B= $type eq "array"
ABresult
1X1
011
000
300 2 $self->_fail( $where.' '.js_stringify($value).' must be a string or an array of strings' );
301 }
302 17 my $is_array = $type eq 'array';
303 17 ▶ if ( $is_array ? !@$value : $value eq '' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($is_array ? !@$value : $value eq "") 2 15 17
$is_array ? : 9 8 17
304 2 $self->_fail( $where.' '.js_stringify($value).' must not be empty'.$omit );
305 }
306 15 ▶ my @list = $is_array ? @$value : ($value);
Branch: 1 branch
BranchTrueFalseTotal
$is_array ? : 8 7 15
307 15 for my $i ( 0 .. $#list ) {
308 20 my $entry = $list[$i];
309 20 ▶ my $w = $where.( $is_array ? '['.$i.']' : '' ).' '.js_stringify($entry);
Branch: 1 branch
BranchTrueFalseTotal
$is_array ? : 13 7 20
310 20 ▶ $self->_fail( $w.' must be a string' ) unless js_type($entry) eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($entry) eq "string" 1 19 20
311 19 ▶ $self->_fail( $w.' must not be empty' ) if $entry eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $entry eq "" 1 18 19
312 18 my $segments = inner_segments($entry);
313 18 ▶ next if ref $segments;
Branch: 1 branch
BranchTrueFalseTotal
if ref $segments 12 6 18
314 6 ▶ $self->_fail( $w.' must not be absolute (it is relative to the source root)' ) if $segments eq 'absolute';
Branch: 1 branch
BranchTrueFalseTotal
if $segments eq "absolute" 2 4 6
315 4 ▶ $self->_fail( $w.' must not contain ".."' ) if $segments eq 'dotdot';
Branch: 1 branch
BranchTrueFalseTotal
if $segments eq "dotdot" 2 2 4
316 2 $self->_fail( $w.' must not be the source root (name the directories its skills lie in)' );
317 }
318 7 return $value;
319 }
320  
321 # Merge incoming source fields over base, field by field: each backend field keeps the origin
322 # of its file; ref and path are replaced whole; unset_ref (the file wrote "ref": null) drops
323 # the ref base had.
324 565 ▶sub _merge_source {
Subroutine _merge_source: called CC=8 SCAR=20.8
325 565 my ( $base, $incoming, $unset_ref ) = @_;
326 565 ▶ my %merged = %{ $base // $incoming };
Condition66%2/3
$base // $incoming
l!l&&r!l&&!r
215440
MC/DC0%0/2
$base // $incoming
$base $incoming
Truth table66%2/3
A // B
A= $baseB= $incoming
ABresult
1X1
011
000
327 565 ▶ $merged{origins} = { %{ $base ? $base->{origins} : {} } };
Branch: 1 branch
BranchTrueFalseTotal
$base ? : 21 544 565
328 565 ▶ if ( exists $incoming->{ref} ) { $merged{ref} = $incoming->{ref} }
Branch: 2 branches
BranchTrueFalseTotal
if (exists $incoming->{'ref'}) { } 23 542 565
elsif ($unset_ref) { } 4 538 542
329 4 elsif ($unset_ref) { delete $merged{ref} }
330 565 ▶ $merged{path} = $incoming->{path} if exists $incoming->{path};
Branch: 1 branch
BranchTrueFalseTotal
if exists $incoming->{"path"} 7 558 565
331 565 for my $kind (@BACKEND_KINDS) {
332 1695 ▶ next unless exists $incoming->{$kind};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $incoming->{$kind} 1150 545 1695
333 545 $merged{$kind} = $incoming->{$kind};
334 545 $merged{origins}{$kind} = $incoming->{origins}{$kind};
335 }
336 565 return \%merged;
337 }
338  
339 2 ▶sub _override_use {
Subroutine _override_use: called CC=1 SCAR=0.0
340 2 my ( $self, $file, $entry, $source ) = @_;
341 2 return $file.': user install "'.$entry.'" references source "'.$source.'", which has no "git", "url" or "local" '
342 .'in this file (user-scope items are built from the user config\'s sources alone)';
343 }
344  
345 898 ▶sub _parse_install {
Subroutine _parse_install: called CC=14 SCAR=26.4
346 898 my ( $self, $obj, $file, $scope, $known, $overrides ) = @_;
347 898 ▶ $overrides //= {};
Condition100%2/2
$overrides //= {}
l!l
431467
MC/DC100%1/1
$overrides //= {}
$overrides
Truth table100%2/2
A
A= $overrides
Aresult
11
00
348 898 my $install = $self->_as_object( $obj, 'install', $file, 'install' );
349 897 my %install_keys = INSTALL_KEYS;
350 897 for my $key ( keys %$install ) {
351 931 ▶ next if exists $install_keys{$key} || $key eq BUNDLES_KEY;
Branch: 1 branch
BranchTrueFalseTotal
if exists $install_keys{$key} or $key eq "bundles" 928 3 931
Condition100%3/3
exists $install_keys{$key} or $key eq "bundles"
l!l&&r!l&&!r
914143
MC/DC100%2/2
exists $install_keys{$key} or $key eq "bundles"
exists $install_keys{$key} $key eq "bundles"
Truth table100%3/3
A or B
A= exists $install_keys{$key}B= $key eq "bundles"
ABresult
1X1
011
000
352 3 $self->_fail( $file.': install.'.$key.' is not a valid type (skills, agents, rules, bundles)' );
353 }
354 894 my ( @items, @wildcards, %seen );
355 894 my @pairs = INSTALL_KEYS;
356 894 ▶ while ( my ( $key, $type ) = splice @pairs, 0, 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@pairs, 0, 2)) 2653 876 3529
357 2653 ▶ next unless exists $install->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $install->{$key} 1740 913 2653
358 913 my $list = $install->{$key};
359 913 ▶ $self->_fail( $file.': install.'.$key.' must be an array' ) unless js_type($list) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($list) eq "array" 1 912 913
360 912 for my $i ( 0 .. $#$list ) {
361 1254 my $entry = $list->[$i];
362 1254 ▶ $self->_fail( $file.': install.'.$key.'['.$i.'] must be a string' ) unless js_type($entry) eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($entry) eq "string" 2 1252 1254
363 1252 my $item = parse_entry( $entry, $type, $file, 'install.'.$key.'['.$i.']' );
364 1246 ▶ $self->_fail( $self->_override_use( $file, $entry, $item->{source} ) ) if $overrides->{ $item->{source} };
Branch: 1 branch
BranchTrueFalseTotal
if $$overrides{$item->{"source"}} 1 1245 1246
365 1245 ▶ unless ( _map_has( $known, $item->{source} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_map_has($known, $item->{"source"})) 4 1241 1245
366 4 $self->_fail( $file.': '.$scope.' install "'.$entry.'" references unknown source "'.$item->{source}.'"' );
367 }
368 1241 my $target_key = seen_key($item);
369 1241 ▶ if ( defined( my $prev = $seen{$target_key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $prev = $seen{$target_key})) 4 1237 1241
370 4 $self->_fail( $file.': duplicate '.$item->{type}.' target "'.$item->{name}.'" declared as '.$prev.' and '.$entry );
371 }
372 1237 $seen{$target_key} = $entry;
373 1237 ▶ if ( is_pattern( $item->{name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_pattern($item->{'name'})) { } 108 1129 1237
374 108 push @wildcards, { type => $item->{type}, source => $item->{source}, pattern => $item->{name}, raw => $entry };
375 }
376 else {
377 1129 push @items, $item;
378 }
379 }
380 }
381 876 my $bundles = $self->_parse_bundles( $install, $file, $scope, $known, $overrides );
382 867 return { install => \@items, wildcards => \@wildcards, bundles => $bundles };
383 }
384  
385 876 ▶sub _parse_bundles {
Subroutine _parse_bundles: called CC=7 SCAR=19.5
386 876 my ( $self, $install, $file, $scope, $known, $overrides ) = @_;
387 876 ▶ return [] unless exists $install->{ BUNDLES_KEY() };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $install->{"bundles"} 863 13 876
388 13 my $list = $install->{ BUNDLES_KEY() };
389 13 ▶ $self->_fail( $file.': install.'.BUNDLES_KEY.' must be an array' ) unless js_type($list) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($list) eq "array" 1 12 13
390 12 my @out;
391 12 for my $i ( 0 .. $#$list ) {
392 15 my $entry = $list->[$i];
393 15 my $where = 'install.'.BUNDLES_KEY.'['.$i.']';
394 15 ▶ $self->_fail( $file.': '.$where.' must be a string' ) unless js_type($entry) eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($entry) eq "string" 1 14 15
395 14 my $b = parse_bundle_entry( $entry, $file, $where );
396 10 ▶ $self->_fail( $self->_override_use( $file, $entry, $b->{source} ) ) if $overrides->{ $b->{source} };
Branch: 1 branch
BranchTrueFalseTotal
if $$overrides{$b->{"source"}} 1 9 10
397 9 ▶ unless ( _map_has( $known, $b->{source} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_map_has($known, $b->{"source"})) 1 8 9
398 1 $self->_fail( $file.': '.$scope.' install "'.$entry.'" references unknown source "'.$b->{source}.'"' );
399 }
400 8 push @out, $b;
401 }
402 5 return $self->_dedupe_bundles( \@out, [], $file );
403 }
404  
405 236 ▶sub _dedupe_bundles {
Subroutine _dedupe_bundles: called CC=3 SCAR=11.0
406 236 my ( $self, $a, $b, $file ) = @_;
407 236 my %seen;
408 236 for my $x ( @$a, @$b ) {
409 10 my $key = $x->{name}.'@'.$x->{source};
410 10 ▶ if ( defined( my $prev = $seen{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $prev = $seen{$key})) 2 8 10
411 2 $self->_fail( $file.': duplicate bundle "'.$key.'" declared as '.$prev.' and '.$x->{raw} );
412 }
413 8 $seen{$key} = $x->{raw};
414 }
415 234 return [ @$a, @$b ];
416 }
417  
418 233 ▶sub _dedupe_across {
Subroutine _dedupe_across: called CC=3 SCAR=11.0
419 233 my ( $self, $a, $b, $file ) = @_;
420 233 my %seen;
421 233 for my $item ( @$a, @$b ) {
422 487 my $key = seen_key($item);
423 487 ▶ if ( defined( my $prev = $seen{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $prev = $seen{$key})) 1 486 487
424 1 $self->_fail( $file.': duplicate '.$item->{type}.' target "'.$item->{name}.'" declared as '.$prev.' and '.$item->{raw} );
425 }
426 486 $seen{$key} = $item->{raw};
427 }
428 232 return [ @$a, @$b ];
429 }
430  
431 232 ▶sub _dedupe_wildcards {
Subroutine _dedupe_wildcards: called CC=3 SCAR=11.0
432 232 my ( $self, $a, $b, $file ) = @_;
433 232 my %seen;
434 232 for my $w ( @$a, @$b ) {
435 5 my $key = seen_key( { type => $w->{type}, name => $w->{pattern}, source => $w->{source} } );
436 5 ▶ if ( defined( my $prev = $seen{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $prev = $seen{$key})) 1 4 5
437 1 $self->_fail( $file.': duplicate '.$w->{type}.' wildcard for "'.$w->{source}.'" declared as '.$prev.' and '.$w->{raw} );
438 }
439 4 $seen{$key} = $w->{raw};
440 }
441 231 return [ @$a, @$b ];
442 }
443  
444 628 ▶sub _merge_vars {
Subroutine _merge_vars: called CC=3 SCAR=11.0
445 628 my ( @objs ) = @_;
446 628 my $out = js_ordered();
447 628 for my $o (@objs) {
448 1084 $out->{$_} = $o->{$_} for keys %$o;
449 }
450 628 return $out;
451 }
452  
453 843 ▶sub _targets_of {
Subroutine _targets_of: called CC=8 SCAR=20.8
454 843 my ( $self, $obj, $file ) = @_;
455 843 ▶ return undef unless exists $obj->{targets};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $obj->{"targets"} 818 25 843
456 25 my $value = $obj->{targets};
457 25 my $allowed = join ', ', HARNESSES;
458 25 my %known = map { $_ => 1 } HARNESSES;
459 25 ▶ unless ( js_type($value) eq 'array' && @$value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (js_type($value) eq "array" and @$value) 3 22 25
Condition100%3/3
js_type($value) eq "array" and @$value
!ll&&!rl&&r
2122
MC/DC100%2/2
js_type($value) eq "array" and @$value
js_type($value) eq "array" @$value
Truth table100%3/3
A and B
A= js_type($value) eq "array"B= @$value
ABresult
0X0
100
111
460 3 $self->_fail( $file.': "targets" must be a non-empty array (of '.$allowed.')' );
461 }
462 22 my @out;
463 22 for my $v (@$value) {
464 34 ▶ unless ( js_type($v) eq 'string' && $known{$v} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (js_type($v) eq "string" and $known{$v}) 2 32 34
Condition100%3/3
js_type($v) eq "string" and $known{$v}
!ll&&!rl&&r
1132
MC/DC100%2/2
js_type($v) eq "string" and $known{$v}
js_type($v) eq "string" $known{$v}
Truth table100%3/3
A and B
A= js_type($v) eq "string"B= $known{$v}
ABresult
0X0
100
111
465 2 $self->_fail( $file.': "targets" has unknown harness '.js_stringify($v).' (allowed: '.$allowed.')' );
466 }
467 32 ▶ $self->_fail( $file.': "targets" lists "'.$v.'" twice' ) if grep { $_ eq $v } @out;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $v;} @out 1 31 32
468 31 push @out, $v;
469 }
470 19 return \@out;
471 }
472  
473 434 ▶sub _number_or {
Subroutine _number_or: called CC=6 SCAR=18.0
474 434 my ( $self, $obj, $key, $fallback, $file ) = @_;
475 434 ▶ return $fallback unless exists $obj->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $obj->{$key} 429 5 434
476 5 my $value = $obj->{$key};
477 5 ▶ unless ( js_type($value) eq 'number' && $value == $value && $value != 9**9**9 && $value != -9**9**9 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (js_type($value) eq "number" and $value == $value and $value != "Inf" and $value != "-Inf") 3 2 5
Condition77%7/9
js_type($value) eq "number" and $value == $value and $value != "Inf" and $value != "-Inf"
!ll&&!rl&&r
302
js_type($value) eq "number" and $value == $value and $value != "Inf"
!ll&&!rl&&r
212
js_type($value) eq "number" and $value == $value
!ll&&!rl&&r
203
MC/DC50%2/4
js_type($value) eq "number" and $value == $value and $value != "Inf" and $value != "-Inf"
js_type($value) eq "number" $value == $value $value != "Inf" $value != "-Inf"
Truth table60%3/5
A and B and C and D
A= js_type($value) eq "number"B= $value == $valueC= $value != "Inf"D= $value != "-Inf"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
478 3 $self->_fail( $file.': "'.$key.'" must be a number' );
479 }
480 2 return $value;
481 }
482  
483 # boolOr: $present says whether the value exists at all (JavaScript's undefined).
484 1476 ▶sub _bool_or {
Subroutine _bool_or: called CC=3 SCAR=11.0
485 1476 my ( $self, $present, $value, $fallback, $file, $key ) = @_;
486 1476 ▶ return $fallback unless $present;
Branch: 1 branch
BranchTrueFalseTotal
unless $present 1460 16 1476
487 16 ▶ $self->_fail( $file.': "'.$key.'" must be a boolean' ) unless js_type($value) eq 'boolean';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($value) eq "boolean" 7 9 16
488 9 return $value;
489 }
490  
491 536 ▶sub _build__loaded {
Subroutine _build__loaded: called CC=30 SCAR=34.1
492 536 my ( $self ) = @_;
493 536 my $user_path = $self->user_path;
494 536 my $has_project = $self->has_project;
495 536 ▶ my $project_path = $has_project ? $self->project_path : '';
Branch: 1 branch
BranchTrueFalseTotal
$has_project ? : 373 163 536
496 536 ▶ my $local_path = $has_project ? $self->local_path : '';
Branch: 1 branch
BranchTrueFalseTotal
$has_project ? : 373 163 536
497  
498 536 my $user = $self->_read_config_file($user_path);
499 481 ▶ my $project = $has_project ? $self->_read_config_file($project_path) : js_ordered();
Branch: 1 branch
BranchTrueFalseTotal
$has_project ? : 320 161 481
500 478 ▶ my $local = $has_project ? $self->_read_config_file($local_path) : js_ordered();
Branch: 1 branch
BranchTrueFalseTotal
$has_project ? : 317 161 478
501 476 for my $pair ( [ $project, $project_path ], [ $local, $local_path ] ) {
502 951 my ( $obj, $p ) = @$pair;
503 951 ▶ $self->_fail( $p.': "checkInterval" is user-only' ) if $p ne '' && exists $obj->{checkInterval};
Branch: 1 branch
BranchTrueFalseTotal
if $p ne "" and exists $obj->{"checkInterval"} 2 949 951
Condition100%3/3
$p ne "" and exists $obj->{"checkInterval"}
!ll&&!rl&&r
3226272
MC/DC100%2/2
$p ne "" and exists $obj->{"checkInterval"}
$p ne "" exists $obj->{"checkInterval"}
Truth table100%3/3
A and B
A= $p ne ""B= exists $obj->{"checkInterval"}
ABresult
0X0
100
111
504 }
505  
506 # The user scope reads the user config's sources alone; the project scope the merged map:
507 # project (base) < user < local, per field.
508 474 my $unchecked = $self->unchecked;
509 1439 ▶ my $skip = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
510 1439 my ( $p ) = @_;
511 1439 ▶ return ( $unchecked && $unchecked->{path} eq $p ) ? $unchecked->{name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$unchecked && $unchecked->{'path'} eq $p ? : 7 1432 1439
Condition100%3/3
$unchecked and $unchecked->{"path"} eq $p
!ll&&!rl&&r
142487
MC/DC100%2/2
$unchecked and $unchecked->{"path"} eq $p
$unchecked $unchecked->{"path"} eq $p
Truth table100%3/3
A and B
A= $uncheckedB= $unchecked->{"path"} eq $p
ABresult
0X0
100
111
512 474 };
513 474 my $user_sources = $self->_parse_sources( $user, $user_path, 'user', $skip->($user_path) );
514 441 ▶ my $project_sources = $has_project ? $self->_parse_sources( $project, $project_path, 'project', $skip->($project_path) ) : _map_new();
Branch: 1 branch
BranchTrueFalseTotal
$has_project ? : 280 161 441
515 440 ▶ my $local_sources = $has_project ? $self->_parse_sources( $local, $local_path, 'user', $skip->($local_path) ) : _map_new();
Branch: 1 branch
BranchTrueFalseTotal
$has_project ? : 279 161 440
516  
517 # "ref": null in a file unsets the ref of the files below it.
518 541 ▶ my $null_ref = sub {
Subroutine __ANON__: called CC=7 SCAR=20.5
519 541 my ( $obj, $name ) = @_;
520 541 ▶ my $s = exists $obj->{sources} ? $obj->{sources} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $obj->{'sources'} ? : 541 0 541
521 541 ▶ return 0 unless js_type($s) eq 'object' && exists $s->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($s) eq "object" and exists $s->{$name} 0 541 541
Condition33%1/3
js_type($s) eq "object" and exists $s->{$name}
!ll&&!rl&&r
00541
MC/DC0%0/2
js_type($s) eq "object" and exists $s->{$name}
js_type($s) eq "object" exists $s->{$name}
Truth table33%1/3
A and B
A= js_type($s) eq "object"B= exists $s->{$name}
ABresult
0X0
100
111
522 541 my $d = $s->{$name};
523 541 ▶ return ( js_type($d) eq 'object' && exists $d->{ref} && !defined $d->{ref} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
js_type($d) eq 'object' && exists $d->{'ref'} && !defined($d->{'ref'}) ? : 4 537 541
Condition83%5/6
js_type($d) eq "object" and exists $d->{"ref"} and not defined $d->{"ref"}
!ll&&!rl&&r
520174
js_type($d) eq "object" and exists $d->{"ref"}
!ll&&!rl&&r
052021
MC/DC66%2/3
js_type($d) eq "object" and exists $d->{"ref"} and not defined $d->{"ref"}
js_type($d) eq "object" exists $d->{"ref"} not defined $d->{"ref"}
Truth table75%3/4
A and B and not(C)
A= js_type($d) eq "object"B= exists $d->{"ref"}C= not defined $d->{"ref"}
ABCresult
0XX0
10X0
1100
1111
524 439 };
525 439 my $sources = _map_new();
526 439 _map_set( $sources, $_, _merge_source( undef, _map_get( $project_sources, $_ ) ) ) for _map_names($project_sources);
527 439 for my $name ( _map_names($user_sources) ) {
528 410 _map_set( $sources, $name, _merge_source( _map_get( $sources, $name ), _map_get( $user_sources, $name ), $null_ref->( $user, $name ) ) );
529 }
530 439 for my $name ( _map_names($local_sources) ) {
531 131 _map_set( $sources, $name, _merge_source( _map_get( $sources, $name ), _map_get( $local_sources, $name ), $null_ref->( $local, $name ) ) );
532 }
533  
534 # An entry without a backend only changes ref or path of a source another file of the
535 # merge defines; a source no file gives one is refused, naming each file declaring it.
536 439 for my $name ( _map_names($sources) ) {
537 544 ▶ next if _has_backend( _map_get( $sources, $name ) );
Branch: 1 branch
BranchTrueFalseTotal
if _has_backend(_map_get($sources, $name)) 535 9 544
538 9 my @files = map { $_->[1] } grep { _map_has( $_->[0], $name ) }
539 [ $project_sources, $project_path ], [ $user_sources, $user_path ], [ $local_sources, $local_path ];
540 9 ▶ next if $unchecked && $unchecked->{name} eq $name && grep { $_ eq $unchecked->{path} } @files;
Branch: 1 branch
BranchTrueFalseTotal
if $unchecked and $unchecked->{"name"} eq $name and grep {$_ eq $unchecked->{"path"};} @files 4 5 9
Condition66%4/6
$unchecked and $unchecked->{"name"} eq $name and grep {$_ eq $unchecked->{"path"};} @files
!ll&&!rl&&r
504
$unchecked and $unchecked->{"name"} eq $name
!ll&&!rl&&r
504
MC/DC33%1/3
$unchecked and $unchecked->{"name"} eq $name and grep {$_ eq $unchecked->{"path"};} @files
$unchecked $unchecked->{"name"} eq $name grep {$_ eq $unchecked->{"path"};} @files
Truth table50%2/4
A and B and C
A= $uncheckedB= $unchecked->{"name"} eq $nameC= grep {$_ eq $unchecked->{"path"};} @files
ABCresult
0XX0
10X0
1100
1111
541 5 ▶ $self->_fail( join( ' and ', @files ).': sources.'.$name.' needs one of "git", "url" or "local"; '
Branch: 1 branch
BranchTrueFalseTotal
@files == 1 ? : 3 2 5
542 .( @files == 1 ? 'no other config file gives one' : 'none of these files gives one' )
543 .' (an entry without one only changes "ref" or "path" of a source another file defines)' );
544 }
545  
546 # The user scope reads the user config alone, so an entry there without a backend is no
547 # source of its own; a user install naming it says so.
548 434 my %overrides;
549 434 for my $name ( _map_names($user_sources) ) {
550 406 my $skipped = $skip->($user_path);
551 406 ▶ next if _has_backend( _map_get( $user_sources, $name ) ) || ( defined $skipped && $skipped eq $name );
Branch: 1 branch
BranchTrueFalseTotal
if _has_backend(_map_get($user_sources, $name)) or defined $skipped and $skipped eq $name 402 4 406
Condition83%5/6
_has_backend(_map_get($user_sources, $name)) or defined $skipped and $skipped eq $name
l!l&&r!l&&!r
40024
defined $skipped and $skipped eq $name
!ll&&!rl&&r
402
MC/DC66%2/3
_has_backend(_map_get($user_sources, $name)) or defined $skipped and $skipped eq $name
_has_backend(_map_get($user_sources, $name)) defined $skipped $skipped eq $name
Truth table75%3/4
A or B and C
A= _has_backend(_map_get($user_sources, $name))B= defined $skippedC= $skipped eq $name
ABCresult
1XX1
0111
00X0
0100
552 4 $overrides{$name} = 1;
553 4 _map_delete( $user_sources, $name );
554 }
555  
556 # Default 30 min. 0 (or negative) disables the in-session check; SessionStart still syncs.
557 434 my $check_interval = $self->_number_or( $user, 'checkInterval', 1800, $user_path );
558  
559 431 my $true = JSON::MaybeXS::true();
560 431 my $user_install = $self->_parse_install( $user, $user_path, 'user', $user_sources, \%overrides );
561 my $user_scope = {
562 scope => 'user',
563 install => $user_install->{install},
564 wildcards => $user_install->{wildcards},
565 bundles => $user_install->{bundles},
566 401 vars => _merge_vars( $self->_as_object( $user, 'vars', $user_path, 'vars' ) ),
567 };
568 400 $user_scope->{gitignore} = $self->_bool_or( exists $user->{gitignore}, $user->{gitignore}, $true, $user_path, 'gitignore' );
569 $user_scope->{claudeSettings} =
570 398 $self->_bool_or( exists $user->{claudeSettings}, $user->{claudeSettings}, $true, $user_path, 'claudeSettings' );
571 398 my $user_targets = $self->_targets_of( $user, $user_path );
572 394 ▶ $user_scope->{targets} = $user_targets if $user_targets;
Branch: 1 branch
BranchTrueFalseTotal
if $user_targets 13 381 394
573  
574 394 my $project_scope;
575 394 ▶ if ($has_project) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_project) 234 160 394
576 # Project install can be declared in the project file and the local file.
577 234 my $project_install = $self->_parse_install( $project, $project_path, 'project', $sources );
578 233 my $local_install = $self->_parse_install( $local, $local_path, 'project', $sources );
579 $project_scope = {
580 scope => 'project',
581 install => $self->_dedupe_across( $project_install->{install}, $local_install->{install}, $project_path ),
582 wildcards => $self->_dedupe_wildcards( $project_install->{wildcards}, $local_install->{wildcards}, $project_path ),
583 233 bundles => $self->_dedupe_bundles( $project_install->{bundles}, $local_install->{bundles}, $project_path ),
584 };
585 230 $project_scope->{vars} = _merge_vars(
586 $self->_as_object( $user, 'vars', $user_path, 'vars' ),
587 $self->_as_object( $project, 'vars', $project_path, 'vars' ),
588 $self->_as_object( $local, 'vars', $local_path, 'vars' ),
589 );
590 # local.gitignore ?? project.gitignore: a null in the local file falls through.
591 my ( $g_present, $g_value ) =
592 ( exists $local->{gitignore} && defined $local->{gitignore} ) ? ( 1, $local->{gitignore} )
593 : exists $project->{gitignore} ? ( 1, $project->{gitignore} )
594 228 ▶ : ( 0, undef );
Branch: 2 branches
BranchTrueFalseTotal
exists $local->{'gitignore'} && defined $local->{'gitignore'} ? : 2 226 228
exists $project->{'gitignore'} ? : 3 223 226
Condition100%3/3
exists $local->{"gitignore"} and defined $local->{"gitignore"}
!ll&&!rl&&r
22512
MC/DC100%2/2
exists $local->{"gitignore"} and defined $local->{"gitignore"}
exists $local->{"gitignore"} defined $local->{"gitignore"}
Truth table100%3/3
A and B
A= exists $local->{"gitignore"}B= defined $local->{"gitignore"}
ABresult
0X0
100
111
595 228 $project_scope->{gitignore} = $self->_bool_or( $g_present, $g_value, $true, $project_path, 'gitignore' );
596 # The last file that sets it: local, the committed project file, the user's.
597 my $from_project = $self->_bool_or( exists $project->{claudeSettings}, $project->{claudeSettings},
598 226 $user_scope->{claudeSettings}, $project_path, 'claudeSettings' );
599 $project_scope->{claudeSettings} =
600 224 $self->_bool_or( exists $local->{claudeSettings}, $local->{claudeSettings}, $from_project, $local_path, 'claudeSettings' );
601 223 my $project_targets = $self->_targets_of( $project, $project_path );
602 222 my $local_targets = $self->_targets_of( $local, $local_path );
603 221 ▶ my $targets = $local_targets // $project_targets;
Condition100%3/3
$local_targets // $project_targets
l!l&&r!l&&!r
14216
MC/DC100%2/2
$local_targets // $project_targets
$local_targets $project_targets
Truth table100%3/3
A // B
A= $local_targetsB= $project_targets
ABresult
1X1
011
000
604 221 ▶ $project_scope->{targets} = $targets if $targets;
Branch: 1 branch
BranchTrueFalseTotal
if $targets 5 216 221
605 }
606  
607 return {
608 381 sources => $sources,
609 checkInterval => $check_interval,
610 user => $user_scope,
611 project => $project_scope,
612 userSources => $user_sources,
613 };
614 }
615  
616 #### Edit operations (spec ยง7) #########################################
617 #
618 # They change one config file, creating it if needed, written as 2-space JSON with a
619 # trailing newline, keeping the file's key order.
620  
621 29 ▶sub _load_raw {
Subroutine _load_raw: called CC=6 SCAR=18.1
622 29 my ( $self, $file ) = @_;
623 29 ▶ return js_ordered() unless -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 1 28 29
624 28 my $value = eval {
625 28 my $v = js_parse( read_text($file) );
626 27 ▶ Skilletor::Error::JSON->throw('top level must be an object') unless js_type($v) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($v) eq "object" 1 26 27
627 26 $v;
628 };
629 28 ▶ unless ($value) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value) 2 26 28
630 2 my $err = $@;
631 2 ▶ $self->_fail( $file.': invalid JSON ('.( ref $err && $err->can('message') ? $err->message : "$err" ).')' );
Branch: 1 branch
BranchTrueFalseTotal
ref $err && $err->can('message') ? : 2 0 2
Condition33%1/3
ref $err and $err->can("message")
!ll&&!rl&&r
002
MC/DC0%0/2
ref $err and $err->can("message")
ref $err $err->can("message")
Truth table33%1/3
A and B
A= ref $errB= $err->can("message")
ABresult
0X0
100
111
632 }
633 26 return $value;
634 }
635  
636 21 ▶sub _save_raw {
Subroutine _save_raw: called CC=1 SCAR=0.0
637 21 my ( $self, $file, $cfg ) = @_;
638 21 write_text( $file, js_stringify( $cfg, 2 )."\n" );
639 }
640  
641 # A plain hash becomes a definition in the reference's field order; an ordered one keeps its.
642 5 ▶sub _source_def {
Subroutine _source_def: called CC=3 SCAR=16.5
643 5 my ( $def ) = @_;
644 5 ▶ return $def if tied %$def;
Branch: 1 branch
BranchTrueFalseTotal
if tied %$def 5 0 5
645 0 ▶ return js_ordered( map { exists $def->{$_} ? ( $_ => $def->{$_} ) : () } @SOURCE_FIELD_ORDER );
Branch: 1 branch
BranchTrueFalseTotal
exists $def->{$_} ? : 0 0 0
646 }
647  
648 3 ▶sub source_entry {
Subroutine source_entry: called CC=3 SCAR=11.0
Pod documented
649 3 my ( $self, $file, $name ) = @_;
650 3 my $sources = $self->_load_raw($file)->{sources};
651 2 ▶ return undef unless js_type($sources) eq 'object' && exists $sources->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($sources) eq "object" and exists $sources->{$name} 1 1 2
Condition66%2/3
js_type($sources) eq "object" and exists $sources->{$name}
!ll&&!rl&&r
011
MC/DC50%1/2
js_type($sources) eq "object" and exists $sources->{$name}
js_type($sources) eq "object" exists $sources->{$name}
Truth table66%2/3
A and B
A= js_type($sources) eq "object"B= exists $sources->{$name}
ABresult
0X0
100
111
652 1 return $sources->{$name};
653 }
654  
655 6 ▶sub add_source {
Subroutine add_source: called CC=3 SCAR=11.0
Pod documented
656 6 my ( $self, $file, $name, $def ) = @_;
657 6 my $cfg = $self->_load_raw($file);
658 5 ▶ my $sources = defined $cfg->{sources} ? $cfg->{sources} : js_ordered();
Branch: 1 branch
BranchTrueFalseTotal
defined $cfg->{'sources'} ? : 3 2 5
659 5 ▶ $sources->{$name} = _source_def($def) if js_type($sources) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
if js_type($sources) eq "object" 5 0 5
660 5 $cfg->{sources} = $sources;
661 5 $self->_save_raw( $file, $cfg );
662 }
663  
664 3 ▶sub remove_source {
Subroutine remove_source: called CC=4 SCAR=14.2
Pod documented
665 3 my ( $self, $file, $name ) = @_;
666 3 my $cfg = $self->_load_raw($file);
667 3 my $sources = $cfg->{sources};
668 3 ▶ if ( js_type($sources) eq 'object' && exists $sources->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (js_type($sources) eq "object" and exists $sources->{$name}) 3 0 3
Condition33%1/3
js_type($sources) eq "object" and exists $sources->{$name}
!ll&&!rl&&r
003
MC/DC0%0/2
js_type($sources) eq "object" and exists $sources->{$name}
js_type($sources) eq "object" exists $sources->{$name}
Truth table33%1/3
A and B
A= js_type($sources) eq "object"B= exists $sources->{$name}
ABresult
0X0
100
111
669 3 delete $sources->{$name};
670 3 ▶ delete $cfg->{sources} unless keys %$sources;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$sources 1 2 3
671 3 $self->_save_raw( $file, $cfg );
672 }
673 }
674  
675 4 ▶sub add_install_entry {
Subroutine add_install_entry: called CC=6 SCAR=18.1
Pod documented
676 4 my ( $self, $file, $type, $entry ) = @_;
677 4 my $cfg = $self->_load_raw($file);
678 4 ▶ my $install = defined $cfg->{install} ? $cfg->{install} : js_ordered();
Branch: 1 branch
BranchTrueFalseTotal
defined $cfg->{'install'} ? : 3 1 4
679 4 my $key = INSTALL_KEY_OF->{$type};
680 4 ▶ my $list = js_type( $install->{$key} ) eq 'array' ? $install->{$key} : [];
Branch: 1 branch
BranchTrueFalseTotal
js_type($install->{$key}) eq 'array' ? : 2 2 4
681 4 ▶ push @$list, $entry unless grep { defined $_ && !ref $_ && $_ eq $entry } @$list;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {defined $_ and not ref $_ and $_ eq $entry;} @$list 3 1 4
Condition50%3/6
defined $_ && !ref($_) && $_ eq $entry
!ll&&!rl&&r
011
defined $_ and not ref $_
!ll&&!rl&&r
002
MC/DC33%1/3
defined $_ && !ref($_) && $_ eq $entry
defined $_ not ref $_ $_ eq $entry
Truth table50%2/4
A and not(B) && C
A= defined $_B= not ref $_C= $_ eq $entry
ABCresult
0XX0
10X0
1100
1111
682 4 $install->{$key} = $list;
683 4 $cfg->{install} = $install;
684 4 $self->_save_raw( $file, $cfg );
685 }
686  
687 # Does raw entry $e ([type:]name@source) declare $name (from $source, if given)? A name
688 # matches ignoring case; a pattern is the entry as written.
689 14 ▶sub _entry_matches {
Subroutine _entry_matches: called CC=9 SCAR=22.1
690 14 my ( $e, $name, $source ) = @_;
691 14 my $at = rindex $e, '@';
692 14 ▶ ( my $e_name = $at > 0 ? substr( $e, 0, $at ) : $e ) =~ s/\A[a-z]+://;
Branch: 1 branch
BranchTrueFalseTotal
$at > 0 ? : 14 0 14
693 14 ▶ my $e_source = $at > 0 ? substr( $e, $at + 1 ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$at > 0 ? : 14 0 14
694 14 ▶ my $same = ( is_pattern($name) || is_pattern($e_name) ) ? $e_name eq $name : name_key($e_name) eq name_key($name);
Branch: 1 branch
BranchTrueFalseTotal
is_pattern($name) || is_pattern($e_name) ? : 4 10 14
Condition100%3/3
is_pattern($name) or is_pattern($e_name)
l!l&&r!l&&!r
1310
MC/DC100%2/2
is_pattern($name) or is_pattern($e_name)
is_pattern($name) is_pattern($e_name)
Truth table100%3/3
A or B
A= is_pattern($name)B= is_pattern($e_name)
ABresult
1X1
011
000
695 14 ▶ return $same && ( !defined $source || ( defined $e_source && $e_source eq $source ) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$same && (!defined($source) || defined $e_source && $e_source eq $source) ? : 7 7 14
Condition88%8/9
$same and !defined($source) || defined $e_source && $e_source eq $source
!ll&&!rl&&r
617
not defined $source or defined $e_source and $e_source eq $source
l!l&&r!l&&!r
521
defined $e_source and $e_source eq $source
!ll&&!rl&&r
012
MC/DC75%3/4
$same and !defined($source) || defined $e_source && $e_source eq $source
$same not defined $source defined $e_source $e_source eq $source
Truth table80%4/5
A and not(B) or C and D
A= $sameB= not defined $sourceC= defined $e_sourceD= $e_source eq $source
ABCDresult
0XXX0
100X0
10100
11XX1
10111
696 }
697  
698 2 ▶sub find_install_entries {
Subroutine find_install_entries: called CC=9 SCAR=22.4
Pod documented
699 2 my ( $self, $file, $name, $source, $type ) = @_;
700 2 my $install = $self->_load_raw($file)->{install};
701 2 ▶ return [] unless $install;
Branch: 1 branch
BranchTrueFalseTotal
unless $install 0 2 2
702 2 my @out;
703 2 ▶ for my $t ( $type ? ($type) : (ITEM_TYPES) ) {
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 0 2 2
704 6 ▶ my $list = js_type($install) eq 'object' ? $install->{ INSTALL_KEY_OF->{$t} } : undef;
Branch: 1 branch
BranchTrueFalseTotal
js_type($install) eq 'object' ? : 6 0 6
705 6 ▶ next unless js_type($list) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($list) eq "array" 2 4 6
706 4 for my $e (@$list) {
707 4 ▶ push @out, { type => $t, entry => $e } if js_type($e) eq 'string' && _entry_matches( $e, $name, $source );
Branch: 1 branch
BranchTrueFalseTotal
if js_type($e) eq "string" and _entry_matches($e, $name, $source) 1 3 4
Condition66%2/3
js_type($e) eq "string" and _entry_matches($e, $name, $source)
!ll&&!rl&&r
031
MC/DC50%1/2
js_type($e) eq "string" and _entry_matches($e, $name, $source)
js_type($e) eq "string" _entry_matches($e, $name, $source)
Truth table66%2/3
A and B
A= js_type($e) eq "string"B= _entry_matches($e, $name, $source)
ABresult
0X0
100
111
708 }
709 }
710 2 return \@out;
711 }
712  
713 6 ▶sub remove_install_entries {
Subroutine remove_install_entries: called CC=11 SCAR=24.1
Pod documented
714 6 my ( $self, $file, $name, $source, $type ) = @_;
715 6 my $cfg = $self->_load_raw($file);
716 6 my $install = $cfg->{install};
717 6 ▶ return 0 unless $install && js_type($install) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
unless $install and js_type($install) eq "object" 0 6 6
Condition33%1/3
$install and js_type($install) eq "object"
!ll&&!rl&&r
006
MC/DC0%0/2
$install and js_type($install) eq "object"
$install js_type($install) eq "object"
Truth table33%1/3
A and B
A= $installB= js_type($install) eq "object"
ABresult
0X0
100
111
718 6 my $removed = 0;
719 6 ▶ for my $key ( $type ? ( INSTALL_KEY_OF->{$type} ) : map { INSTALL_KEY_OF->{$_} } ITEM_TYPES ) {
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 2 4 6
720 14 my $list = $install->{$key};
721 14 ▶ next unless js_type($list) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($list) eq "array" 6 8 14
722 my @kept = grep {
723 8 ▶ my $match = js_type($_) eq 'string' && _entry_matches( $_, $name, $source );
Condition100%3/3
js_type($_) eq 'string' && _entry_matches($_, $name, $source)
!ll&&!rl&&r
146
MC/DC100%2/2
js_type($_) eq 'string' && _entry_matches($_, $name, $source)
js_type($_) eq 'string' _entry_matches($_, $name, $source)
Truth table100%3/3
A && B
A= js_type($_) eq 'string'B= _entry_matches($_, $name, $source)
ABresult
0X0
100
111
724 11 ▶ $removed++ if $match;
Branch: 1 branch
BranchTrueFalseTotal
if $match 6 5 11
725 11 !$match;
726 } @$list;
727 8 ▶ if (@kept) { $install->{$key} = \@kept }
Branch: 1 branch
BranchTrueFalseTotal
if (@kept) { } 4 4 8
728 4 else { delete $install->{$key} }
729 }
730 6 ▶ delete $cfg->{install} unless keys %$install;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$install 1 5 6
731 6 ▶ $self->_save_raw( $file, $cfg ) if $removed;
Branch: 1 branch
BranchTrueFalseTotal
if $removed 6 0 6
732 6 return $removed;
733 }
734  
735 1 ▶sub find_wildcard_entries {
Subroutine find_wildcard_entries: called CC=11 SCAR=25.6
Pod documented
736 1 my ( $self, $file, $source, $type ) = @_;
737 1 my $install = $self->_load_raw($file)->{install};
738 1 ▶ return [] unless $install && js_type($install) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
unless $install and js_type($install) eq "object" 0 1 1
Condition33%1/3
$install and js_type($install) eq "object"
!ll&&!rl&&r
001
MC/DC0%0/2
$install and js_type($install) eq "object"
$install js_type($install) eq "object"
Truth table33%1/3
A and B
A= $installB= js_type($install) eq "object"
ABresult
0X0
100
111
739 1 my @out;
740 1 ▶ for my $t ( $type ? ($type) : (ITEM_TYPES) ) {
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 0 1 1
741 3 my $list = $install->{ INSTALL_KEY_OF->{$t} };
742 3 ▶ next unless js_type($list) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($list) eq "array" 1 2 3
743 2 for my $e (@$list) {
744 2 ▶ next unless js_type($e) eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($e) eq "string" 0 2 2
745 2 my $at = rindex $e, '@';
746 2 ▶ next if $at <= 0 || substr( $e, $at + 1 ) ne $source;
Branch: 1 branch
BranchTrueFalseTotal
if $at <= 0 or substr($e, $at + 1) ne $source 0 2 2
Condition33%1/3
$at <= 0 or substr($e, $at + 1) ne $source
l!l&&r!l&&!r
002
MC/DC0%0/2
$at <= 0 or substr($e, $at + 1) ne $source
$at <= 0 substr($e, $at + 1) ne $source
Truth table33%1/3
A or B
A= $at <= 0B= substr($e, $at + 1) ne $source
ABresult
1X1
011
000
747 2 ( my $pattern = substr( $e, 0, $at ) ) =~ s/\A[a-z]+://;
748 2 ▶ push @out, { type => $t, entry => $e, pattern => $pattern } if is_pattern($pattern);
Branch: 1 branch
BranchTrueFalseTotal
if is_pattern($pattern) 1 1 2
749 }
750 }
751 1 return \@out;
752 }
753  
754 5 ▶sub _bundle_parts {
Subroutine _bundle_parts: called CC=2 SCAR=7.0
755 5 my ( $e ) = @_;
756 5 my $at = rindex $e, '@';
757 5 ▶ return undef if $at <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $at <= 0 0 5 5
758 5 ( my $name = substr( $e, 0, $at ) ) =~ s/\Abundle://;
759 5 return { name => $name, source => substr( $e, $at + 1 ) };
760 }
761  
762 1 ▶sub bundle_entries {
Subroutine bundle_entries: called CC=7 SCAR=21.2
Pod documented
763 1 my ( $self, $file ) = @_;
764 1 my $install = $self->_load_raw($file)->{install};
765 1 ▶ my $list = ( $install && js_type($install) eq 'object' ) ? $install->{ BUNDLES_KEY() } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$install && js_type($install) eq 'object' ? : 1 0 1
Condition33%1/3
$install and js_type($install) eq "object"
!ll&&!rl&&r
001
MC/DC0%0/2
$install and js_type($install) eq "object"
$install js_type($install) eq "object"
Truth table33%1/3
A and B
A= $installB= js_type($install) eq "object"
ABresult
0X0
100
111
766 1 ▶ return [] unless js_type($list) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($list) eq "array" 0 1 1
767 1 my @out;
768 1 for my $e (@$list) {
769 1 ▶ my $p = js_type($e) eq 'string' ? _bundle_parts($e) : undef;
Branch: 1 branch
BranchTrueFalseTotal
js_type($e) eq 'string' ? : 1 0 1
770 1 ▶ push @out, { %$p, entry => $e } if $p;
Branch: 1 branch
BranchTrueFalseTotal
if $p 1 0 1
771 }
772 1 return \@out;
773 }
774  
775 2 ▶sub add_bundle_entry {
Subroutine add_bundle_entry: called CC=8 SCAR=22.0
Pod documented
776 2 my ( $self, $file, $entry ) = @_;
777 2 my $cfg = $self->_load_raw($file);
778 2 ▶ my $install = defined $cfg->{install} ? $cfg->{install} : js_ordered();
Branch: 1 branch
BranchTrueFalseTotal
defined $cfg->{'install'} ? : 2 0 2
779 2 ▶ my $list = js_type( $install->{ BUNDLES_KEY() } ) eq 'array' ? $install->{ BUNDLES_KEY() } : [];
Branch: 1 branch
BranchTrueFalseTotal
js_type($install->{'bundles'}) eq 'array' ? : 1 1 2
780 2 ▶ my $p = _bundle_parts($entry) or croak __PACKAGE__.'->add_bundle_entry needs name@source';
Branch: 1 branch
BranchTrueFalseTotal
my $p = _bundle_parts($entry) or croak("Skilletor::Config->add_bundle_entry needs name\@source") 2 0 2
781 my $known = grep {
782 2 ▶ my $q = js_type($_) eq 'string' ? _bundle_parts($_) : undef;
Branch: 1 branch
BranchTrueFalseTotal
js_type($_) eq 'string' ? : 1 0 1
783 1 ▶ $q && $q->{name} eq $p->{name} && $q->{source} eq $p->{source};
Condition33%2/6
$q && $q->{'name'} eq $p->{'name'} && $q->{'source'} eq $p->{'source'}
!ll&&!rl&&r
001
$q and $q->{"name"} eq $p->{"name"}
!ll&&!rl&&r
001
MC/DC0%0/3
$q && $q->{'name'} eq $p->{'name'} && $q->{'source'} eq $p->{'source'}
$q $q->{"name"} eq $p->{"name"} $q->{'source'} eq $p->{'source'}
Truth table25%1/4
A and B && C
A= $qB= $q->{"name"} eq $p->{"name"}C= $q->{'source'} eq $p->{'source'}
ABCresult
0XX0
10X0
1100
1111
784 } @$list;
785 2 ▶ push @$list, $entry unless $known;
Branch: 1 branch
BranchTrueFalseTotal
unless $known 1 1 2
786 2 $install->{ BUNDLES_KEY() } = $list;
787 2 $cfg->{install} = $install;
788 2 $self->_save_raw( $file, $cfg );
789 }
790  
791 1 ▶sub remove_bundle_entries {
Subroutine remove_bundle_entries: called CC=10 SCAR=26.4
Pod documented
792 1 my ( $self, $file, $name, $source ) = @_;
793 1 my $cfg = $self->_load_raw($file);
794 1 my $install = $cfg->{install};
795 1 ▶ return 0 unless $install && js_type($install) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
unless $install and js_type($install) eq "object" 0 1 1
Condition33%1/3
$install and js_type($install) eq "object"
!ll&&!rl&&r
001
MC/DC0%0/2
$install and js_type($install) eq "object"
$install js_type($install) eq "object"
Truth table33%1/3
A and B
A= $installB= js_type($install) eq "object"
ABresult
0X0
100
111
796 1 my $list = $install->{ BUNDLES_KEY() };
797 1 ▶ return 0 unless js_type($list) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($list) eq "array" 0 1 1
798 my @kept = grep {
799 1 ▶ my $p = js_type($_) eq 'string' ? _bundle_parts($_) : undef;
Branch: 1 branch
BranchTrueFalseTotal
js_type($_) eq 'string' ? : 1 0 1
800 1 ▶ !( $p && $p->{name} eq $name && $p->{source} eq $source );
Condition33%2/6
$p && $p->{'name'} eq $name && $p->{'source'} eq $source
!ll&&!rl&&r
001
$p and $p->{"name"} eq $name
!ll&&!rl&&r
001
MC/DC0%0/3
$p && $p->{'name'} eq $name && $p->{'source'} eq $source
$p $p->{"name"} eq $name $p->{'source'} eq $source
Truth table25%1/4
A and B && C
A= $pB= $p->{"name"} eq $nameC= $p->{'source'} eq $source
ABCresult
0XX0
10X0
1100
1111
801 } @$list;
802 1 my $removed = @$list - @kept;
803 1 ▶ return 0 unless $removed;
Branch: 1 branch
BranchTrueFalseTotal
unless $removed 0 1 1
804 0 ▶ if (@kept) { $install->{ BUNDLES_KEY() } = \@kept }
Branch: 1 branch
BranchTrueFalseTotal
if (@kept) { } 0 1 1
805 1 else { delete $install->{ BUNDLES_KEY() } }
806 1 ▶ delete $cfg->{install} unless keys %$install;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$install 1 0 1
807 1 $self->_save_raw( $file, $cfg );
808 1 return $removed;
809 }
810  
811 37 1;
812  
813 __END__
« Skilletor/Bundles.pm ↑ Summary Skilletor/Catalog.pm »