| 1 | package App::teai::Session; | ||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use App::teai::Err; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use App::teai::Bus (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use App::teai::Config (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use App::teai::Lead (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use App::teai::Presence (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub _err ($code, $msg, %more) { eval { App::teai::Err::fail($code, $msg, %more) }; $@ } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_err: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub peers ($bus, $ids, $cb) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
peers: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | App::teai::Presence::list($bus, sub ($peers, $err = undef) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | my ($e) = $peers ? grep { defined } map { ($peers->{$_} // {})->{error} } @$ids : ($err); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$peers->{$_} // {}
MC/DC0%0/1
$peers->{$_} // {}
$peers->{$_}
Truth table0%0/2
A
A= $peers->{$_}
| |||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | return $cb->($peers) unless defined $e; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | return $cb->(undef, _err(3, 'the hub has no teai_peers bucket: run teai init')) if App::teai::Bus::no_bucket($e); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my $reason = 'cannot read presence (' . App::teai::Bus::_text($e) . ')'; | |||||||||||||||||||||||||||||||||||||
| 19 | 0 | $cb->(undef, _err(3, "$reason; add --force to remove without the live check", reason => $reason)); | |||||||||||||||||||||||||||||||||||||
| 20 | 0 | }); | |||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub clear_runtime ($id, $lock = undef) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_runtime: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | return undef unless lstat App::teai::Config::runtime_path(); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $e = ''; | |||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if (!$lock) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 27 | 0 | $lock = eval { App::teai::Config::reader_lock($id, 1) }; | |||||||||||||||||||||||||||||||||||||
| 28 | 0 | $e = $@; | |||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $why = $lock ? undef | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 31 | : !$e ? 'another process holds its reader lock' | ||||||||||||||||||||||||||||||||||||||
| 32 | : App::teai::Bus::_text($e); | ||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if (!defined $why) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $dir = App::teai::Config::runtime_dir(); | |||||||||||||||||||||||||||||||||||||
| 35 | 0 | for my $f (map { "$dir/$id.$_" } qw(wake wake.lock waiter reader)) { | |||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | $why //= "cannot remove $f: $!" unless unlink $f or $!{ENOENT}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
unlink $f or $!{"ENOENT"}
$why //= "cannot remove ${f}: $!"
MC/DC0%0/2
unlink $f or $!{"ENOENT"}
unlink $f
$!{"ENOENT"}
MC/DC0%0/1
$why //= "cannot remove ${f}: $!"
$why
Truth table0%0/3
A or B
A= unlink $fB= $!{"ENOENT"}
Truth table0%0/2
A
A= $why
| |||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||
| 39 | 0 | return $why; | |||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub remove ($bus, $id, @args) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $cb = pop @args; | |||||||||||||||||||||||||||||||||||||
| 44 | 0 | my %o = @args; | |||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $force = $o{force}; | |||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $peers = $o{peers} // ($force ? {} : die "Session::remove needs peers without force\n"); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$o{"peers"} // ($force ? {} : die("Session::remove needs peers without force\n"))
MC/DC0%0/1
$o{"peers"} // ($force ? {} : die("Session::remove needs peers without force\n"))
$o{"peers"}
Truth table0%0/2
A
A= $o{"peers"}
| |||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $bus->consumer_info($id, sub ($info, $err = undef) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return $cb->(undef, $err) if defined $err; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return $cb->({ missing => 1 }) unless $info; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my ($lock, $reader); | |||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if (!$force && lstat(App::teai::Config::runtime_path() . "/$id.reader")) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $force and lstat App::teai::Config::runtime_path() . "/$id.reader"
MC/DC0%0/2
not $force and lstat App::teai::Config::runtime_path() . "/$id.reader"
not $force
lstat App::teai::Config::runtime_path() . "/$id.reader"
Truth table0%0/3
not(A) and B
A= not $forceB= lstat App::teai::Config::runtime_path() . "/$id.reader"
| |||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $lock = eval { App::teai::Config::reader_lock($id, 1) }; | |||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $reader = !$lock && !length $@; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$lock || length $@
MC/DC0%0/2
$lock || length $@
$lock
length $@
Truth table0%0/3
A || B
A= $lockB= length $@
| |||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | my $live = ($peers->{$id} // {})->{live} // []; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
+($peers->{$id} // {})->{"live"} // []
$peers->{$id} // {}
MC/DC0%0/1
+($peers->{$id} // {})->{"live"} // []
$peers->{$id}
Truth table0%0/2
A
A= $peers->{$id}
| |||||||||||||||||||||||||||||||||||||||
| 56 | my @busy = $force ? () : ( | ||||||||||||||||||||||||||||||||||||||
| 57 | ($info->{num_waiting} ? "waiting=$info->{num_waiting}" : ()), | ||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | ($info->{num_ack_pending} ? "held=$info->{num_ack_pending}" : ()), | ||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||
| 59 | (@$live ? 'live=' . join(',', @$live) : ()), | ||||||||||||||||||||||||||||||||||||||
| 60 | ($reader ? 'reader' : ()), | ||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | return $cb->({ busy => \@busy }) if @busy; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $bus->mark_removed($id, $o{by}, sub ($ok, $e = undef) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return $cb->(undef, App::teai::Bus::no_bucket($e) | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 65 | ? _err(3, 'the hub has no teai_removed bucket: run teai init') : $e) if defined $e; | ||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $bus->remove_session($id, sub ($gone, $e2 = undef) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | return $cb->(undef, $e2) if defined $e2; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my $left = clear_runtime($id, $lock); | |||||||||||||||||||||||||||||||||||||
| 69 | 0 | undef $lock; | |||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | App::teai::Lead::release($bus, $id, sub ($ok, $e3 = undef) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $cb->({ removed => 1, left => $left, leases => defined $e3 ? App::teai::Bus::_text($e3) : undef }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 72 | 0 | }); | |||||||||||||||||||||||||||||||||||||
| 73 | 0 | }); | |||||||||||||||||||||||||||||||||||||
| 74 | 0 | }); | |||||||||||||||||||||||||||||||||||||
| 75 | 0 | }); | |||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||
| 78 | 1 | 1; | |||||||||||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||||||||||||