lib/App/teai/Address.pm

filter: Statementstmt 16.0% 21 / 131 Branchbran 0.0% 0 / 76 Conditioncond 0.0% 0 / 51 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 18.1% 6 / 33 Podpod 100% 10 / 10 totaltotal 11.3% 37 / 327 CC 70 SCAR 36.8
CC
70
Cov
8%
__ANON__
156.0
__ANON__
56.0
__ANON__
56.0
CRAP 39.5
« lib/App/teai/Presence.pm ↑ Summary lib/App/teai/Dash/Threads.pm »
1 package App::teai::Address;
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::Lead ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use App::teai::Presence ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use App::teai::Wire ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '0.08';
10  
11 1 my $OPERATOR = 'operator';
12 1 my $NOTICE = 'project mail waiting for %1$s - read it with teai inbox --project %1$s or teai_inbox {project: "%1$s"}';
13  
14 0 ▶sub _err ($code, $msg) { eval { App::teai::Err::fail($code, $msg) }; $@ }
Subroutine _err: not called CC=1 SCAR=6.9
15  
16 0 ▶sub parse ($text) {
Subroutine parse: not called CC=5 SCAR=34.0
Pod documented
17 0 my $addr = App::teai::Wire::parse_address($text);
18 0 ▶ return $addr if $addr;
Branch: 1 branch
BranchTrueFalseTotal
if $addr 0 0 0
19 0 ▶ my ($id) = ($text // '') =~ /\Asession:(.+)\z/s;
Condition0%0/2
$text // ""
l!l
00
MC/DC0%0/1
$text // ""
$text
Truth table0%0/2
A
A= $text
Aresult
11
00
20 0 ▶ App::teai::Err::fail(2, defined $id ? "invalid id '$id'" : "invalid target '" . ($text // '') . "'");
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 0 0 0
Condition0%0/2
$text // ""
l!l
00
MC/DC0%0/1
$text // ""
$text
Truth table0%0/2
A
A= $text
Aresult
11
00
21 }
22  
23 0 ▶sub resolve ($bus, $addr, $from, $cb) {
Subroutine resolve: not called CC=2 SCAR=17.9
Pod documented
24 0 ▶ return $cb->([ $addr->{id} ]) if $addr->{type} eq 'session';
Branch: 1 branch
BranchTrueFalseTotal
if $addr->{"type"} eq "session" 0 0 0
25 0 ▶ App::teai::Presence::list($bus, sub ($list, $err = undef) {
Subroutine __ANON__: not called CC=12 SCAR=50.5
26 0 ▶ return $cb->(undef, _err(3, 'the hub has no teai_peers bucket: run teai init'))
Branch: 1 branch
BranchTrueFalseTotal
if defined $err and App::teai::Bus::no_bucket($err) 0 0 0
Condition0%0/3
defined $err and App::teai::Bus::no_bucket($err)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $err and App::teai::Bus::no_bucket($err)
defined $err App::teai::Bus::no_bucket($err)
Truth table0%0/3
A and B
A= defined $errB= App::teai::Bus::no_bucket($err)
ABresult
0X0
100
111
27 if defined $err && App::teai::Bus::no_bucket($err);
28 0 ▶ return $cb->(undef, $err) if defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 0 0 0
29 my @ids = sort grep {
30 0 my $s = $list->{$_};
31 0 ▶ my $role = $s->{role} // '';
Condition0%0/2
$s->{"role"} // ""
l!l
00
MC/DC0%0/1
$s->{"role"} // ""
$s->{"role"}
Truth table0%0/2
A
A= $s->{"role"}
Aresult
11
00
32 $_ ne $from && App::teai::Presence::interactive($s->{live})
33 && ($s->{project} // '') eq $addr->{project} && $role ne $OPERATOR
34 0 ▶ && ($addr->{type} ne 'role' || $role eq $addr->{role});
Condition0%0/17
$_ ne $from && App::teai::Presence::interactive($s->{'live'}) && ($s->{'project'} // '') eq $addr->{'project'} && $role ne $OPERATOR && ($addr->{'type'} ne 'role' || $role eq $addr->{'role'})
!ll&&!rl&&r
000
$_ ne $from and App::teai::Presence::interactive($s->{"live"}) and ($s->{"project"} // "") eq $addr->{"project"} and $role ne $OPERATOR
!ll&&!rl&&r
000
$_ ne $from and App::teai::Presence::interactive($s->{"live"}) and ($s->{"project"} // "") eq $addr->{"project"}
!ll&&!rl&&r
000
$_ ne $from and App::teai::Presence::interactive($s->{"live"})
!ll&&!rl&&r
000
$s->{"project"} // ""
l!l
00
$addr->{"type"} ne "role" or $role eq $addr->{"role"}
l!l&&r!l&&!r
000
MC/DC0%0/6
$_ ne $from && App::teai::Presence::interactive($s->{'live'}) && ($s->{'project'} // '') eq $addr->{'project'} && $role ne $OPERATOR && ($addr->{'type'} ne 'role' || $role eq $addr->{'role'})
$_ ne $from App::teai::Presence::interactive($s->{"live"}) $s->{"project"} $role ne $OPERATOR $addr->{"type"} ne "role" $role eq $addr->{"role"}
Truth table0%0/7
A and B and C and D && E or F
A= $_ ne $fromB= App::teai::Presence::interactive($s->{"live"})C= $s->{"project"}D= $role ne $OPERATORE= $addr->{"type"} ne "role"F= $role eq $addr->{"role"}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
1111000
11111X1
1111011
35 } keys %$list;
36 0 $cb->(\@ids);
37 0 });
38 }
39  
40 0 ▶sub inbox_note ($bus, $id, $cb) {
Subroutine inbox_note: not called CC=1 SCAR=6.9
Pod documented
41 0 ▶ $bus->consumer_info($id, sub ($info, $err = undef) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
42 0 ▶ return $cb->(undef) if $info || defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if $info or defined $err 0 0 0
Condition0%0/3
$info or defined $err
l!l&&r!l&&!r
000
MC/DC0%0/2
$info or defined $err
$info defined $err
Truth table0%0/3
A or B
A= $infoB= defined $err
ABresult
1X1
011
000
43 0 ▶ $bus->removed($id, sub ($gone, @) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
44 0 ▶ $cb->($gone ? "session $id was removed; nothing will read this message"
Branch: 1 branch
BranchTrueFalseTotal
$gone ? : 0 0 0
45 : "session $id has no inbox yet; the message waits until it is created");
46 0 });
47 0 });
48 }
49  
50 0 ▶sub deliver ($bus, $addr, $payload, $from, $cb, $opts = undef) {
Subroutine deliver: not called CC=4 SCAR=30.0
Pod documented
51 0 ▶ return _to_project($bus, $addr, $payload, $from, $cb) if $addr->{type} eq 'project';
Branch: 1 branch
BranchTrueFalseTotal
if $addr->{"type"} eq "project" 0 0 0
52 0 ▶ my %o = ref $opts eq 'HASH' ? %$opts : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $opts eq 'HASH' ? : 0 0 0
53 0 my $off = 0;
54 0 ▶ my $stop = sub { $off = 1 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 0 ▶ resolve($bus, $addr, $from, sub ($ids, $err = undef) {
Subroutine __ANON__: not called CC=7 SCAR=40.3
56 0 ▶ return if $off;
Branch: 1 branch
BranchTrueFalseTotal
if $off 0 0 0
57 0 ▶ return $cb->(undef, $err) if defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 0 0 0
58 0 my $text = App::teai::Wire::address_text($addr);
59 0 ▶ return $cb->(undef, _err(1, "no live session for $text")) unless @$ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @$ids 0 0 0
60 0 ▶ $o{on_ids}->([@$ids]) if ref $o{on_ids} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $o{"on_ids"} eq "CODE" 0 0 0
61 0 my %copy = %$payload;
62 0 ▶ if ($addr->{type} eq 'session') { delete $copy{via} } else { $copy{via} = $text }
Branch: 1 branch
BranchTrueFalseTotal
if ($addr->{'type'} eq 'session') { } 0 0 0
63 0 my @todo = @$ids;
64 0 my @copies;
65 0 ▶ my $next = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
66 0 my $again = __SUB__;
67 0 ▶ return if $off;
Branch: 1 branch
BranchTrueFalseTotal
if $off 0 0 0
68 0 ▶ my $to = shift @todo // return $cb->(\@copies);
Condition0%0/2
shift @todo // (return &$cb(\@copies))
l!l
00
MC/DC0%0/1
shift @todo // (return &$cb(\@copies))
shift @todo
Truth table0%0/2
A
A= shift @todo
Aresult
11
00
69 0 my $subject = eval { App::teai::Wire::session_subject($to, $from) };
70 0 ▶ if (!defined $subject) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $subject) 0 0 0
71 0 push @copies, { to => $to, error => App::teai::Bus::_text($@) };
72 0 ▶ $o{on_copy}->($copies[-1]) if ref $o{on_copy} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $o{"on_copy"} eq "CODE" 0 0 0
73 0 return $again->();
74 }
75 0 ▶ $bus->publish($subject, \%copy, sub ($seq, $e = undef) {
Subroutine __ANON__: not called CC=5 SCAR=34.0
76 0 ▶ push @copies, defined $e ? { to => $to, error => App::teai::Bus::_text($e) } : { to => $to, seq => $seq };
Branch: 1 branch
BranchTrueFalseTotal
defined $e ? : 0 0 0
77 0 ▶ $o{on_copy}->($copies[-1]) if ref $o{on_copy} eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $o{"on_copy"} eq "CODE" 0 0 0
78 0 ▶ return if $off;
Branch: 1 branch
BranchTrueFalseTotal
if $off 0 0 0
79 0 $again->();
80 0 });
81 0 };
82 0 $next->();
83 0 });
84 0 return $stop;
85 }
86  
87 0 ▶sub _to_project ($bus, $addr, $payload, $from, $cb) {
Subroutine _to_project: not called CC=1 SCAR=6.9
88 0 ▶ store($bus, $addr, $payload, $from, sub ($seq, $err = undef) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
89 0 ▶ return $cb->(undef, $err) if defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 0 0 0
90 0 ▶ notify($bus, $addr, $payload, $from, $seq, sub ($r) { $cb->([$r]) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 0 });
92 }
93  
94 0 ▶sub store ($bus, $addr, $payload, $from, $cb) {
Subroutine store: not called CC=2 SCAR=17.9
Pod documented
95 0 ▶ my $subject = eval { App::teai::Wire::project_subject($addr->{project}, $from) } // return $cb->(undef, $@);
Condition0%0/2
eval { do { App::teai::Wire::project_subject($addr->{"project"}, $from) } } // (return &$cb(undef, $@))
l!l
00
MC/DC0%0/1
eval { do { App::teai::Wire::project_subject($addr->{"project"}, $from) } } // (return &$cb(undef, $@))
eval { do { App::teai::Wire::project_subject($addr->{"project"}, $from) } }
Truth table0%0/2
A
A= eval { do { App::teai::Wire::project_subject($addr->{"project"}, $from) } }
Aresult
11
00
96 0 my %mail = %$payload;
97 0 delete $mail{via};
98 0 $bus->publish($subject, \%mail, $cb);
99 }
100  
101 0 ▶sub notify ($bus, $addr, $payload, $from, $seq, $cb) {
Subroutine notify: not called CC=1 SCAR=6.9
Pod documented
102 0 my $project = $addr->{project};
103 0 my $text = App::teai::Wire::address_text($addr);
104 0 my %r = (to => $text, seq => $seq, lead => undef, notice => undef, notice_error => undef);
105 0 ▶ App::teai::Lead::lease($bus, $project, sub ($lease, $e = undef) {
Subroutine __ANON__: not called CC=5 SCAR=34.0
106 0 ▶ $r{notice_error} = App::teai::Bus::_text($e) if defined $e && !App::teai::Lead::no_leads($e);
Branch: 1 branch
BranchTrueFalseTotal
if defined $e and not App::teai::Lead::no_leads($e) 0 0 0
Condition0%0/3
defined $e and not App::teai::Lead::no_leads($e)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $e and not App::teai::Lead::no_leads($e)
defined $e not App::teai::Lead::no_leads($e)
Truth table0%0/3
A and not(B)
A= defined $eB= not App::teai::Lead::no_leads($e)
ABresult
0X0
100
111
107 0 ▶ return $cb->(\%r) unless $lease;
Branch: 1 branch
BranchTrueFalseTotal
unless $lease 0 0 0
108 0 ▶ $bus->removed($lease->{session}, sub ($gone, @) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
109 0 ▶ return $cb->(\%r) if $gone;
Branch: 1 branch
BranchTrueFalseTotal
if $gone 0 0 0
110 0 my $lead = $r{lead} = $lease->{session};
111 0 ▶ return $cb->(\%r) if $lead eq $from;
Branch: 1 branch
BranchTrueFalseTotal
if $lead eq $from 0 0 0
112 my $notice = {
113 kind => 'msg', body => sprintf($NOTICE, $project), via => $text,
114 0 ▶ map { defined $payload->{$_} ? ($_ => $payload->{$_}) : () } qw(project agent role),
Branch: 1 branch
BranchTrueFalseTotal
defined $payload->{$_} ? : 0 0 0
115 };
116 0 ▶ $bus->publish(App::teai::Wire::session_subject($lead, $from), $notice, sub ($n, $ne = undef) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
117 0 ▶ if (defined $ne) { $r{notice_error} = App::teai::Bus::_text($ne) } else { $r{notice} = $n }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ne) { } 0 0 0
118 0 $cb->(\%r);
119 0 });
120 0 });
121 0 });
122 }
123  
124 0 ▶sub note ($r) {
Subroutine note: not called CC=5 SCAR=34.0
Pod documented
125 0 my $addr = App::teai::Wire::parse_address($r->{to});
126 0 ▶ return undef unless $addr && $addr->{type} eq 'project';
Branch: 1 branch
BranchTrueFalseTotal
unless $addr and $addr->{"type"} eq "project" 0 0 0
Condition0%0/3
$addr and $addr->{"type"} eq "project"
!ll&&!rl&&r
000
MC/DC0%0/2
$addr and $addr->{"type"} eq "project"
$addr $addr->{"type"} eq "project"
Truth table0%0/3
A and B
A= $addrB= $addr->{"type"} eq "project"
ABresult
0X0
100
111
127 0 ▶ return "the lead of $addr->{project} was not told: $r->{notice_error}" if defined $r->{notice_error};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"notice_error"} 0 0 0
128 0 ▶ return "project $addr->{project} has no lead; the message waits for one" unless defined $r->{lead};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r->{"lead"} 0 0 0
129 0 return undef;
130 }
131  
132 0 ▶sub answers ($to, $from) { ($from // '') eq $to || $to =~ /\Aproject:/ }
Subroutine answers: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
($from // "") eq $to or $to =~ /\Aproject:/u 0 0 0
Condition0%0/2
$from // ""
l!l
00
MC/DC0%0/1
$from // ""
$from
Truth table0%0/2
A
A= $from
Aresult
11
00
133  
134 0 ▶sub addressed ($bus, $m, $session, $cb) {
Subroutine addressed: not called CC=5 SCAR=34.0
Pod documented
135 0 my $addr = App::teai::Wire::parse_address($m->{to});
136 0 ▶ return $cb->(($m->{to} // '') eq $session ? 1 : 0) unless $addr && $addr->{type} eq 'project';
Branch: 2 branches
BranchTrueFalseTotal
unless $addr and $addr->{"type"} eq "project" 0 0 0
($m->{'to'} // '') eq $session ? : 0 0 0
Condition0%0/5
$addr and $addr->{"type"} eq "project"
!ll&&!rl&&r
000
$m->{"to"} // ""
l!l
00
MC/DC0%0/2
$addr and $addr->{"type"} eq "project"
$addr $addr->{"type"} eq "project"
MC/DC0%0/1
$m->{"to"} // ""
$m->{"to"}
Truth table0%0/3
A and B
A= $addrB= $addr->{"type"} eq "project"
ABresult
0X0
100
111
Truth table0%0/2
A
A= $m->{"to"}
Aresult
11
00
137 0 ▶ App::teai::Lead::check($bus, $addr->{project}, $session, sub ($epoch, $err = undef) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
138 0 ▶ defined $err ? $cb->(undef, $err) : $cb->(1);
Branch: 1 branch
BranchTrueFalseTotal
defined $err ? : 0 0 0
139 0 });
140 }
141  
142 0 ▶sub reply ($bus, $seq, $payload, $from, $cb) {
Subroutine reply: not called CC=1 SCAR=6.9
Pod documented
143 0 ▶ $bus->message($seq, sub ($orig, $err = undef) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
144 0 ▶ return $cb->(undef, $err) if defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 0 0 0
145 0 ▶ addressed($bus, $orig, $from, sub ($ok, $e = undef) {
Subroutine __ANON__: not called CC=7 SCAR=40.3
146 0 ▶ return $cb->(undef, $e) if defined $e;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e 0 0 0
147 0 ▶ return $cb->(undef, _err(2, "message #$seq is not addressed to this session")) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
148 0 ▶ return $cb->(undef, _err(2, "message #$seq is a reply")) unless $orig->{kind} eq 'ask' || $orig->{kind} eq 'msg';
Branch: 1 branch
BranchTrueFalseTotal
unless $orig->{"kind"} eq "ask" or $orig->{"kind"} eq "msg" 0 0 0
Condition0%0/3
$orig->{"kind"} eq "ask" or $orig->{"kind"} eq "msg"
l!l&&r!l&&!r
000
MC/DC0%0/2
$orig->{"kind"} eq "ask" or $orig->{"kind"} eq "msg"
$orig->{"kind"} eq "ask" $orig->{"kind"} eq "msg"
Truth table0%0/3
A or B
A= $orig->{"kind"} eq "ask"B= $orig->{"kind"} eq "msg"
ABresult
1X1
011
000
149 0 ▶ my $subject = eval { App::teai::Wire::session_subject($orig->{from}, $from) } // return $cb->(undef, $@);
Condition0%0/2
eval { do { App::teai::Wire::session_subject($orig->{"from"}, $from) } } // (return &$cb(undef, $@))
l!l
00
MC/DC0%0/1
eval { do { App::teai::Wire::session_subject($orig->{"from"}, $from) } } // (return &$cb(undef, $@))
eval { do { App::teai::Wire::session_subject($orig->{"from"}, $from) } }
Truth table0%0/2
A
A= eval { do { App::teai::Wire::session_subject($orig->{"from"}, $from) } }
Aresult
11
00
150 0 $bus->publish($subject, { %$payload, thread => $orig->{thread} }, $cb);
151 0 });
152 0 });
153 }
154  
155 1 1;
156 __END__
« lib/App/teai/Presence.pm ↑ Summary lib/App/teai/Dash/Threads.pm »