| 1 | package Skilletor::Targets; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Which agent harnesses a sync installs for (detection and the targets merge) | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 33 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 33 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 33 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 33 | ▶ | use Skilletor::Entry qw( HARNESSES ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 33 | ▶ | use Skilletor::Error::Target; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 33 | ▶ | use Skilletor::FSUtil qw( path_join ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 33 | ▶ | use Skilletor::JSString qw( js_trim ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 33 | ▶ | use Skilletor::Lock qw( parse_lock_key ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 33 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 33 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 17 | DETECTED default_markers detect_harnesses select_targets default_hermes_home | ||||||||||||||||||||||||||||||||||||||||||
| 18 | lock_key supports root_of root_of_key served_via receivers is_block_type is_local_type all_roots target_gaps | ||||||||||||||||||||||||||||||||||||||||||
| 19 | place_output lacks_local_prefix | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # Only Claude and Codex are detected; Hermes is a target only when `targets` names it. | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 33 | ▶ | use constant DETECTED => qw( claude codex ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # $claude_config_dir: an explicit CLAUDE_CONFIG_DIR, inside which Claude Code keeps its .claude.json. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 269 | ▶ | sub default_markers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_markers: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 269 | my ( $home, $codex_home, $claude_config_dir ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 269 | ▶ | my $cx = ( defined $codex_home && length $codex_home ) ? $codex_home : path_join( $home, '.codex' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $codex_home and length $codex_home
MC/DC100%2/2
defined $codex_home and length $codex_home
defined $codex_home
length $codex_home
Truth table100%3/3
A and B
A= defined $codex_homeB= length $codex_home
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | claude => ( defined $claude_config_dir && length $claude_config_dir ) | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | ? [ map { path_join( $claude_config_dir, $_ ) } qw( .claude.json settings.json projects ) ] | |||||||||||||||||||||||||||||||||||||||||
| 32 | : [ path_join( $home, '.claude.json' ), path_join( $home, '.claude', 'settings.json' ), path_join( $home, '.claude', 'projects' ) ], | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 269 | ▶ | codex => [ map { path_join( $cx, $_ ) } qw( config.toml auth.json sessions installation_id ) ], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $claude_config_dir and length $claude_config_dir
MC/DC50%1/2
defined $claude_config_dir and length $claude_config_dir
defined $claude_config_dir
length $claude_config_dir
Truth table66%2/3
A and B
A= defined $claude_config_dirB= length $claude_config_dir
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 333 | ▶ | sub detect_harnesses { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
detect_harnesses: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 333 | my ( $markers ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 333 | ▶ | return [ grep { my $h = $_; grep { -e $_ } @{ $markers->{$h} // [] } } DETECTED ]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$markers->{$h} // []
MC/DC0%0/1
$markers->{$h} // []
$markers->{$h}
Truth table50%1/2
A
A= $markers->{$h}
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # Hermes' default home: ~/.hermes; on native Windows %LOCALAPPDATA%\hermes. | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 101 | ▶ | sub default_hermes_home { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_hermes_home: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 101 | my ( $home, $platform, $env ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 101 | ▶ | $platform //= $^O; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$platform //= $^O
MC/DC0%0/2
$platform //= $^O
$platform
$^O
Truth table66%2/3
A //= B
A= $platformB= $^O
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 101 | ▶ | $env //= \%ENV; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$env //= \%ENV
MC/DC100%1/1
$env //= \%ENV
$env
Truth table100%2/2
A
A= $env
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 101 | ▶ | return path_join( $home, '.hermes' ) unless $platform eq 'MSWin32'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | ▶ | my $local = js_trim( $env->{LOCALAPPDATA} // '' ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$env->{"LOCALAPPDATA"} // ""
MC/DC0%0/1
$env->{"LOCALAPPDATA"} // ""
$env->{"LOCALAPPDATA"}
Truth table50%1/2
A
A= $env->{"LOCALAPPDATA"}
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | $local = $home.'\\AppData\\Local' unless length $local; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | ( my $joined = $local.'\\hermes' ) =~ s{[\\/]+}{\\}g; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | return $joined; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # The merge rule (spec §14.1): machine = user targets // detected (empty is an error); the user | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # scope gets the machine set; the project scope the machine set narrowed to the project's. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 337 | ▶ | sub select_targets { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select_targets: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 337 | my ( $configured, $detected, $markers ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 337 | ▶ | my $machine = $configured->{user} // $detected; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$configured->{"user"} // $detected
MC/DC0%0/2
$configured->{"user"} // $detected
$configured->{"user"}
$detected
Truth table66%2/3
A // B
A= $configured->{"user"}B= $detected
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 337 | ▶ | unless (@$machine) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | my $looked = $markers | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 266 | ▶ | ? ' (looked for '.join( '; ', map { $_.': '.join( ', ', @{ $markers->{$_} } ) } grep { $markers->{$_} } DETECTED ).')' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | : ''; | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 266 | Skilletor::Error::Target->throw( 'no agent harness detected'.$looked | |||||||||||||||||||||||||||||||||||||||||
| 64 | .'; set "targets": ["claude"], "codex" and/or "hermes" in ~/.claude/skilletor.json' ); | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 71 | my @warnings; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 71 | my $project = [@$machine]; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 71 | ▶ | if ( my $want = $configured->{project} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | my %in = map { $_ => 1 } @$want; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | $project = [ grep { $in{$_} } @$machine ]; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 5 | ▶ | unless (@$project) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 4 | push @warnings, 'project targets ('.join( ', ', @$want ).') are not in use on this machine ' | |||||||||||||||||||||||||||||||||||||||||
| 73 | .'('.join( ', ', @$machine ).'); nothing is installed for the project'; | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 71 | return { user => [@$machine], project => $project, warnings => \@warnings }; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | #### The layout table (spec §14.2, §16.2) ############################## | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # Where each harness reads each item type. The Perl port writes for Claude Code alone, but the | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # table is whole: the managed blocks list every harness's roots (spec §6.4), and lock keys of | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # every harness are parsed, kept or reported as the reference does. | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 34 | ▶ | sub _under { my ( $dir ) = @_; return sub { path_join( $_[0]{base}, $dir ) } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
_under: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 199 | ▶ | sub _claude_root { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_claude_root: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 199 | my ( $r ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 199 | ▶ | return ( $r->{scope} eq 'user' && defined $r->{claude_dir} && length $r->{claude_dir} ) ? $r->{claude_dir} : path_join( $r->{base}, '.claude' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$r->{"scope"} eq "user" and defined $r->{"claude_dir"} and length $r->{"claude_dir"}
$r->{"scope"} eq "user" and defined $r->{"claude_dir"}
MC/DC33%1/3
$r->{"scope"} eq "user" and defined $r->{"claude_dir"} and length $r->{"claude_dir"}
$r->{"scope"} eq "user"
defined $r->{"claude_dir"}
length $r->{"claude_dir"}
Truth table50%2/4
A and B and C
A= $r->{"scope"} eq "user"B= defined $r->{"claude_dir"}C= length $r->{"claude_dir"}
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 94 | ▶ | sub _codex_home_dir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_codex_home_dir: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 94 | my ( $r ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 94 | ▶ | return ( defined $r->{codex_home} && length $r->{codex_home} ) ? $r->{codex_home} : path_join( $r->{base}, '.codex' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $r->{"codex_home"} and length $r->{"codex_home"}
MC/DC0%0/2
defined $r->{"codex_home"} and length $r->{"codex_home"}
defined $r->{"codex_home"}
length $r->{"codex_home"}
Truth table33%1/3
A and B
A= defined $r->{"codex_home"}B= length $r->{"codex_home"}
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 118 | ▶ | sub _codex_root { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_codex_root: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 118 | my ( $r ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 118 | ▶ | return $r->{scope} eq 'user' ? _codex_home_dir($r) : path_join( $r->{base}, '.codex' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | ▶ | sub _hermes_root { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hermes_root: called CC=4 SCAR=22.5
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | my ( $r ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | ▶ | return path_join( $r->{base}, '.hermes' ) unless $r->{scope} eq 'user'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | return ( defined $r->{hermes_home} && length $r->{hermes_home} ) ? $r->{hermes_home} : default_hermes_home( $r->{base} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $r->{"hermes_home"} and length $r->{"hermes_home"}
MC/DC0%0/2
defined $r->{"hermes_home"} and length $r->{"hermes_home"}
defined $r->{"hermes_home"}
length $r->{"hermes_home"}
Truth table0%0/3
A and B
A= defined $r->{"hermes_home"}B= length $r->{"hermes_home"}
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | # roots: [ type => root function ] in the reference's order. | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 33 | my %LAYOUTS = ( | |||||||||||||||||||||||||||||||||||||||||
| 110 | claude => { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | prefix => '', | ||||||||||||||||||||||||||||||||||||||||||
| 112 | roots => [ skill => \&_claude_root, agent => \&_claude_root, rule => \&_claude_root ], | ||||||||||||||||||||||||||||||||||||||||||
| 113 | local_types => { agent => 1, rule => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 115 | codex => { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | prefix => 'codex:', | ||||||||||||||||||||||||||||||||||||||||||
| 117 | roots => [ skill => _under('.agents'), agent => \&_codex_root, rule => \&_codex_root ], | ||||||||||||||||||||||||||||||||||||||||||
| 118 | block_types => { rule => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | local_types => { agent => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | hermes => { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | prefix => 'hermes:', | ||||||||||||||||||||||||||||||||||||||||||
| 123 | roots => [ skill => \&_hermes_root ], | ||||||||||||||||||||||||||||||||||||||||||
| 124 | project_via => { skill => 'codex' }, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | no_gitignore_block => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 522 | ▶ | sub _root_fn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_root_fn: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 522 | my ( $harness, $type ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 522 | my @pairs = @{ $LAYOUTS{$harness}{roots} }; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 522 | ▶ | while ( my ( $t, $fn ) = splice @pairs, 0, 2 ) { return $fn if $t eq $type } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 12 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 177 | ▶ | sub lock_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lock_key: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 177 | my ( $harness, $target ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 177 | return $LAYOUTS{$harness}{prefix}.$target; | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 303 | ▶ | sub supports { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supports: called CC=3 SCAR=13.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 303 | my ( $harness, $type ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 303 | ▶ | return ( $LAYOUTS{$harness} && _root_fn( $harness, $type ) ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$LAYOUTS{$harness} and _root_fn($harness, $type)
MC/DC0%0/2
$LAYOUTS{$harness} and _root_fn($harness, $type)
$LAYOUTS{$harness}
_root_fn($harness, $type)
Truth table33%1/3
A and B
A= $LAYOUTS{$harness}B= _root_fn($harness, $type)
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 219 | ▶ | sub root_of { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
root_of: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 219 | my ( $rc, $harness, $type ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 219 | ▶ | my $fn = _root_fn( $harness, $type ) or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 207 | return $fn->($rc); | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 112 | ▶ | sub root_of_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
root_of_key: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 112 | my ( $rc, $key ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 112 | my $k = parse_lock_key($key); | |||||||||||||||||||||||||||||||||||||||||
| 155 | 112 | ▶ | return defined $k->{harness} ? root_of( $rc, $k->{harness}, $k->{type} ) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 221 | ▶ | sub served_via { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
served_via: called CC=5 SCAR=21.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 221 | my ( $active, $harness, $type, $scope ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 221 | ▶ | my $via = $scope eq 'project' ? ( $LAYOUTS{$harness}{project_via} // {} )->{$type} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$LAYOUTS{$harness}{"project_via"} // {}
MC/DC0%0/1
$LAYOUTS{$harness}{"project_via"} // {}
$LAYOUTS{$harness}{"project_via"}
Truth table0%0/2
A
A= $LAYOUTS{$harness}{"project_via"}
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | return ( defined $via && grep { $_ eq $via } @$active ) ? $via : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $via and grep {$_ eq $via;} @$active
MC/DC0%0/2
defined $via and grep {$_ eq $via;} @$active
defined $via
grep {$_ eq $via;} @$active
Truth table33%1/3
A and B
A= defined $viaB= grep {$_ eq $via;} @$active
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 221 | ▶ | sub receivers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
receivers: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 221 | my ( $active, $type, $scope ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 221 | ▶ | return [ grep { supports( $_, $type ) && !defined served_via( $active, $_, $type, $scope ) } @$active ]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
supports($_, $type) && !defined(served_via($active, $_, $type, $scope))
MC/DC0%0/2
supports($_, $type) && !defined(served_via($active, $_, $type, $scope))
supports($_, $type)
!defined(served_via($active, $_, $type, $scope))
Truth table33%1/3
A && not(B)
A= supports($_, $type)B= !defined(served_via($active, $_, $type, $scope))
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 73 | ▶ | sub is_block_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_block_type: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 73 | my ( $harness, $type ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 73 | ▶ | return ( $LAYOUTS{$harness}{block_types} // {} )->{$type} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$LAYOUTS{$harness}{"block_types"} // {}
MC/DC100%1/1
$LAYOUTS{$harness}{"block_types"} // {}
$LAYOUTS{$harness}{"block_types"}
Truth table100%2/2
A
A= $LAYOUTS{$harness}{"block_types"}
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 90 | ▶ | sub is_local_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_local_type: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 90 | my ( $harness, $type ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 90 | ▶ | return ( $LAYOUTS{$harness}{local_types} // {} )->{$type} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$LAYOUTS{$harness}{"local_types"} // {}
MC/DC0%0/1
$LAYOUTS{$harness}{"local_types"} // {}
$LAYOUTS{$harness}{"local_types"}
Truth table50%1/2
A
A= $LAYOUTS{$harness}{"local_types"}
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | # Every distinct root of a scope that can hold a gitignore block, in the reference's order. | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 25 | ▶ | sub all_roots { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all_roots: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 25 | my ( $rc ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 25 | my ( %seen, @out ); | |||||||||||||||||||||||||||||||||||||||||
| 183 | 25 | for my $h (HARNESSES) { | |||||||||||||||||||||||||||||||||||||||||
| 184 | 75 | ▶ | next if $LAYOUTS{$h}{no_gitignore_block}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 50 | my @pairs = @{ $LAYOUTS{$h}{roots} }; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 50 | ▶ | while ( my ( undef, $fn ) = splice @pairs, 0, 2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 150 | my $root = $fn->($rc); | |||||||||||||||||||||||||||||||||||||||||
| 188 | 150 | ▶ | push @out, $root unless $seen{$root}++; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 25 | return @out; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | # Where the lock disagrees with the active targets: an entry of a harness that gets no copy | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # (`key` alone), or an item an active receiving harness lacks (`missing`). | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 36 | ▶ | sub target_gaps { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
target_gaps: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 36 | my ( $keys, $active, $scope ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 36 | ▶ | $scope //= 'user'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$scope //= "user"
MC/DC0%0/1
$scope //= "user"
$scope
Truth table50%1/2
A
A= $scope
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 36 | my %set = map { $_ => 1 } @$keys; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 36 | my @gaps; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 36 | for my $key (@$keys) { | |||||||||||||||||||||||||||||||||||||||||
| 202 | 44 | my $k = parse_lock_key($key); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 44 | ▶ | next unless defined $k->{harness} && supports( $k->{harness}, $k->{type} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $k->{"harness"} and supports($k->{"harness"}, $k->{"type"})
MC/DC50%1/2
defined $k->{"harness"} and supports($k->{"harness"}, $k->{"type"})
defined $k->{"harness"}
supports($k->{"harness"}, $k->{"type"})
Truth table66%2/3
A and B
A= defined $k->{"harness"}B= supports($k->{"harness"}, $k->{"type"})
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 41 | my $receiving = receivers( $active, $k->{type}, $scope ); | |||||||||||||||||||||||||||||||||||||||||
| 205 | 41 | ▶ | unless ( grep { $_ eq $k->{harness} } @$receiving ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 3 | push @gaps, { key => $key }; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 38 | for my $h (@$receiving) { | |||||||||||||||||||||||||||||||||||||||||
| 210 | 38 | my $missing = lock_key( $h, $k->{target} ); | |||||||||||||||||||||||||||||||||||||||||
| 211 | 38 | ▶ | push @gaps, { key => $key, missing => $missing } unless $set{$missing}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 36 | return \@gaps; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 33 | ▶ | use constant LOCAL_PREFIX => '.local.'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 5 | ▶ | sub _cut { my ( $rel ) = @_; my $s = rindex( $rel, '/' ); my $b = rindex( $rel, '\\' ); return ( $s > $b ? $s : $b ) + 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_cut: called CC=2 SCAR=7.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | # An item's output as the harness installs it: `.local.` file names for its local types, and | ||||||||||||||||||||||||||||||||||||||||||
| 222 | # the plain paths the item still claims. $output: [ [ rel, bytes ], ... ]. | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 31 | ▶ | sub place_output { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
place_output: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 31 | my ( $harness, $type, $output ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 31 | ▶ | return { output => $output, claims => [] } unless is_local_type( $harness, $type ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | my ( @placed, @claims ); | |||||||||||||||||||||||||||||||||||||||||
| 227 | 3 | for my $pair (@$output) { | |||||||||||||||||||||||||||||||||||||||||
| 228 | 3 | my ( $rel, $bytes ) = @$pair; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 3 | my $cut = _cut($rel); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 3 | push @placed, [ substr( $rel, 0, $cut ).LOCAL_PREFIX.substr( $rel, $cut ), $bytes ]; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 3 | push @claims, $rel; | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 3 | return { output => \@placed, claims => \@claims }; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 41 | ▶ | sub lacks_local_prefix { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lacks_local_prefix: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 41 | my ( $harness, $type, $paths ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 41 | ▶ | return 0 unless is_local_type( $harness, $type ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | ▶ | return ( grep { index( substr( $_, _cut($_) ), LOCAL_PREFIX ) != 0 } @$paths ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 33 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | __END__ | ||||||||||||||||||||||||||||||||||||||||||