lib/Skilletor/Config.pm

filter: Statementstmt 98.4% 517 / 525 Branchbran 86.6% 267 / 308 Conditioncond 73.2% 112 / 153 MC/DCmcdc 55.5% 50 / 90 Subroutinesub 100% 77 / 77 Podpod 96.4% 27 / 28 totaltotal 88.9% 1050 / 1181 CC 234 SCAR 22.8
CC
234
Cov
91%
_build__loaded
30.2
source_fields
15.1
_read_error
14.9
CRAP 9.7
« lib/Skilletor/CLI.pm ↑ Summary lib/Skilletor/FSUtil.pm »
1 package Skilletor::Config;
2 # ABSTRACT: Load, merge and validate the user, project and local skilletor config
3  
4 413 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 413 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 413 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 413 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 413 ▶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 413 );
12 413 ▶use Skilletor::Error::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 413 ▶use Skilletor::Error::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 413 ▶use Skilletor::FSUtil qw( read_text inner_segments path_join write_text );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 413 ▶use Skilletor::JSON qw( js_parse js_stringify js_ordered js_type );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 413 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 413 our $VERSION = '0.008000';
19  
20 413 my @ALLOWED_KEYS = qw( sources install vars gitignore claudeSettings checkInterval targets );
21 413 my %ALLOWED_KEY = map { $_ => 1 } @ALLOWED_KEYS;
22 413 my %SOURCE_KEY = map { $_ => 1 } qw( git ref url local path );
23 413 my @BACKEND_KINDS = qw( git url local );
24 # The order the reference writes a source definition's fields in (commands.ts pickDef).
25 413 my @SOURCE_FIELD_ORDER = qw( git ref url local path );
26 # What `git check-ref-format` forbids character by character.
27 413 my $NOT_IN_REF = qr/[\x00-\x20\x7f~^:?*[\\]|\.\.|\@\{/;
28  
29 413 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 413 has claude_config_dir => (
36 is => 'ro',
37 );
38  
39 413 has project_dir => (
40 is => 'ro',
41 );
42  
43 413 has unchecked => (
44 is => 'ro',
45 );
46  
47 413 has user_path => (
48 is => 'lazy',
49 init_arg => undef,
50 );
51  
52 9285 ▶sub _build_user_path {
Subroutine _build_user_path: called CC=3 SCAR=11.0
53 9285 my ( $self ) = @_;
54 9285 my $cd = $self->claude_config_dir;
55 9285 ▶ return path_join( ( defined $cd && length $cd ) ? $cd : path_join( $self->home, '.claude' ), 'skilletor.json' );
Branch: 1 branch
BranchTrueFalseTotal
defined $cd && length $cd ? : 1139 8146 9285
Condition100%3/3
defined $cd and length $cd
!ll&&!rl&&r
75046421139
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
56 }
57  
58 413 has project_path => (
59 is => 'lazy',
60 init_arg => undef,
61 );
62  
63 8743 ▶sub _build_project_path {
Subroutine _build_project_path: called CC=2 SCAR=6.9
64 8743 my ( $self ) = @_;
65 8743 ▶ return defined $self->project_dir ? path_join( $self->project_dir, '.claude', 'skilletor.json' ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->project_dir ? : 8742 1 8743
66 }
67  
68 413 has local_path => (
69 is => 'lazy',
70 init_arg => undef,
71 );
72  
73 8742 ▶sub _build_local_path {
Subroutine _build_local_path: called CC=2 SCAR=7.2
74 8742 my ( $self ) = @_;
75 8742 ▶ return defined $self->project_dir ? path_join( $self->project_dir, '.claude', 'skilletor.local.json' ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->project_dir ? : 8742 0 8742
76 }
77  
78 413 has _loaded => (
79 is => 'lazy',
80 init_arg => undef,
81 );
82  
83 9285 ▶sub BUILD { $_[0]->_loaded }
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
84  
85 9133 ▶sub load {
Subroutine load: called CC=1 SCAR=0.0
Pod documented
86 9133 my ( $class, %args ) = @_;
87 9133 return $class->new(%args);
88 }
89  
90 9287 ▶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 ? : 8743 544 9287
91 675 ▶sub check_interval { $_[0]->_loaded->{checkInterval} }
Subroutine check_interval: called CC=1 SCAR=0.0
Pod documented
92 17732 ▶sub user { $_[0]->_loaded->{user} }
Subroutine user: called CC=1 SCAR=0.0
Pod documented
93 49727 ▶sub project { $_[0]->_loaded->{project} }
Subroutine project: called CC=1 SCAR=0.0
Pod documented
94 407 ▶sub sources { [ _map_values( $_[0]->_loaded->{sources} ) ] }
Subroutine sources: called CC=1 SCAR=0.0
Pod documented
95 15 ▶sub source_names { _map_names( $_[0]->_loaded->{sources} ) }
Subroutine source_names: called CC=1 SCAR=0.0
Pod documented
96 450 ▶sub user_sources { [ _map_values( $_[0]->_loaded->{userSources} ) ] }
Subroutine user_sources: called CC=1 SCAR=0.0
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 5916 ▶sub source {
Subroutine source: called CC=1 SCAR=0.0
Pod documented
100 5916 my ( $self, $name ) = @_;
101 5916 return _map_get( $self->_loaded->{sources}, $name );
102 }
103  
104 7727 ▶sub user_source {
Subroutine user_source: called CC=1 SCAR=0.0
Pod documented
105 7727 my ( $self, $name ) = @_;
106 7727 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 603 ▶sub sources_of {
Subroutine sources_of: called CC=2 SCAR=6.9
Pod documented
112 603 my ( $self, $scope ) = @_;
113 603 ▶ return $scope eq 'user' ? $self->user_sources : $self->sources;
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'user' ? : 450 153 603
114 }
115  
116 13625 ▶sub source_of {
Subroutine source_of: called CC=2 SCAR=6.9
Pod documented
117 13625 my ( $self, $scope, $name ) = @_;
118 13625 ▶ return $scope eq 'user' ? $self->user_source($name) : $self->source($name);
Branch: 1 branch
BranchTrueFalseTotal
$scope eq 'user' ? : 7713 5912 13625
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 35962 ▶sub _map_new { { order => [], by => {} } }
Subroutine _map_new: called CC=1 SCAR=0.0
147 13548 ▶sub _map_has { exists $_[0]{by}{ $_[1] } }
Subroutine _map_has: called CC=1 SCAR=0.0
148 54601 ▶sub _map_get { $_[0]{by}{ $_[1] } }
Subroutine _map_get: called CC=1 SCAR=0.0
149 45008 ▶sub _map_names { @{ $_[0]{order} } }
Subroutine _map_names: called CC=1 SCAR=0.0
150 857 ▶sub _map_values { map { $_[0]{by}{$_} } @{ $_[0]{order} } }
Subroutine _map_values: called CC=1 SCAR=0.0
151  
152 21428 ▶sub _map_set {
Subroutine _map_set: called CC=2 SCAR=6.9
153 21428 my ( $m, $k, $v ) = @_;
154 21428 ▶ push @{ $m->{order} }, $k unless exists $m->{by}{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $m->{"by"}{$k} 21327 101 21428
155 21428 $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 386 ▶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 26285 ▶sub _read_config_file {
Subroutine _read_config_file: called CC=11 SCAR=24.1
182 26285 my ( $self, $file ) = @_;
183 26285 my $text;
184 26285 ▶ if ( -d $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $file) 1 26284 26285
185 1 $self->_fail( $file.': cannot read config (EISDIR: illegal operation on a directory, read)' );
186 }
187 26284 ▶ if ( open my $fh, '<:raw', $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, '<:raw', $file) { } 14761 11523 26284
188 14761 local $/;
189 14761 my $bytes = <$fh>;
190 14761 close $fh;
191 14761 ▶ $text = Skilletor::FSUtil::decode_utf8_lossy( $bytes // '' );
Condition50%1/2
$bytes // ""
l!l
147610
MC/DC0%0/1
$bytes // ""
$bytes
Truth table50%1/2
A
A= $bytes
Aresult
11
00
192 }
193 else {
194 11523 ▶ return js_ordered() if $!{ENOENT};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"ENOENT"} 11522 1 11523
195 1 $self->_fail( $file.': cannot read config ('.$self->_read_error( $file, 0 + $! ).')' );
196 }
197 14761 my $value;
198 14761 ▶ unless ( eval { $value = js_parse($text); 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $value = js_parse($text); 1 } }) 260 14501 14761
199 260 my $err = $@;
200 260 ▶ $self->_fail( $file.': invalid JSON ('.( ref $err && $err->can('message') ? $err->message : "$err" ).')' );
Branch: 1 branch
BranchTrueFalseTotal
ref $err && $err->can('message') ? : 260 0 260
Condition33%1/3
ref $err and $err->can("message")
!ll&&!rl&&r
00260
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 14501 ▶ $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 14498 14501
203 14498 for my $key ( keys %$value ) {
204 25783 ▶ next if $ALLOWED_KEY{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $ALLOWED_KEY{$key} 25781 2 25783
205 2 $self->_fail( $file.': unknown key "'.$key.'" (allowed: '.join( ', ', @ALLOWED_KEYS ).')' );
206 }
207 14496 return $value;
208 }
209  
210 85763 ▶sub _as_object {
Subroutine _as_object: called CC=3 SCAR=11.0
211 85763 my ( $self, $obj, $key, $file, $where ) = @_;
212 85763 ▶ return js_ordered() unless exists $obj->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $obj->{$key} 63992 21771 85763
213 21771 my $value = $obj->{$key};
214 21771 ▶ $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 21765 21771
215 21765 return $value;
216 }
217  
218 20939 ▶sub _has_backend {
Subroutine _has_backend: called CC=4 SCAR=13.9
219 20939 my ( $src ) = @_;
220 20939 ▶ 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'} ? : 20924 15 20939
Condition100%6/6
exists $src->{"git"} or exists $src->{"url"} or exists $src->{"local"}
l!l&&r!l&&!r
33721755215
exists $src->{"git"} or exists $src->{"url"}
l!l&&r!l&&!r
33601217567
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 25899 ▶sub _parse_sources {
Subroutine _parse_sources: called CC=7 SCAR=19.5
224 25899 my ( $self, $obj, $file, $origin, $unchecked ) = @_;
225 25899 my $sources = _map_new();
226 25899 my $raw = $self->_as_object( $obj, 'sources', $file, 'sources' );
227 25897 for my $name ( keys %$raw ) {
228 10747 ▶ if ( defined $unchecked && $name eq $unchecked ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $unchecked and $name eq $unchecked) 4 10743 10747
Condition100%3/3
defined $unchecked and $name eq $unchecked
!ll&&!rl&&r
1074214
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 10743 ▶ unless ( is_source_name($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_source_name($name)) 3 10740 10743
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 10740 my $fields = $self->source_fields( $raw->{$name}, $file.': sources.'.$name, 0 );
237 10710 my $src = { name => $name, origins => {}, %$fields };
238 10710 for my $kind (@BACKEND_KINDS) {
239 32130 ▶ $src->{origins}{$kind} = $origin if exists $src->{$kind};
Branch: 1 branch
BranchTrueFalseTotal
if exists $src->{$kind} 10694 21436 32130
240 }
241 10710 _map_set( $sources, $name, $src );
242 }
243 25864 return $sources;
244 }
245  
246 11390 ▶sub source_fields {
Subroutine source_fields: called CC=15 SCAR=27.1
Pod documented
247 11390 my ( $self, $def, $at, $needs_backend ) = @_;
248 11390 ▶ $needs_backend //= 1;
Condition100%2/2
$needs_backend //= 1
l!l
10740650
MC/DC100%1/1
$needs_backend //= 1
$needs_backend
Truth table100%2/2
A
A= $needs_backend
Aresult
11
00
249 11390 ▶ $self->_fail( $at.' must be an object' ) unless js_type($def) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($def) eq "object" 1 11389 11390
250 11389 for my $key ( keys %$def ) {
251 11427 ▶ $self->_fail( $at.': unknown key "'.$key.'"' ) unless $SOURCE_KEY{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $SOURCE_KEY{$key} 1 11426 11427
252 }
253 11388 my %src;
254 11388 ▶ $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"} 2168 9220 11388
255 # "ref": null is no ref: in a file of the merge it unsets a lower file's.
256 11384 ▶ if ( exists $def->{ref} && defined $def->{ref} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"ref"} and defined $def->{"ref"}) 30 11354 11384
Condition100%3/3
exists $def->{"ref"} and defined $def->{"ref"}
!ll&&!rl&&r
11350430
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 11377 ▶ $src{local} = $self->_string_field( $def->{local}, 'local', $at ) if exists $def->{local};
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"local"} 9164 2213 11377
260 11375 ▶ if ( exists $def->{url} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $def->{"url"}) 40 11335 11375
261 40 my $url = $def->{url};
262 40 ▶ unless ( js_type($url) eq 'string' && $url =~ m{\Ahttps://} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (js_type($url) eq "string" and $url =~ m[\Ahttps://]) 32 8 40
Condition100%3/3
js_type($url) eq "string" and $url =~ m[\Ahttps://]
!ll&&!rl&&r
2308
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 32 $self->_fail( $at.'.url '.js_stringify($url).' must be an https:// URL' );
264 }
265 8 $src{url} = $url;
266 }
267 11343 ▶ $src{path} = $self->_path_field( $def->{path}, $at ) if exists $def->{path};
Branch: 1 branch
BranchTrueFalseTotal
if exists $def->{"path"} 19 11324 11343
268 11331 ▶ if ( $needs_backend && !_has_backend( \%src ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($needs_backend and not _has_backend(\%src)) 0 11331 11331
Condition66%2/3
$needs_backend and not _has_backend(\%src)
!ll&&!rl&&r
107106210
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 11331 return \%src;
272 }
273  
274 11362 ▶sub _string_field {
Subroutine _string_field: called CC=4 SCAR=13.9
275 11362 my ( $self, $value, $key, $at ) = @_;
276 11362 my $where = $at.'.'.$key.' '.js_stringify($value);
277 11362 ▶ $self->_fail( $where.' must be a string' ) unless js_type($value) eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($value) eq "string" 4 11358 11362
278 11358 ▶ if ( $value eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value eq "") 3 11355 11358
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 11355 return $value;
282 }
283  
284 2193 ▶sub _git_field {
Subroutine _git_field: called CC=4 SCAR=13.9
285 2193 my ( $self, $value, $key, $at ) = @_;
286 2193 my $where = $at.'.'.$key.' '.js_stringify($value);
287 2193 ▶ $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 2191 2193
288 2191 ▶ if ( $key eq 'ref' && $value =~ $NOT_IN_REF ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "ref" and $value =~ /$NOT_IN_REF/) 4 2187 2191
Condition100%3/3
$key eq "ref" and $value =~ /$NOT_IN_REF/
!ll&&!rl&&r
2164234
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 2187 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 10714 ▶sub _merge_source {
Subroutine _merge_source: called CC=8 SCAR=20.8
325 10714 my ( $base, $incoming, $unset_ref ) = @_;
326 10714 ▶ my %merged = %{ $base // $incoming };
Condition66%2/3
$base // $incoming
l!l&&r!l&&!r
101106130
MC/DC0%0/2
$base // $incoming
$base $incoming
Truth table66%2/3
A // B
A= $baseB= $incoming
ABresult
1X1
011
000
327 10714 ▶ $merged{origins} = { %{ $base ? $base->{origins} : {} } };
Branch: 1 branch
BranchTrueFalseTotal
$base ? : 101 10613 10714
328 10714 ▶ if ( exists $incoming->{ref} ) { $merged{ref} = $incoming->{ref} }
Branch: 2 branches
BranchTrueFalseTotal
if (exists $incoming->{'ref'}) { } 23 10691 10714
elsif ($unset_ref) { } 4 10687 10691
329 4 elsif ($unset_ref) { delete $merged{ref} }
330 10714 ▶ $merged{path} = $incoming->{path} if exists $incoming->{path};
Branch: 1 branch
BranchTrueFalseTotal
if exists $incoming->{"path"} 7 10707 10714
331 10714 for my $kind (@BACKEND_KINDS) {
332 32142 ▶ next unless exists $incoming->{$kind};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $incoming->{$kind} 21448 10694 32142
333 10694 $merged{$kind} = $incoming->{$kind};
334 10694 $merged{origins}{$kind} = $incoming->{origins}{$kind};
335 }
336 10714 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 25758 ▶sub _parse_install {
Subroutine _parse_install: called CC=14 SCAR=26.4
346 25758 my ( $self, $obj, $file, $scope, $known, $overrides ) = @_;
347 25758 ▶ $overrides //= {};
Condition100%2/2
$overrides //= {}
l!l
897316785
MC/DC100%1/1
$overrides //= {}
$overrides
Truth table100%2/2
A
A= $overrides
Aresult
11
00
348 25758 my $install = $self->_as_object( $obj, 'install', $file, 'install' );
349 25757 my %install_keys = INSTALL_KEYS;
350 25757 for my $key ( keys %$install ) {
351 11825 ▶ next if exists $install_keys{$key} || $key eq BUNDLES_KEY;
Branch: 1 branch
BranchTrueFalseTotal
if exists $install_keys{$key} or $key eq "bundles" 11822 3 11825
Condition100%3/3
exists $install_keys{$key} or $key eq "bundles"
l!l&&r!l&&!r
114164063
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 25754 my ( @items, @wildcards, %seen );
355 25754 my @pairs = INSTALL_KEYS;
356 25754 ▶ while ( my ( $key, $type ) = splice @pairs, 0, 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@pairs, 0, 2)) 77227 25733 102960
357 77227 ▶ next unless exists $install->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $install->{$key} 65812 11415 77227
358 11415 my $list = $install->{$key};
359 11415 ▶ $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 11414 11415
360 11414 for my $i ( 0 .. $#$list ) {
361 13129 my $entry = $list->[$i];
362 13129 ▶ $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 13127 13129
363 13127 my $item = parse_entry( $entry, $type, $file, 'install.'.$key.'['.$i.']' );
364 13121 ▶ $self->_fail( $self->_override_use( $file, $entry, $item->{source} ) ) if $overrides->{ $item->{source} };
Branch: 1 branch
BranchTrueFalseTotal
if $$overrides{$item->{"source"}} 1 13120 13121
365 13120 ▶ unless ( _map_has( $known, $item->{source} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_map_has($known, $item->{"source"})) 7 13113 13120
366 7 $self->_fail( $file.': '.$scope.' install "'.$entry.'" references unknown source "'.$item->{source}.'"' );
367 }
368 13113 my $target_key = seen_key($item);
369 13113 ▶ if ( defined( my $prev = $seen{$target_key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $prev = $seen{$target_key})) 4 13109 13113
370 4 $self->_fail( $file.': duplicate '.$item->{type}.' target "'.$item->{name}.'" declared as '.$prev.' and '.$entry );
371 }
372 13109 $seen{$target_key} = $entry;
373 13109 ▶ if ( is_pattern( $item->{name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_pattern($item->{'name'})) { } 192 12917 13109
374 192 push @wildcards, { type => $item->{type}, source => $item->{source}, pattern => $item->{name}, raw => $entry };
375 }
376 else {
377 12917 push @items, $item;
378 }
379 }
380 }
381 25733 my $bundles = $self->_parse_bundles( $install, $file, $scope, $known, $overrides );
382 25724 return { install => \@items, wildcards => \@wildcards, bundles => $bundles };
383 }
384  
385 25733 ▶sub _parse_bundles {
Subroutine _parse_bundles: called CC=7 SCAR=19.5
386 25733 my ( $self, $install, $file, $scope, $known, $overrides ) = @_;
387 25733 ▶ return [] unless exists $install->{ BUNDLES_KEY() };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $install->{"bundles"} 25328 405 25733
388 405 my $list = $install->{ BUNDLES_KEY() };
389 405 ▶ $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 404 405
390 404 my @out;
391 404 for my $i ( 0 .. $#$list ) {
392 407 my $entry = $list->[$i];
393 407 my $where = 'install.'.BUNDLES_KEY.'['.$i.']';
394 407 ▶ $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 406 407
395 406 my $b = parse_bundle_entry( $entry, $file, $where );
396 402 ▶ $self->_fail( $self->_override_use( $file, $entry, $b->{source} ) ) if $overrides->{ $b->{source} };
Branch: 1 branch
BranchTrueFalseTotal
if $$overrides{$b->{"source"}} 1 401 402
397 401 ▶ unless ( _map_has( $known, $b->{source} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (_map_has($known, $b->{"source"})) 1 400 401
398 1 $self->_fail( $file.': '.$scope.' install "'.$entry.'" references unknown source "'.$b->{source}.'"' );
399 }
400 400 push @out, $b;
401 }
402 397 return $self->_dedupe_bundles( \@out, [], $file );
403 }
404  
405 8787 ▶sub _dedupe_bundles {
Subroutine _dedupe_bundles: called CC=3 SCAR=11.0
406 8787 my ( $self, $a, $b, $file ) = @_;
407 8787 my %seen;
408 8787 for my $x ( @$a, @$b ) {
409 557 my $key = $x->{name}.'@'.$x->{source};
410 557 ▶ if ( defined( my $prev = $seen{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $prev = $seen{$key})) 2 555 557
411 2 $self->_fail( $file.': duplicate bundle "'.$key.'" declared as '.$prev.' and '.$x->{raw} );
412 }
413 555 $seen{$key} = $x->{raw};
414 }
415 8785 return [ @$a, @$b ];
416 }
417  
418 8392 ▶sub _dedupe_across {
Subroutine _dedupe_across: called CC=3 SCAR=11.0
419 8392 my ( $self, $a, $b, $file ) = @_;
420 8392 my %seen;
421 8392 for my $item ( @$a, @$b ) {
422 5500 my $key = seen_key($item);
423 5500 ▶ if ( defined( my $prev = $seen{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $prev = $seen{$key})) 1 5499 5500
424 1 $self->_fail( $file.': duplicate '.$item->{type}.' target "'.$item->{name}.'" declared as '.$prev.' and '.$item->{raw} );
425 }
426 5499 $seen{$key} = $item->{raw};
427 }
428 8391 return [ @$a, @$b ];
429 }
430  
431 8391 ▶sub _dedupe_wildcards {
Subroutine _dedupe_wildcards: called CC=3 SCAR=11.0
432 8391 my ( $self, $a, $b, $file ) = @_;
433 8391 my %seen;
434 8391 for my $w ( @$a, @$b ) {
435 11 my $key = seen_key( { type => $w->{type}, name => $w->{pattern}, source => $w->{source} } );
436 11 ▶ if ( defined( my $prev = $seen{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $prev = $seen{$key})) 1 10 11
437 1 $self->_fail( $file.': duplicate '.$w->{type}.' wildcard for "'.$w->{source}.'" declared as '.$prev.' and '.$w->{raw} );
438 }
439 10 $seen{$key} = $w->{raw};
440 }
441 8390 return [ @$a, @$b ];
442 }
443  
444 17326 ▶sub _merge_vars {
Subroutine _merge_vars: called CC=3 SCAR=11.0
445 17326 my ( @objs ) = @_;
446 17326 my $out = js_ordered();
447 17326 for my $o (@objs) {
448 34100 $out->{$_} = $o->{$_} for keys %$o;
449 }
450 17326 return $out;
451 }
452  
453 25700 ▶sub _targets_of {
Subroutine _targets_of: called CC=8 SCAR=20.8
454 25700 my ( $self, $obj, $file ) = @_;
455 25700 ▶ return undef unless exists $obj->{targets};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $obj->{"targets"} 22426 3274 25700
456 3274 my $value = $obj->{targets};
457 3274 my $allowed = join ', ', HARNESSES;
458 3274 my %known = map { $_ => 1 } HARNESSES;
459 3274 ▶ unless ( js_type($value) eq 'array' && @$value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (js_type($value) eq "array" and @$value) 3 3271 3274
Condition100%3/3
js_type($value) eq "array" and @$value
!ll&&!rl&&r
213271
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 3271 my @out;
463 3271 for my $v (@$value) {
464 4390 ▶ unless ( js_type($v) eq 'string' && $known{$v} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (js_type($v) eq "string" and $known{$v}) 2 4388 4390
Condition100%3/3
js_type($v) eq "string" and $known{$v}
!ll&&!rl&&r
114388
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 4388 ▶ $self->_fail( $file.': "targets" lists "'.$v.'" twice' ) if grep { $_ eq $v } @out;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $v;} @out 1 4387 4388
468 4387 push @out, $v;
469 }
470 3268 return \@out;
471 }
472  
473 8976 ▶sub _number_or {
Subroutine _number_or: called CC=6 SCAR=18.0
474 8976 my ( $self, $obj, $key, $fallback, $file ) = @_;
475 8976 ▶ return $fallback unless exists $obj->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $obj->{$key} 8813 163 8976
476 163 my $value = $obj->{$key};
477 163 ▶ 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 160 163
Condition77%7/9
js_type($value) eq "number" and $value == $value and $value != "Inf" and $value != "-Inf"
!ll&&!rl&&r
30160
js_type($value) eq "number" and $value == $value and $value != "Inf"
!ll&&!rl&&r
21160
js_type($value) eq "number" and $value == $value
!ll&&!rl&&r
20161
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 160 return $value;
481 }
482  
483 # boolOr: $present says whether the value exists at all (JavaScript's undefined).
484 43031 ▶sub _bool_or {
Subroutine _bool_or: called CC=3 SCAR=11.0
485 43031 my ( $self, $present, $value, $fallback, $file, $key ) = @_;
486 43031 ▶ return $fallback unless $present;
Branch: 1 branch
BranchTrueFalseTotal
unless $present 41878 1153 43031
487 1153 ▶ $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 1146 1153
488 1146 return $value;
489 }
490  
491 9285 ▶sub _build__loaded {
Subroutine _build__loaded: called CC=30 SCAR=34.1
492 9285 my ( $self ) = @_;
493 9285 my $user_path = $self->user_path;
494 9285 my $has_project = $self->has_project;
495 9285 ▶ my $project_path = $has_project ? $self->project_path : '';
Branch: 1 branch
BranchTrueFalseTotal
$has_project ? : 8742 543 9285
496 9285 ▶ my $local_path = $has_project ? $self->local_path : '';
Branch: 1 branch
BranchTrueFalseTotal
$has_project ? : 8742 543 9285
497  
498 9285 my $user = $self->_read_config_file($user_path);
499 9062 ▶ my $project = $has_project ? $self->_read_config_file($project_path) : js_ordered();
Branch: 1 branch
BranchTrueFalseTotal
$has_project ? : 8521 541 9062
500 9020 ▶ my $local = $has_project ? $self->_read_config_file($local_path) : js_ordered();
Branch: 1 branch
BranchTrueFalseTotal
$has_project ? : 8479 541 9020
501 9018 for my $pair ( [ $project, $project_path ], [ $local, $local_path ] ) {
502 18035 my ( $obj, $p ) = @$pair;
503 18035 ▶ $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 18033 18035
Condition100%3/3
$p ne "" and exists $obj->{"checkInterval"}
!ll&&!rl&&r
1082169512
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 9016 my $unchecked = $self->unchecked;
509 35604 ▶ my $skip = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
510 35604 my ( $p ) = @_;
511 35604 ▶ return ( $unchecked && $unchecked->{path} eq $p ) ? $unchecked->{name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$unchecked && $unchecked->{'path'} eq $p ? : 7 35597 35604
Condition100%3/3
$unchecked and $unchecked->{"path"} eq $p
!ll&&!rl&&r
3558987
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 9016 };
513 9016 my $user_sources = $self->_parse_sources( $user, $user_path, 'user', $skip->($user_path) );
514 8983 ▶ my $project_sources = $has_project ? $self->_parse_sources( $project, $project_path, 'project', $skip->($project_path) ) : _map_new();
Branch: 1 branch
BranchTrueFalseTotal
$has_project ? : 8442 541 8983
515 8982 ▶ my $local_sources = $has_project ? $self->_parse_sources( $local, $local_path, 'user', $skip->($local_path) ) : _map_new();
Branch: 1 branch
BranchTrueFalseTotal
$has_project ? : 8441 541 8982
516  
517 # "ref": null in a file unsets the ref of the files below it.
518 9841 ▶ my $null_ref = sub {
Subroutine __ANON__: called CC=7 SCAR=20.5
519 9841 my ( $obj, $name ) = @_;
520 9841 ▶ my $s = exists $obj->{sources} ? $obj->{sources} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $obj->{'sources'} ? : 9841 0 9841
521 9841 ▶ 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 9841 9841
Condition33%1/3
js_type($s) eq "object" and exists $s->{$name}
!ll&&!rl&&r
009841
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 9841 my $d = $s->{$name};
523 9841 ▶ 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 9837 9841
Condition83%5/6
js_type($d) eq "object" and exists $d->{"ref"} and not defined $d->{"ref"}
!ll&&!rl&&r
9820174
js_type($d) eq "object" and exists $d->{"ref"}
!ll&&!rl&&r
0982021
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 8981 };
525 8981 my $sources = _map_new();
526 8981 _map_set( $sources, $_, _merge_source( undef, _map_get( $project_sources, $_ ) ) ) for _map_names($project_sources);
527 8981 for my $name ( _map_names($user_sources) ) {
528 9709 _map_set( $sources, $name, _merge_source( _map_get( $sources, $name ), _map_get( $user_sources, $name ), $null_ref->( $user, $name ) ) );
529 }
530 8981 for my $name ( _map_names($local_sources) ) {
531 132 _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 8981 for my $name ( _map_names($sources) ) {
537 10613 ▶ next if _has_backend( _map_get( $sources, $name ) );
Branch: 1 branch
BranchTrueFalseTotal
if _has_backend(_map_get($sources, $name)) 10604 9 10613
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 8976 my %overrides;
549 8976 for my $name ( _map_names($user_sources) ) {
550 9705 my $skipped = $skip->($user_path);
551 9705 ▶ 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 9701 4 9705
Condition83%5/6
_has_backend(_map_get($user_sources, $name)) or defined $skipped and $skipped eq $name
l!l&&r!l&&!r
969924
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 8976 my $check_interval = $self->_number_or( $user, 'checkInterval', 1800, $user_path );
558  
559 8973 my $true = JSON::MaybeXS::true();
560 8973 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 8940 vars => _merge_vars( $self->_as_object( $user, 'vars', $user_path, 'vars' ) ),
567 };
568 8939 $user_scope->{gitignore} = $self->_bool_or( exists $user->{gitignore}, $user->{gitignore}, $true, $user_path, 'gitignore' );
569 $user_scope->{claudeSettings} =
570 8937 $self->_bool_or( exists $user->{claudeSettings}, $user->{claudeSettings}, $true, $user_path, 'claudeSettings' );
571 8937 my $user_targets = $self->_targets_of( $user, $user_path );
572 8933 ▶ $user_scope->{targets} = $user_targets if $user_targets;
Branch: 1 branch
BranchTrueFalseTotal
if $user_targets 1582 7351 8933
573  
574 8933 my $project_scope;
575 8933 ▶ if ($has_project) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_project) 8393 540 8933
576 # Project install can be declared in the project file and the local file.
577 8393 my $project_install = $self->_parse_install( $project, $project_path, 'project', $sources );
578 8392 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 8392 bundles => $self->_dedupe_bundles( $project_install->{bundles}, $local_install->{bundles}, $project_path ),
584 };
585 8389 $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 8387 ▶ : ( 0, undef );
Branch: 2 branches
BranchTrueFalseTotal
exists $local->{'gitignore'} && defined $local->{'gitignore'} ? : 2 8385 8387
exists $project->{'gitignore'} ? : 1140 7245 8385
Condition100%3/3
exists $local->{"gitignore"} and defined $local->{"gitignore"}
!ll&&!rl&&r
838412
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 8387 $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 8385 $user_scope->{claudeSettings}, $project_path, 'claudeSettings' );
599 $project_scope->{claudeSettings} =
600 8383 $self->_bool_or( exists $local->{claudeSettings}, $local->{claudeSettings}, $from_project, $local_path, 'claudeSettings' );
601 8382 my $project_targets = $self->_targets_of( $project, $project_path );
602 8381 my $local_targets = $self->_targets_of( $local, $local_path );
603 8380 ▶ my $targets = $local_targets // $project_targets;
Condition100%3/3
$local_targets // $project_targets
l!l&&r!l&&!r
22814566696
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 8380 ▶ $project_scope->{targets} = $targets if $targets;
Branch: 1 branch
BranchTrueFalseTotal
if $targets 1684 6696 8380
605 }
606  
607 return {
608 8920 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 1349 ▶sub _load_raw {
Subroutine _load_raw: called CC=6 SCAR=18.1
622 1349 my ( $self, $file ) = @_;
623 1349 ▶ return js_ordered() unless -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 268 1081 1349
624 1081 my $value = eval {
625 1081 my $v = js_parse( read_text($file) );
626 1080 ▶ 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 1079 1080
627 1079 $v;
628 };
629 1081 ▶ unless ($value) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value) 2 1079 1081
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 1079 return $value;
634 }
635  
636 521 ▶sub _save_raw {
Subroutine _save_raw: called CC=1 SCAR=0.0
637 521 my ( $self, $file, $cfg ) = @_;
638 521 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 203 ▶sub _source_def {
Subroutine _source_def: called CC=3 SCAR=16.5
643 203 my ( $def ) = @_;
644 203 ▶ return $def if tied %$def;
Branch: 1 branch
BranchTrueFalseTotal
if tied %$def 203 0 203
645 0 ▶ return js_ordered( map { exists $def->{$_} ? ( $_ => $def->{$_} ) : () } @SOURCE_FIELD_ORDER );
Branch: 1 branch
BranchTrueFalseTotal
exists $def->{$_} ? : 0 0 0
646 }
647  
648 43 ▶sub source_entry {
Subroutine source_entry: called CC=3 SCAR=11.0
Pod documented
649 43 my ( $self, $file, $name ) = @_;
650 43 my $sources = $self->_load_raw($file)->{sources};
651 42 ▶ 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 41 42
Condition66%2/3
js_type($sources) eq "object" and exists $sources->{$name}
!ll&&!rl&&r
0141
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 41 return $sources->{$name};
653 }
654  
655 # Does the file declare source $name โ€“ the reference's sourceEntry(...) !== undefined, which
656 # tells an entry written as null from none at all (source_entry is undef for both)?
657 677 ▶sub has_source_entry {
Subroutine has_source_entry: called CC=3 SCAR=11.0
Pod documented
658 677 my ( $self, $file, $name ) = @_;
659 677 my $sources = $self->_load_raw($file)->{sources};
660 677 ▶ return ( js_type($sources) eq 'object' && exists $sources->{$name} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
js_type($sources) eq 'object' && exists $sources->{$name} ? : 120 557 677
Condition100%3/3
js_type($sources) eq "object" and exists $sources->{$name}
!ll&&!rl&&r
213344120
MC/DC100%2/2
js_type($sources) eq "object" and exists $sources->{$name}
js_type($sources) eq "object" exists $sources->{$name}
Truth table100%3/3
A and B
A= js_type($sources) eq "object"B= exists $sources->{$name}
ABresult
0X0
100
111
661 }
662  
663 204 ▶sub add_source {
Subroutine add_source: called CC=3 SCAR=11.0
Pod documented
664 204 my ( $self, $file, $name, $def ) = @_;
665 204 my $cfg = $self->_load_raw($file);
666 203 ▶ my $sources = defined $cfg->{sources} ? $cfg->{sources} : js_ordered();
Branch: 1 branch
BranchTrueFalseTotal
defined $cfg->{'sources'} ? : 147 56 203
667 203 ▶ $sources->{$name} = _source_def($def) if js_type($sources) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
if js_type($sources) eq "object" 203 0 203
668 203 $cfg->{sources} = $sources;
669 203 $self->_save_raw( $file, $cfg );
670 }
671  
672 3 ▶sub remove_source {
Subroutine remove_source: called CC=4 SCAR=14.2
Pod documented
673 3 my ( $self, $file, $name ) = @_;
674 3 my $cfg = $self->_load_raw($file);
675 3 my $sources = $cfg->{sources};
676 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
677 3 delete $sources->{$name};
678 3 ▶ delete $cfg->{sources} unless keys %$sources;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$sources 1 2 3
679 3 $self->_save_raw( $file, $cfg );
680 }
681 }
682  
683 9 ▶sub add_install_entry {
Subroutine add_install_entry: called CC=6 SCAR=18.1
Pod documented
684 9 my ( $self, $file, $type, $entry ) = @_;
685 9 my $cfg = $self->_load_raw($file);
686 9 ▶ my $install = defined $cfg->{install} ? $cfg->{install} : js_ordered();
Branch: 1 branch
BranchTrueFalseTotal
defined $cfg->{'install'} ? : 3 6 9
687 9 my $key = INSTALL_KEY_OF->{$type};
688 9 ▶ my $list = js_type( $install->{$key} ) eq 'array' ? $install->{$key} : [];
Branch: 1 branch
BranchTrueFalseTotal
js_type($install->{$key}) eq 'array' ? : 2 7 9
689 9 ▶ push @$list, $entry unless grep { defined $_ && !ref $_ && $_ eq $entry } @$list;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {defined $_ and not ref $_ and $_ eq $entry;} @$list 8 1 9
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
690 9 $install->{$key} = $list;
691 9 $cfg->{install} = $install;
692 9 $self->_save_raw( $file, $cfg );
693 }
694  
695 # Does raw entry $e ([type:]name@source) declare $name (from $source, if given)? A name
696 # matches ignoring case; a pattern is the entry as written.
697 82 ▶sub _entry_matches {
Subroutine _entry_matches: called CC=9 SCAR=22.1
698 82 my ( $e, $name, $source ) = @_;
699 82 my $at = rindex $e, '@';
700 82 ▶ ( my $e_name = $at > 0 ? substr( $e, 0, $at ) : $e ) =~ s/\A[a-z]+://;
Branch: 1 branch
BranchTrueFalseTotal
$at > 0 ? : 82 0 82
701 82 ▶ my $e_source = $at > 0 ? substr( $e, $at + 1 ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$at > 0 ? : 82 0 82
702 82 ▶ 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) ? : 28 54 82
Condition100%3/3
is_pattern($name) or is_pattern($e_name)
l!l&&r!l&&!r
52354
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
703 82 ▶ 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) ? : 45 37 82
Condition88%8/9
$same and !defined($source) || defined $e_source && $e_source eq $source
!ll&&!rl&&r
36145
not defined $source or defined $e_source and $e_source eq $source
l!l&&r!l&&!r
5401
defined $e_source and $e_source eq $source
!ll&&!rl&&r
0140
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
704 }
705  
706 41 ▶sub find_install_entries {
Subroutine find_install_entries: called CC=9 SCAR=22.2
Pod documented
707 41 my ( $self, $file, $name, $source, $type ) = @_;
708 41 my $install = $self->_load_raw($file)->{install};
709 41 ▶ return [] unless $install;
Branch: 1 branch
BranchTrueFalseTotal
unless $install 0 41 41
710 41 my @out;
711 41 ▶ for my $t ( $type ? ($type) : (ITEM_TYPES) ) {
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 8 33 41
712 107 ▶ my $list = js_type($install) eq 'object' ? $install->{ INSTALL_KEY_OF->{$t} } : undef;
Branch: 1 branch
BranchTrueFalseTotal
js_type($install) eq 'object' ? : 107 0 107
713 107 ▶ next unless js_type($list) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($list) eq "array" 62 45 107
714 45 for my $e (@$list) {
715 49 ▶ 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) 24 25 49
Condition66%2/3
js_type($e) eq "string" and _entry_matches($e, $name, $source)
!ll&&!rl&&r
02524
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
716 }
717 }
718 41 return \@out;
719 }
720  
721 21 ▶sub remove_install_entries {
Subroutine remove_install_entries: called CC=11 SCAR=24.1
Pod documented
722 21 my ( $self, $file, $name, $source, $type ) = @_;
723 21 my $cfg = $self->_load_raw($file);
724 21 my $install = $cfg->{install};
725 21 ▶ return 0 unless $install && js_type($install) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
unless $install and js_type($install) eq "object" 0 21 21
Condition33%1/3
$install and js_type($install) eq "object"
!ll&&!rl&&r
0021
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
726 21 my $removed = 0;
727 21 ▶ for my $key ( $type ? ( INSTALL_KEY_OF->{$type} ) : map { INSTALL_KEY_OF->{$_} } ITEM_TYPES ) {
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 8 13 21
728 47 my $list = $install->{$key};
729 47 ▶ next unless js_type($list) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($list) eq "array" 20 27 47
730 my @kept = grep {
731 27 ▶ my $match = js_type($_) eq 'string' && _entry_matches( $_, $name, $source );
Condition100%3/3
js_type($_) eq 'string' && _entry_matches($_, $name, $source)
!ll&&!rl&&r
11221
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
732 34 ▶ $removed++ if $match;
Branch: 1 branch
BranchTrueFalseTotal
if $match 21 13 34
733 34 !$match;
734 } @$list;
735 27 ▶ if (@kept) { $install->{$key} = \@kept }
Branch: 1 branch
BranchTrueFalseTotal
if (@kept) { } 12 15 27
736 15 else { delete $install->{$key} }
737 }
738 21 ▶ delete $cfg->{install} unless keys %$install;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$install 2 19 21
739 21 ▶ $self->_save_raw( $file, $cfg ) if $removed;
Branch: 1 branch
BranchTrueFalseTotal
if $removed 21 0 21
740 21 return $removed;
741 }
742  
743 30 ▶sub find_wildcard_entries {
Subroutine find_wildcard_entries: called CC=11 SCAR=25.1
Pod documented
744 30 my ( $self, $file, $source, $type ) = @_;
745 30 my $install = $self->_load_raw($file)->{install};
746 30 ▶ return [] unless $install && js_type($install) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
unless $install and js_type($install) eq "object" 0 30 30
Condition33%1/3
$install and js_type($install) eq "object"
!ll&&!rl&&r
0030
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
747 30 my @out;
748 30 ▶ for my $t ( $type ? ($type) : (ITEM_TYPES) ) {
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 6 24 30
749 78 my $list = $install->{ INSTALL_KEY_OF->{$t} };
750 78 ▶ next unless js_type($list) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($list) eq "array" 43 35 78
751 35 for my $e (@$list) {
752 39 ▶ next unless js_type($e) eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($e) eq "string" 0 39 39
753 39 my $at = rindex $e, '@';
754 39 ▶ 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 39 39
Condition33%1/3
$at <= 0 or substr($e, $at + 1) ne $source
l!l&&r!l&&!r
0039
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
755 39 ( my $pattern = substr( $e, 0, $at ) ) =~ s/\A[a-z]+://;
756 39 ▶ push @out, { type => $t, entry => $e, pattern => $pattern } if is_pattern($pattern);
Branch: 1 branch
BranchTrueFalseTotal
if is_pattern($pattern) 15 24 39
757 }
758 }
759 30 return \@out;
760 }
761  
762 301 ▶sub _bundle_parts {
Subroutine _bundle_parts: called CC=2 SCAR=7.0
763 301 my ( $e ) = @_;
764 301 my $at = rindex $e, '@';
765 301 ▶ return undef if $at <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $at <= 0 0 301 301
766 301 ( my $name = substr( $e, 0, $at ) ) =~ s/\Abundle://;
767 301 return { name => $name, source => substr( $e, $at + 1 ) };
768 }
769  
770 36 ▶sub bundle_entries {
Subroutine bundle_entries: called CC=7 SCAR=20.5
Pod documented
771 36 my ( $self, $file ) = @_;
772 36 my $install = $self->_load_raw($file)->{install};
773 36 ▶ my $list = ( $install && js_type($install) eq 'object' ) ? $install->{ BUNDLES_KEY() } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$install && js_type($install) eq 'object' ? : 36 0 36
Condition33%1/3
$install and js_type($install) eq "object"
!ll&&!rl&&r
0036
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
774 36 ▶ return [] unless js_type($list) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($list) eq "array" 21 15 36
775 15 my @out;
776 15 for my $e (@$list) {
777 15 ▶ my $p = js_type($e) eq 'string' ? _bundle_parts($e) : undef;
Branch: 1 branch
BranchTrueFalseTotal
js_type($e) eq 'string' ? : 15 0 15
778 15 ▶ push @out, { %$p, entry => $e } if $p;
Branch: 1 branch
BranchTrueFalseTotal
if $p 15 0 15
779 }
780 15 return \@out;
781 }
782  
783 282 ▶sub add_bundle_entry {
Subroutine add_bundle_entry: called CC=8 SCAR=21.6
Pod documented
784 282 my ( $self, $file, $entry ) = @_;
785 282 my $cfg = $self->_load_raw($file);
786 282 ▶ my $install = defined $cfg->{install} ? $cfg->{install} : js_ordered();
Branch: 1 branch
BranchTrueFalseTotal
defined $cfg->{'install'} ? : 13 269 282
787 282 ▶ my $list = js_type( $install->{ BUNDLES_KEY() } ) eq 'array' ? $install->{ BUNDLES_KEY() } : [];
Branch: 1 branch
BranchTrueFalseTotal
js_type($install->{'bundles'}) eq 'array' ? : 1 281 282
788 282 ▶ 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") 282 0 282
789 my $known = grep {
790 282 ▶ my $q = js_type($_) eq 'string' ? _bundle_parts($_) : undef;
Branch: 1 branch
BranchTrueFalseTotal
js_type($_) eq 'string' ? : 1 0 1
791 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
792 } @$list;
793 282 ▶ push @$list, $entry unless $known;
Branch: 1 branch
BranchTrueFalseTotal
unless $known 281 1 282
794 282 $install->{ BUNDLES_KEY() } = $list;
795 282 $cfg->{install} = $install;
796 282 $self->_save_raw( $file, $cfg );
797 }
798  
799 3 ▶sub remove_bundle_entries {
Subroutine remove_bundle_entries: called CC=10 SCAR=26.4
Pod documented
800 3 my ( $self, $file, $name, $source ) = @_;
801 3 my $cfg = $self->_load_raw($file);
802 3 my $install = $cfg->{install};
803 3 ▶ return 0 unless $install && js_type($install) eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
unless $install and js_type($install) eq "object" 0 3 3
Condition33%1/3
$install and js_type($install) eq "object"
!ll&&!rl&&r
003
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
804 3 my $list = $install->{ BUNDLES_KEY() };
805 3 ▶ return 0 unless js_type($list) eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
unless js_type($list) eq "array" 0 3 3
806 my @kept = grep {
807 3 ▶ my $p = js_type($_) eq 'string' ? _bundle_parts($_) : undef;
Branch: 1 branch
BranchTrueFalseTotal
js_type($_) eq 'string' ? : 3 0 3
808 3 ▶ !( $p && $p->{name} eq $name && $p->{source} eq $source );
Condition33%2/6
$p && $p->{'name'} eq $name && $p->{'source'} eq $source
!ll&&!rl&&r
003
$p and $p->{"name"} eq $name
!ll&&!rl&&r
003
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
809 } @$list;
810 3 my $removed = @$list - @kept;
811 3 ▶ return 0 unless $removed;
Branch: 1 branch
BranchTrueFalseTotal
unless $removed 0 3 3
812 0 ▶ if (@kept) { $install->{ BUNDLES_KEY() } = \@kept }
Branch: 1 branch
BranchTrueFalseTotal
if (@kept) { } 0 3 3
813 3 else { delete $install->{ BUNDLES_KEY() } }
814 3 ▶ delete $cfg->{install} unless keys %$install;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$install 3 0 3
815 3 $self->_save_raw( $file, $cfg );
816 3 return $removed;
817 }
818  
819 413 1;
820  
821 __END__
« lib/Skilletor/CLI.pm ↑ Summary lib/Skilletor/FSUtil.pm »