| 1 | package LibTmux::Snapshot; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use v5.44; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use LibTmux::Schema; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use LibTmux::Selection; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use LibTmux::PaneSelection; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use LibTmux::WindowSelection; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use LibTmux::WindowLinkSelection; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use LibTmux::SessionSelection; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use LibTmux::ClientSelection; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use LibTmux::Pane; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use LibTmux::Window; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use LibTmux::WindowLink; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use LibTmux::Session; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use LibTmux::Client; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use LibTmux::X; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | my %plural = ( | |||||||||||||||||||||||||||||||||||||||||
| 18 | session => 'sessions', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | window => 'windows', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | window_link => 'window_links', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | pane => 'panes', | ||||||||||||||||||||||||||||||||||||||||||
| 22 | client => 'clients' | ||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | ▶ | sub from_records ($class, %args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_records: called CC=34 SCAR=38.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | server_id => $args{server_id} // 'detached', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | generation => $args{generation} // 'detached', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | complete => exists $args{complete} ? !!$args{complete} : true, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | records => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | order => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | loaded => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 7 | ▶ | metadata => {%{$args{metadata} // {}}}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$args{"server_id"} // "detached"
$args{"generation"} // "detached"
$args{"metadata"} // {}
MC/DC100%1/1
$args{"server_id"} // "detached"
$args{"server_id"}
MC/DC100%1/1
$args{"generation"} // "detached"
$args{"generation"}
MC/DC100%1/1
$args{"metadata"} // {}
$args{"metadata"}
Truth table100%2/2
A
A= $args{"server_id"}
Truth table100%2/2
A
A= $args{"generation"}
Truth table100%2/2
A
A= $args{"metadata"}
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 7 | for my $kind (sort keys %plural) { | |||||||||||||||||||||||||||||||||||||||||
| 36 | 35 | my $key = $plural{$kind}; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 35 | $self->{records}{$kind} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 35 | $self->{order}{$kind} = []; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 35 | $self->{loaded}{$kind} = exists $args{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 35 | ▶ | next unless exists $args{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | LibTmux::X::InvalidArgument->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 42 | message => "$key must be an array reference") | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 24 | ▶ | unless ref($args{$key}) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 24 | for my $record ($args{$key}->@*) { | |||||||||||||||||||||||||||||||||||||||||
| 45 | 48 | ▶ | LibTmux::X::InvalidArgument->throw( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | message => "$kind record must be a hash reference") | ||||||||||||||||||||||||||||||||||||||||||
| 47 | unless ref($record) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 48 | my %copy; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 48 | for my $field (sort keys %$record) { | |||||||||||||||||||||||||||||||||||||||||
| 50 | 183 | my $spec = LibTmux::Schema->field($kind, $field); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 183 | ▶ | if ($spec && $spec->{type} ne 'relation') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$spec and $spec->{"type"} ne "relation"
MC/DC50%1/2
$spec and $spec->{"type"} ne "relation"
$spec
$spec->{"type"} ne "relation"
Truth table66%2/3
A and B
A= $specB= $spec->{"type"} ne "relation"
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | $copy{$field} = LibTmux::Schema->normalize( | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 141 | $spec, $record->{$field}, | |||||||||||||||||||||||||||||||||||||||||
| 54 | "$kind.$field", 'InvalidArgument' | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ▶ | elsif ($field eq 'window_id' || $field eq 'session_id') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$field eq "window_id" or $field eq "session_id"
MC/DC0%0/2
$field eq "window_id" or $field eq "session_id"
$field eq "window_id"
$field eq "session_id"
Truth table66%2/3
A or B
A= $field eq "window_id"B= $field eq "session_id"
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | LibTmux::X::InvalidArgument->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 59 | message => 'relation ID must be scalar') | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 42 | ▶ | if ref($record->{$field}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 42 | $copy{$field} = $record->{$field}; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | LibTmux::X::InvalidArgument->throw( | |||||||||||||||||||||||||||||||||||||||||
| 65 | message => "unknown record field $kind.$field"); | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 48 | ▶ | $copy{id} //= ($copy{session_id} // '') . ':' . ($copy{index} // '') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$copy{"id"} //= ($copy{"session_id"} // "") . ':' . ($copy{"index"} // "")
$copy{"session_id"} // ""
$copy{"index"} // ""
MC/DC0%0/1
$copy{"id"} //= ($copy{"session_id"} // "") . ':' . ($copy{"index"} // "")
$copy{"id"}
MC/DC0%0/1
$copy{"index"} // ""
$copy{"index"}
Truth table50%1/2
A
A= $copy{"id"}
Truth table50%1/2
A
A= $copy{"index"}
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | if $kind eq 'window_link'; | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 48 | my $id = $copy{id}; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 48 | ▶ | LibTmux::X::InvalidArgument->throw(message => "invalid $kind ID") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $id and length $id and not $id =~ /\0/u
defined $id and length $id
MC/DC0%0/3
defined $id and length $id and not $id =~ /\0/u
defined $id
length $id
not $id =~ /\0/u
Truth table25%1/4
A and B and not(C)
A= defined $idB= length $idC= not $id =~ /\0/u
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | unless defined($id) && length($id) && $id !~ /\0/; | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 48 | my %prefix = (session => '\$', window => '\@', pane => '\%'); | |||||||||||||||||||||||||||||||||||||||||
| 74 | LibTmux::X::InvalidArgument->throw(message => "invalid $kind ID") | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 48 | ▶ | if exists $prefix{$kind} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $prefix{$kind} and not $id =~ /\A(?:$prefix{$kind})[0-9]+\z/u
MC/DC0%0/2
exists $prefix{$kind} and not $id =~ /\A(?:$prefix{$kind})[0-9]+\z/u
exists $prefix{$kind}
not $id =~ /\A(?:$prefix{$kind})[0-9]+\z/u
Truth table66%2/3
A and not(B)
A= exists $prefix{$kind}B= not $id =~ /\A(?:$prefix{$kind})[0-9]+\z/u
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | && $id !~ /\A(?:$prefix{$kind})[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 77 | LibTmux::X::InvalidArgument->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 78 | message => "duplicate physical $kind ID $id") | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 48 | ▶ | if exists $self->{records}{$kind}{$id}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 48 | $self->{records}{$kind}{$id} = \%copy; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 48 | push $self->{order}{$kind}->@*, $id; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 7 | ▶ | if ($self->{complete}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | for my $kind (qw(pane window_link client)) { | |||||||||||||||||||||||||||||||||||||||||
| 86 | 21 | for my $record (values $self->{records}{$kind}->%*) { | |||||||||||||||||||||||||||||||||||||||||
| 87 | 31 | for my $edge (qw(window_id session_id)) { | |||||||||||||||||||||||||||||||||||||||||
| 88 | next | ||||||||||||||||||||||||||||||||||||||||||
| 89 | unless exists $record->{$edge} | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 62 | ▶ | && defined $record->{$edge}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $record->{$edge} and defined $record->{$edge}
MC/DC50%1/2
exists $record->{$edge} and defined $record->{$edge}
exists $record->{$edge}
defined $record->{$edge}
Truth table66%2/3
A and B
A= exists $record->{$edge}B= defined $record->{$edge}
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 42 | ▶ | my $target = $edge eq 'window_id' ? 'window' : 'session'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | LibTmux::X::AcquisitionRace->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 93 | message => "missing $target relation for $kind") | ||||||||||||||||||||||||||||||||||||||||||
| 94 | unless | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 42 | ▶ | exists $self->{records}{$target}{$record->{$edge}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 563 | ▶ | sub server_id ($self) { $self->{server_id} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 563 | ▶ | sub generation ($self) { $self->{generation} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generation: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub complete ($self) { $self->{complete} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
complete: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 23 | ▶ | sub metadata ($self) { +{$self->{metadata}->%*} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
metadata: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 244 | ▶ | sub _handle ($self, $kind, $id) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 244 | ▶ | return undef unless defined $id && exists $self->{records}{$kind}{$id}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $id and exists $self->{"records"}{$kind}{$id}
MC/DC0%0/2
defined $id and exists $self->{"records"}{$kind}{$id}
defined $id
exists $self->{"records"}{$kind}{$id}
Truth table33%1/3
A and B
A= defined $idB= exists $self->{"records"}{$kind}{$id}
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 244 | return LibTmux::Schema->class_for($kind)->_new($self, $kind, $id); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 86 | ▶ | sub _selection ($self, $kind, $ids = undef) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_selection: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | LibTmux::X::Unloaded->throw(message => "$kind collection was not loaded") | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 86 | ▶ | unless $self->{loaded}{$kind}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | return LibTmux::Schema->selection_for($kind) | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 236 | ▶ | ->new(map { $self->_handle($kind, $_) } | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$ids // $self->{"order"}{$kind}
MC/DC0%0/2
$ids // $self->{"order"}{$kind}
$ids
$self->{"order"}{$kind}
Truth table66%2/3
A // B
A= $idsB= $self->{"order"}{$kind}
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 86 | ($ids // $self->{order}{$kind})->@*); | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 246 | ▶ | sub _read ($self, $kind, $id, $field) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read: called CC=29 SCAR=39.5
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 246 | my $spec = LibTmux::Schema->field($kind, $field); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 246 | ▶ | LibTmux::X::InvalidArgument->throw(message => "unknown field $kind.$field") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | unless $spec; | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 246 | my $record = $self->{records}{$kind}{$id}; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 246 | ▶ | if ($spec->{type} ne 'relation') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 228 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $self->{"metadata"}{"version"} and defined $spec->{"minimum"} and not "LibTmux::Schema"->_version_at_least($self->{"metadata"}{"version"}, $spec->{"minimum"})
defined $self->{"metadata"}{"version"} and defined $spec->{"minimum"}
MC/DC66%2/3
defined $self->{"metadata"}{"version"} and defined $spec->{"minimum"} and not "LibTmux::Schema"->_version_at_least($self->{"metadata"}{"version"}, $spec->{"minimum"})
defined $self->{"metadata"}{"version"}
defined $spec->{"minimum"}
not "LibTmux::Schema"->_version_at_least($self->{"metadata"}{"version"}, $spec->{"minimum"})
Truth table75%3/4
A and B and not(C)
A= defined $self->{"metadata"}{"version"}B= defined $spec->{"minimum"}C= not "LibTmux::Schema"->_version_at_least($self->{"metadata"}{"version"}, $spec->{"minimum"})
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | defined($self->{metadata}{version}) | ||||||||||||||||||||||||||||||||||||||||||
| 128 | && defined($spec->{minimum}) | ||||||||||||||||||||||||||||||||||||||||||
| 129 | && !LibTmux::Schema->_version_at_least( | ||||||||||||||||||||||||||||||||||||||||||
| 130 | $self->{metadata}{version}, | ||||||||||||||||||||||||||||||||||||||||||
| 131 | $spec->{minimum} | ||||||||||||||||||||||||||||||||||||||||||
| 132 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 133 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||||||||||||||||
| 135 | LibTmux::X::Unsupported->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 136 | path => "$kind.$field", | ||||||||||||||||||||||||||||||||||||||||||
| 137 | message => 'field requires tmux ' . $spec->{minimum} | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | LibTmux::X::Unloaded->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 142 | path => "$kind.$field", | ||||||||||||||||||||||||||||||||||||||||||
| 143 | entity => $kind, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | message => 'field was not loaded' | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 227 | ▶ | ) unless exists $record->{$field}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 224 | return $record->{$field}; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | LibTmux::X::Unloaded->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 149 | path => "$kind.$field", | ||||||||||||||||||||||||||||||||||||||||||
| 150 | message => 'relation is incomplete' | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 18 | ▶ | ) unless $self->{complete}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 18 | my $target = $spec->{entity}; | |||||||||||||||||||||||||||||||||||||||||
| 153 | LibTmux::X::Unloaded->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 154 | path => "$kind.$field", | ||||||||||||||||||||||||||||||||||||||||||
| 155 | message => 'relation collection was not loaded' | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 18 | ▶ | ) unless $self->{loaded}{$target}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 18 | ▶ | if ($spec->{many}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 10 | ▶ | my $edge = $kind eq 'session' ? 'session_id' : 'window_id'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 10 | for my $child (values $self->{records}{$target}->%*) { | |||||||||||||||||||||||||||||||||||||||||
| 160 | LibTmux::X::Unloaded->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 161 | path => "$kind.$field", | ||||||||||||||||||||||||||||||||||||||||||
| 162 | message => 'child relation membership was not loaded' | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 30 | ▶ | ) unless exists($child->{$edge}) && defined($child->{$edge}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $child->{$edge} and defined $child->{$edge}
MC/DC50%1/2
exists $child->{$edge} and defined $child->{$edge}
exists $child->{$edge}
defined $child->{$edge}
Truth table66%2/3
A and B
A= exists $child->{$edge}B= defined $child->{$edge}
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | my @ids = CORE::grep { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 29 | my $r = $self->{records}{$target}{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 167 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 168 | $kind eq 'session' | ||||||||||||||||||||||||||||||||||||||||||
| 169 | ? ($r->{session_id} // '') | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 29 | ▶ | : ($r->{window_id} // '') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$r->{"session_id"} // ""
$r->{"window_id"} // ""
MC/DC0%0/1
$r->{"session_id"} // ""
$r->{"session_id"}
MC/DC0%0/1
$r->{"window_id"} // ""
$r->{"window_id"}
Truth table50%1/2
A
A= $r->{"session_id"}
Truth table50%1/2
A
A= $r->{"window_id"}
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | ) eq $id | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 9 | } $self->{order}{$target}->@*; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 9 | return $self->_selection($target, \@ids); | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 8 | ▶ | if ($field eq 'active_pane') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | my @active; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | for my $pid ($self->{order}{pane}->@*) { | |||||||||||||||||||||||||||||||||||||||||
| 178 | LibTmux::X::Unloaded->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 179 | path => "$kind.$field", | ||||||||||||||||||||||||||||||||||||||||||
| 180 | message => 'pane relation membership was not loaded' | ||||||||||||||||||||||||||||||||||||||||||
| 181 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 182 | unless exists($self->{records}{pane}{$pid}{window_id}) | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | ▶ | && defined($self->{records}{pane}{$pid}{window_id}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $self->{"records"}{"pane"}{$pid}{"window_id"} and defined $self->{"records"}{"pane"}{$pid}{"window_id"}
MC/DC0%0/2
exists $self->{"records"}{"pane"}{$pid}{"window_id"} and defined $self->{"records"}{"pane"}{$pid}{"window_id"}
exists $self->{"records"}{"pane"}{$pid}{"window_id"}
defined $self->{"records"}{"pane"}{$pid}{"window_id"}
Truth table33%1/3
A and B
A= exists $self->{"records"}{"pane"}{$pid}{"window_id"}B= defined $self->{"records"}{"pane"}{$pid}{"window_id"}
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | next unless ($self->{records}{pane}{$pid}{window_id} // '') eq $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{"records"}{"pane"}{$pid}{"window_id"} // ""
MC/DC0%0/1
$self->{"records"}{"pane"}{$pid}{"window_id"} // ""
$self->{"records"}{"pane"}{$pid}{"window_id"}
Truth table0%0/2
A
A= $self->{"records"}{"pane"}{$pid}{"window_id"}
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | push @active, $pid if $self->_read('pane', $pid, 'active'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | LibTmux::X::AcquisitionRace->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | message => 'more than one active pane in physical window') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | if @active > 1; | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | return $self->_handle('pane', $active[0]); | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 7 | my $foreign = $target . '_id'; | |||||||||||||||||||||||||||||||||||||||||
| 193 | LibTmux::X::Unloaded->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 194 | path => "$kind.$field", | ||||||||||||||||||||||||||||||||||||||||||
| 195 | message => 'relation ID was not loaded' | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 7 | ▶ | ) unless exists $record->{$foreign}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 7 | ▶ | return undef if !defined($record->{$foreign}) && $spec->{nullable}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $record->{$foreign} and $spec->{"nullable"}
MC/DC0%0/2
not defined $record->{$foreign} and $spec->{"nullable"}
not defined $record->{$foreign}
$spec->{"nullable"}
Truth table33%1/3
not(A) and B
A= not defined $record->{$foreign}B= $spec->{"nullable"}
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 7 | my $handle = $self->_handle($target, $record->{$foreign}); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 7 | ▶ | LibTmux::X::Unloaded->throw( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | path => "$kind.$field", | ||||||||||||||||||||||||||||||||||||||||||
| 201 | message => 'related entity was not loaded' | ||||||||||||||||||||||||||||||||||||||||||
| 202 | ) unless $handle; | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 7 | return $handle; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | ▶ | sub sessions ($self) { $self->_selection('session') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sessions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 5 | ▶ | sub windows ($self) { $self->_selection('window') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
windows: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | ▶ | sub window_links ($self) { $self->_selection('window_link') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
window_links: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 70 | ▶ | sub panes ($self) { $self->_selection('pane') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
panes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | sub clients ($self) { $self->_selection('client') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clients: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | sub session_by_id ($self, $id) { $self->_handle('session', $id) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
session_by_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | sub window_by_id ($self, $id) { $self->_handle('window', $id) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
window_by_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | ▶ | sub pane_by_id ($self, $id) { $self->_handle('pane', $id) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pane_by_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | sub to_records ($self) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_records: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my %out = ( | |||||||||||||||||||||||||||||||||||||||||
| 216 | server_id => $self->server_id, | ||||||||||||||||||||||||||||||||||||||||||
| 217 | generation => $self->generation, | ||||||||||||||||||||||||||||||||||||||||||
| 218 | complete => $self->complete | ||||||||||||||||||||||||||||||||||||||||||
| 219 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | for my $kind (sort keys %plural) { | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | next unless $self->{loaded}{$kind}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $out{$plural{$kind}} = [map { +{%{$self->{records}{$kind}{$_}}} } | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $self->{order}{$kind}->@*]; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | return \%out; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | LibTmux::Snapshot - Captured graph with explicit completeness | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | =head2 from_records | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | C<from_records(server_id =E<gt> ..., generation =E<gt> ..., sessions =E<gt> [...], windows =E<gt> [...], window_links =E<gt> [...], panes =E<gt> [...], clients =E<gt> [...])> constructs a detached graph. Scalar records and relation IDs are copied. Omitted fields/collections remain unloaded; null is explicit. Invalid identities or inconsistent complete topology throw typed acquisition errors. | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | =head2 server_id | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | Return the captured server scope. Entity IDs are meaningful only within this scope and L</generation>. | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | =head2 generation | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | Return the captured daemon generation. L<LibTmux::Server> checks it before mutations through captured handles; retained snapshots never silently refresh. | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | =head2 complete | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | Return the capture completeness Boolean. The strict live acquisition path fails on incomplete topology; it does not synthesize empty relations. | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | =head2 metadata | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | Return a fresh metadata hash with capture start/end, daemon version, and PID where acquired. Several commands observe an interval; the snapshot is not an atomic tmux transaction. | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | =head2 sessions | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | Return a fresh L<LibTmux::SessionSelection> in captured order. Empty loaded collections yield empty selections; unloaded collections throw. | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | =head2 windows | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | Return a fresh L<LibTmux::WindowSelection> containing each physical window identity once. Context lives in L</window_links>. | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | =head2 window_links | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | Return a fresh L<LibTmux::WindowLinkSelection> retaining every session/index association, including repeated links of one physical window. | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | =head2 panes | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | Return a fresh L<LibTmux::PaneSelection> containing each physical pane identity once. Membership edits cannot change the graph store. | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | =head2 clients | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | Return a fresh L<LibTmux::ClientSelection> in captured order. A loaded empty client set is valid. | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | =head2 session_by_id | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | C<session_by_id('$1')> returns a L<LibTmux::Session> or undef. Single quotes preserve the dollar-prefixed ID instead of interpolating a regex capture. | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | =head2 window_by_id | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | C<window_by_id('@3')> returns one physical L<LibTmux::Window> or undef, independent of session link context. | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | =head2 pane_by_id | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | C<pane_by_id('%3')> returns a L<LibTmux::Pane> or undef. The returned handle retains the captured graph after this wrapper goes out of scope. | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | =head2 to_records | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | Return independent scalar records and adjacency IDs for detached use. No handles or live transport are serialized. | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | =head1 EXECUTION | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | All methods in this module operate on local captured data and perform no tmux | ||||||||||||||||||||||||||||||||||||||||||
| 293 | I/O. Ordering is deterministic; public query methods do not mutate membership. | ||||||||||||||||||||||||||||||||||||||||||
| 294 | Typed validation/evaluation errors propagate. See L<LibTmux::Server/snapshot> | ||||||||||||||||||||||||||||||||||||||||||
| 295 | for explicit acquisition and L<LibTmux::X> for machine-readable failures. | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | =cut | ||||||||||||||||||||||||||||||||||||||||||