lib/App/teai/Session.pm

filter: Statementstmt 26.3% 19 / 72 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 40.0% 6 / 15 Podpod 100% 3 / 3 totaltotal 16.9% 28 / 165 CC 39 SCAR 46.4
CC
39
Cov
14%
__ANON__
240.0
clear_runtime
132.0
__ANON__
42.0
CRAP 103.8
« lib/App/teai/MCP.pm ↑ Summary lib/App/teai/Dash/Mail.pm »
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
BranchTrueFalseTotal
$peers ? : 0 0 0
Condition0%0/2
$peers->{$_} // {}
l!l
00
MC/DC0%0/1
$peers->{$_} // {}
$peers->{$_}
Truth table0%0/2
A
A= $peers->{$_}
Aresult
11
00
16 0 ▶ return $cb->($peers) unless defined $e;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e 0 0 0
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
BranchTrueFalseTotal
if App::teai::Bus::no_bucket($e) 0 0 0
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
BranchTrueFalseTotal
unless lstat App::teai::Config::runtime_path() 0 0 0
25 0 my $e = '';
26 0 ▶ if (!$lock) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lock) 0 0 0
27 0 $lock = eval { App::teai::Config::reader_lock($id, 1) };
28 0 $e = $@;
29 }
30 0 ▶ my $why = $lock ? undef
Branch: 2 branches
BranchTrueFalseTotal
$lock ? : 0 0 0
!$e ? : 0 0 0
31 : !$e ? 'another process holds its reader lock'
32 : App::teai::Bus::_text($e);
33 0 ▶ if (!defined $why) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $why) 0 0 0
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
BranchTrueFalseTotal
unless unlink $f or $!{"ENOENT"} 0 0 0
Condition0%0/5
unlink $f or $!{"ENOENT"}
l!l&&r!l&&!r
000
$why //= "cannot remove ${f}: $!"
l!l
00
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"}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $why
Aresult
11
00
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
BranchTrueFalseTotal
$force ? : 0 0 0
Condition0%0/2
$o{"peers"} // ($force ? {} : die("Session::remove needs peers without force\n"))
l!l
00
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"}
Aresult
11
00
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
BranchTrueFalseTotal
if defined $err 0 0 0
49 0 ▶ return $cb->({ missing => 1 }) unless $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 0 0
50 0 my ($lock, $reader);
51 0 ▶ if (!$force && lstat(App::teai::Config::runtime_path() . "/$id.reader")) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $force and lstat App::teai::Config::runtime_path() . "/$id.reader") 0 0 0
Condition0%0/3
not $force and lstat App::teai::Config::runtime_path() . "/$id.reader"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
52 0 $lock = eval { App::teai::Config::reader_lock($id, 1) };
53 0 ▶ $reader = !$lock && !length $@;
Condition0%0/3
$lock || length $@
l!l&&r!l&&!r
000
MC/DC0%0/2
$lock || length $@
$lock length $@
Truth table0%0/3
A || B
A= $lockB= length $@
ABresult
1X1
011
000
54 }
55 0 ▶ my $live = ($peers->{$id} // {})->{live} // [];
Condition0%0/4
+($peers->{$id} // {})->{"live"} // []
l!l
00
$peers->{$id} // {}
l!l
00
MC/DC0%0/1
+($peers->{$id} // {})->{"live"} // []
$peers->{$id}
Truth table0%0/2
A
A= $peers->{$id}
Aresult
11
00
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
BranchTrueFalseTotal
$force ? : 0 0 0
$info->{'num_waiting'} ? : 0 0 0
$info->{'num_ack_pending'} ? : 0 0 0
@$live ? : 0 0 0
$reader ? : 0 0 0
59 (@$live ? 'live=' . join(',', @$live) : ()),
60 ($reader ? 'reader' : ()),
61 );
62 0 ▶ return $cb->({ busy => \@busy }) if @busy;
Branch: 1 branch
BranchTrueFalseTotal
if @busy 0 0 0
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
BranchTrueFalseTotal
if defined $e 0 0 0
App::teai::Bus::no_bucket($e) ? : 0 0 0
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
BranchTrueFalseTotal
if defined $e2 0 0 0
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
BranchTrueFalseTotal
defined $e3 ? : 0 0 0
72 0 });
73 0 });
74 0 });
75 0 });
76 }
77  
78 1 1;
79 __END__
« lib/App/teai/MCP.pm ↑ Summary lib/App/teai/Dash/Mail.pm »