lib/App/teai/Wire.pm

filter: Statementstmt 100% 134 / 134 Branchbran 96.3% 79 / 82 Conditioncond 87.6% 57 / 65 MC/DCmcdc 78.3% 29 / 37 Subroutinesub 100% 30 / 30 Podpod 63.1% 12 / 19 totaltotal 92.9% 341 / 367 CC 69 SCAR 19.8
CC
69
Cov
96%
decode_payload
19.0
format_human
8.0
parse_address
7.0
CRAP 7.2
« lib/App/teai/Lock.pm ↑ Summary bin/teai »
1 package App::teai::Wire;
2 42 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 42 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 42 ▶use Cpanel::JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 42 ▶use Cpanel::JSON::XS::Type ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 42 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 42 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 42 ▶use Time::Local ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 42 ▶use App::teai::Err;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 42 our $VERSION = '0.08';
12 42 our @EXPORT_OK = qw(valid_id MAX_PAYLOAD ns session_subject parse_subject encode_payload
13 decode_payload parse_ack iso_time utc_time utc_now text_in new_msg_id pub_header format_human format_json
14 parse_address address_text project_subject utc_epoch);
15  
16 42 ▶use constant MAX_PAYLOAD => 1047552;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 42 my @PAYLOAD_KEYS = qw(kind re thread via body project agent role status);
19 42 my @NOT_NULL = qw(re thread body status);
20 42 my @JSON_KEYS = qw(seq time from to kind re thread via body project agent role status);
21 42 my %KINDS = map { $_ => 1 } qw(msg ask reply);
22 42 my $ID = qr/[A-Za-z0-9_-]{1,64}/;
23  
24 42 my $bytes_json = Cpanel::JSON::XS->new->utf8->canonical;
25 42 my $chars_json = Cpanel::JSON::XS->new->canonical;
26  
27 37 ▶sub valid_id ($s) { defined $s && !ref $s && $s =~ /\A[A-Za-z0-9_-]{1,64}\z/ }
Subroutine valid_id: called CC=3 SCAR=11.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $s and not ref $s and $s =~ /\A[A-Za-z0-9_-]{1,64}\z/u 32 5 37
Condition100%3/3
defined $s and not ref $s
!ll&&!rl&&r
1432
MC/DC100%2/2
defined $s and not ref $s
defined $s not ref $s
Truth table100%3/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
28  
29 1 ▶sub ns ($seconds) { $seconds * 1_000_000_000 }
Subroutine ns: called CC=1 SCAR=0.0
Pod undocumented
30  
31 2 ▶sub session_subject ($to, $from) {
Subroutine session_subject: called CC=4 SCAR=14.0
Pod documented
32 2 for my $id ($to, $from) {
33 3 ▶ App::teai::Err::fail(2, 'invalid id ' . ($id // '')) unless valid_id($id);
Branch: 1 branch
BranchTrueFalseTotal
unless valid_id($id) 1 2 3
Condition50%1/2
$id // ""
l!l
10
MC/DC0%0/1
$id // ""
$id
Truth table50%1/2
A
A= $id
Aresult
11
00
34 }
35 1 "teai.s.$to.$from";
36 }
37  
38 3 ▶sub project_subject ($project, $from) {
Subroutine project_subject: called CC=4 SCAR=13.9
Pod documented
39 3 for my $id ($project, $from) {
40 5 ▶ App::teai::Err::fail(2, 'invalid id ' . ($id // '')) unless valid_id($id);
Branch: 1 branch
BranchTrueFalseTotal
unless valid_id($id) 2 3 5
Condition100%2/2
$id // ""
l!l
11
MC/DC100%1/1
$id // ""
$id
Truth table100%2/2
A
A= $id
Aresult
11
00
41 }
42 1 "teai.p.$project.$from";
43 }
44  
45 8 ▶sub parse_subject ($s) {
Subroutine parse_subject: called CC=4 SCAR=13.9
Pod documented
46 8 ▶ return undef unless defined $s && $s =~ /\Ateai\.([sp])\.($ID)\.($ID)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and $s =~ /\Ateai\.([sp])\.($ID)\.($ID)\z/u 5 3 8
Condition66%2/3
defined $s and $s =~ /\Ateai\.([sp])\.($ID)\.($ID)\z/u
!ll&&!rl&&r
053
MC/DC50%1/2
defined $s and $s =~ /\Ateai\.([sp])\.($ID)\.($ID)\z/u
defined $s $s =~ /\Ateai\.([sp])\.($ID)\.($ID)\z/u
Truth table66%2/3
A and B
A= defined $sB= $s =~ /\Ateai\.([sp])\.($ID)\.($ID)\z/u
ABresult
0X0
100
111
47 3 ▶ return { type => 'p', project => $2, to => "project:$2", from => $3 } if $1 eq 'p';
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "p" 2 1 3
48 1 { type => $1, to => $2, from => $3 };
49 }
50  
51 41 ▶sub parse_address ($text) {
Subroutine parse_address: called CC=7 SCAR=19.5
Pod documented
52 41 ▶ return undef unless defined $text && !ref $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and not ref $text 6 35 41
Condition100%3/3
defined $text and not ref $text
!ll&&!rl&&r
1535
MC/DC100%2/2
defined $text and not ref $text
defined $text not ref $text
Truth table100%3/3
A and not(B)
A= defined $textB= not ref $text
ABresult
0X0
100
111
53 35 ▶ return { type => 'session', id => $1 } if $text =~ /\Asession:($ID)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\Asession:($ID)\z/u 3 32 35
54 32 ▶ return { type => 'live', project => $1 } if $text =~ /\Alive:($ID)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\Alive:($ID)\z/u 3 29 32
55 29 ▶ return { type => 'role', project => $1, role => $2 } if $text =~ m{\Arole:($ID)/($ID)\z};
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ m[\Arole:($ID)/($ID)\z]u 3 26 29
56 26 ▶ return { type => 'project', project => $1 } if $text =~ /\Aproject:($ID)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\Aproject:($ID)\z/u 3 23 26
57 23 return undef;
58 }
59  
60 6 ▶sub address_text ($addr) {
Subroutine address_text: called CC=6 SCAR=17.9
Pod documented
61 6 ▶ my $type = $addr->{type} // '';
Condition100%2/2
$addr->{"type"} // ""
l!l
51
MC/DC100%1/1
$addr->{"type"} // ""
$addr->{"type"}
Truth table100%2/2
A
A= $addr->{"type"}
Aresult
11
00
62 6 ▶ return "session:$addr->{id}" if $type eq 'session';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "session" 1 5 6
63 5 ▶ return "live:$addr->{project}" if $type eq 'live';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "live" 1 4 5
64 4 ▶ return "role:$addr->{project}/$addr->{role}" if $type eq 'role';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "role" 1 3 4
65 3 ▶ return "project:$addr->{project}" if $type eq 'project';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "project" 1 2 3
66 2 die "unknown address type '$type'\n";
67 }
68  
69 6 ▶sub encode_payload ($p) {
Subroutine encode_payload: called CC=3 SCAR=11.0
Pod documented
70 6 ▶ my %h = map { defined $p->{$_} ? ($_ => $p->{$_}) : () } @PAYLOAD_KEYS;
Branch: 1 branch
BranchTrueFalseTotal
defined $p->{$_} ? : 14 40 54
71 6 my $bytes = $bytes_json->encode(\%h);
72 6 my $n = length $bytes;
73 6 ▶ App::teai::Err::fail(2, "message too large ($n bytes, limit " . MAX_PAYLOAD . ")") if $n > MAX_PAYLOAD;
Branch: 1 branch
BranchTrueFalseTotal
if $n > 1047552 1 5 6
74 5 $bytes;
75 }
76  
77 42 ▶sub decode_payload ($bytes) {
Subroutine decode_payload: called CC=19 SCAR=29.5
Pod documented
78 42 my $types;
79 42 my $p = eval { $bytes_json->decode($bytes, $types) };
80 42 ▶ return undef unless ref $p eq 'HASH' && defined $p->{kind} && !ref $p->{kind} && $KINDS{ $p->{kind} };
Branch: 1 branch
BranchTrueFalseTotal
unless ref $p eq "HASH" and defined $p->{"kind"} and not ref $p->{"kind"} and $KINDS{$p->{"kind"}} 3 39 42
Condition77%7/9
ref $p eq "HASH" and defined $p->{"kind"} and not ref $p->{"kind"} and $KINDS{$p->{"kind"}}
!ll&&!rl&&r
2139
ref $p eq "HASH" and defined $p->{"kind"} and not ref $p->{"kind"}
!ll&&!rl&&r
2040
ref $p eq "HASH" and defined $p->{"kind"}
!ll&&!rl&&r
2040
MC/DC50%2/4
ref $p eq "HASH" and defined $p->{"kind"} and not ref $p->{"kind"} and $KINDS{$p->{"kind"}}
ref $p eq "HASH" defined $p->{"kind"} not ref $p->{"kind"} $KINDS{$p->{"kind"}}
Truth table60%3/5
A and B and not(C) and D
A= ref $p eq "HASH"B= defined $p->{"kind"}C= not ref $p->{"kind"}D= $KINDS{$p->{"kind"}}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
81 39 ▶ return undef if grep { exists $p->{$_} && !defined $p->{$_} } @NOT_NULL;
Branch: 1 branch
BranchTrueFalseTotal
if grep {exists $p->{$_} and not defined $p->{$_};} @NOT_NULL 4 35 39
Condition100%3/3
exists $p->{$_} && !defined($p->{$_})
!ll&&!rl&&r
112404
MC/DC100%2/2
exists $p->{$_} && !defined($p->{$_})
exists $p->{$_} !defined($p->{$_})
Truth table100%3/3
A && not(B)
A= exists $p->{$_}B= !defined($p->{$_})
ABresult
0X0
100
111
82 35 delete @$p{ grep { !defined $p->{$_} } @PAYLOAD_KEYS };
83 35 ▶ if (exists $p->{re}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $p->{"re"}) 8 27 35
84 8 ▶ return undef if ref $p->{re} || $p->{re} !~ /\A[1-9][0-9]{0,15}\z/;
Branch: 1 branch
BranchTrueFalseTotal
if ref $p->{"re"} or not $p->{"re"} =~ /\A[1-9][0-9]{0,15}\z/u 6 2 8
Condition100%3/3
ref $p->{"re"} or not $p->{"re"} =~ /\A[1-9][0-9]{0,15}\z/u
l!l&&r!l&&!r
242
MC/DC100%2/2
ref $p->{"re"} or not $p->{"re"} =~ /\A[1-9][0-9]{0,15}\z/u
ref $p->{"re"} not $p->{"re"} =~ /\A[1-9][0-9]{0,15}\z/u
Truth table100%3/3
A or not(B)
A= ref $p->{"re"}B= not $p->{"re"} =~ /\A[1-9][0-9]{0,15}\z/u
ABresult
1X1
011
000
85 2 $p->{re} += 0;
86 }
87 29 ▶ return undef if exists $p->{thread} && !valid_id($p->{thread});
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"thread"} and not valid_id($p->{"thread"}) 3 26 29
Condition100%3/3
exists $p->{"thread"} and not valid_id($p->{"thread"})
!ll&&!rl&&r
2423
MC/DC100%2/2
exists $p->{"thread"} and not valid_id($p->{"thread"})
exists $p->{"thread"} not valid_id($p->{"thread"})
Truth table100%3/3
A and not(B)
A= exists $p->{"thread"}B= not valid_id($p->{"thread"})
ABresult
0X0
100
111
88 26 ▶ return undef if exists $p->{body} && !_json_string($types->{body});
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"body"} and not _json_string($types->{"body"}) 7 19 26
Condition100%3/3
exists $p->{"body"} and not _json_string($types->{"body"})
!ll&&!rl&&r
2177
MC/DC100%2/2
exists $p->{"body"} and not _json_string($types->{"body"})
exists $p->{"body"} not _json_string($types->{"body"})
Truth table100%3/3
A and not(B)
A= exists $p->{"body"}B= not _json_string($types->{"body"})
ABresult
0X0
100
111
89 19 ▶ return undef if exists $p->{status} && ref $p->{status} ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"status"} and ref $p->{"status"} ne "HASH" 2 17 19
Condition100%3/3
exists $p->{"status"} and ref $p->{"status"} ne "HASH"
!ll&&!rl&&r
1612
MC/DC100%2/2
exists $p->{"status"} and ref $p->{"status"} ne "HASH"
exists $p->{"status"} ref $p->{"status"} ne "HASH"
Truth table100%3/3
A and B
A= exists $p->{"status"}B= ref $p->{"status"} ne "HASH"
ABresult
0X0
100
111
90 17 ▶ if (exists $p->{via}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $p->{"via"}) 11 6 17
91 11 my $addr = parse_address($p->{via});
92 11 ▶ delete $p->{via} unless $addr && $addr->{type} ne 'session';
Branch: 1 branch
BranchTrueFalseTotal
unless $addr and $addr->{"type"} ne "session" 8 3 11
Condition100%3/3
$addr and $addr->{"type"} ne "session"
!ll&&!rl&&r
713
MC/DC100%2/2
$addr and $addr->{"type"} ne "session"
$addr $addr->{"type"} ne "session"
Truth table100%3/3
A and B
A= $addrB= $addr->{"type"} ne "session"
ABresult
0X0
100
111
93 }
94 17 $p;
95 }
96  
97 24 ▶sub _json_string ($type) {
Subroutine _json_string: called CC=3 SCAR=11.1
98 24 ▶ defined $type && !ref $type && $type == Cpanel::JSON::XS::Type::JSON_TYPE_STRING()
Branch: 1 branch
BranchTrueFalseTotal
defined $type and not ref $type and $type == 4 22 2 24
Condition66%2/3
defined $type and not ref $type
!ll&&!rl&&r
0222
MC/DC50%1/2
defined $type and not ref $type
defined $type not ref $type
Truth table66%2/3
A and not(B)
A= defined $typeB= not ref $type
ABresult
0X0
100
111
99 }
100  
101 2 ▶sub parse_ack ($subject) {
Subroutine parse_ack: called CC=5 SCAR=16.4
Pod documented
102 2 my @t = split /\./, $subject, -1;
103 2 ▶ return undef unless @t == 9 && $t[0] eq '$JS' && $t[1] eq 'ACK';
Branch: 1 branch
BranchTrueFalseTotal
unless @t == 9 and $t[0] eq "\$JS" and $t[1] eq "ACK" 1 1 2
Condition66%4/6
@t == 9 and $t[0] eq "\$JS" and $t[1] eq "ACK"
!ll&&!rl&&r
101
@t == 9 and $t[0] eq "\$JS"
!ll&&!rl&&r
101
MC/DC33%1/3
@t == 9 and $t[0] eq "\$JS" and $t[1] eq "ACK"
@t == 9 $t[0] eq "\$JS" $t[1] eq "ACK"
Truth table50%2/4
A and B and C
A= @t == 9B= $t[0] eq "\$JS"C= $t[1] eq "ACK"
ABCresult
0XX0
10X0
1100
1111
104 1 ▶ return undef if grep { !/\A[0-9]+\z/ } @t[4 .. 8];
Branch: 1 branch
BranchTrueFalseTotal
if grep {not /\A[0-9]+\z/u;} @t[4..8] 0 1 1
105 1 my ($stream, $consumer, $delivered, $seq, $cseq, $time_ns, $pending) = @t[2 .. 8];
106 {
107 1 stream => $stream, consumer => $consumer, delivered => $delivered + 0, seq => $seq + 0,
108 cseq => $cseq + 0, time_ns => $time_ns, pending => $pending + 0,
109 };
110 }
111  
112 6 ▶sub _iso ($secs, $ms) {
Subroutine _iso: called CC=1 SCAR=0.0
113 6 my ($S, $M, $H, $d, $m, $y) = gmtime $secs;
114 6 sprintf '%04d-%02d-%02dT%02d:%02d:%02d.%sZ', $y + 1900, $m + 1, $d, $H, $M, $S, $ms;
115 }
116  
117 2 ▶sub iso_time ($ns) {
Subroutine iso_time: called CC=1 SCAR=0.0
Pod undocumented
118 2 $ns = sprintf '%012s', $ns =~ s/\A0+(?=\d)//r;
119 2 $ns =~ tr/ /0/;
120 2 my $secs = substr $ns, 0, length($ns) - 9;
121 2 my $ms = substr $ns, -9, 3;
122 2 _iso($secs + 0, $ms);
123 }
124  
125 6 ▶sub utc_time ($t) {
Subroutine utc_time: called CC=7 SCAR=19.5
Pod undocumented
126 6 ▶ my ($y, $mo, $d, $h, $mi, $s, $frac, $zone, $sign, $oh, $om) = ($t // '') =~
Branch: 1 branch
BranchTrueFalseTotal
() = ($t // "") =~ /\A(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.(\d+))?(?:(Z)|([+-])(\d\d):(\d\d))\z/u or return $t 4 2 6
Condition100%2/2
$t // ""
l!l
51
MC/DC100%1/1
$t // ""
$t
Truth table100%2/2
A
A= $t
Aresult
11
00
127 /\A(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(?:\.(\d+))?(?:(Z)|([+-])(\d\d):(\d\d))\z/
128 or return $t;
129 4 ▶ my $secs = eval { Time::Local::timegm_modern($s, $mi, $h, $d, $mo - 1, $y) } // return $t;
Condition100%2/2
eval { do { Time::Local::timegm_modern($s, $mi, $h, $d, $mo - 1, $y) } } // (return $t)
l!l
31
MC/DC100%1/1
eval { do { Time::Local::timegm_modern($s, $mi, $h, $d, $mo - 1, $y) } } // (return $t)
eval { do { Time::Local::timegm_modern($s, $mi, $h, $d, $mo - 1, $y) } }
Truth table100%2/2
A
A= eval { do { Time::Local::timegm_modern($s, $mi, $h, $d, $mo - 1, $y) } }
Aresult
11
00
130 3 ▶ $secs -= ($sign eq '-' ? -1 : 1) * ($oh * 3600 + $om * 60) unless $zone;
Branch: 2 branches
BranchTrueFalseTotal
unless $zone 2 1 3
$sign eq '-' ? : 1 1 2
131 3 ▶ _iso($secs, substr(($frac // '') . '000', 0, 3));
Condition100%2/2
$frac // ""
l!l
21
MC/DC100%1/1
$frac // ""
$frac
Truth table100%2/2
A
A= $frac
Aresult
11
00
132 }
133  
134 10 ▶sub utc_epoch ($t) {
Subroutine utc_epoch: called CC=4 SCAR=13.9
Pod undocumented
135 10 ▶ my ($y, $mo, $d, $h, $mi, $s, $ms) = ($t // '') =~ /\A(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)\.(\d{3})Z\z/
Branch: 1 branch
BranchTrueFalseTotal
() = ($t // "") =~ /\A(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)\.(\d{3})Z\z/u or return undef 4 6 10
Condition100%2/2
$t // ""
l!l
91
MC/DC100%1/1
$t // ""
$t
Truth table100%2/2
A
A= $t
Aresult
11
00
136 or return undef;
137 4 ▶ my $secs = eval { Time::Local::timegm_modern($s, $mi, $h, $d, $mo - 1, $y) } // return undef;
Condition100%2/2
eval { do { Time::Local::timegm_modern($s, $mi, $h, $d, $mo - 1, $y) } } // (return undef)
l!l
31
MC/DC100%1/1
eval { do { Time::Local::timegm_modern($s, $mi, $h, $d, $mo - 1, $y) } } // (return undef)
eval { do { Time::Local::timegm_modern($s, $mi, $h, $d, $mo - 1, $y) } }
Truth table100%2/2
A
A= eval { do { Time::Local::timegm_modern($s, $mi, $h, $d, $mo - 1, $y) } }
Aresult
11
00
138 3 return $secs + $ms / 1000;
139 }
140  
141 1 ▶sub utc_now () {
Subroutine utc_now: called CC=1 SCAR=0.0
Pod documented
142 1 my $t = Time::HiRes::time();
143 1 my $s = int $t;
144 1 _iso($s, sprintf '%03d', int(($t - $s) * 1000));
145 }
146  
147 2 ▶sub text_in ($bytes) {
Subroutine text_in: called CC=2 SCAR=6.9
Pod documented
148 2 my $src = $bytes;
149 2 my $s = eval { Encode::decode('UTF-8', $src, Encode::FB_CROAK | Encode::LEAVE_SRC) };
150 2 ▶ return ($s, 0) if defined $s;
Branch: 1 branch
BranchTrueFalseTotal
if defined $s 1 1 2
151 1 ($s) = Encode::decode('UTF-8', $bytes, Encode::FB_DEFAULT | Encode::LEAVE_SRC);
152 1 ($s, 1);
153 }
154  
155 1 ▶sub new_msg_id () {
Subroutine new_msg_id: called CC=3 SCAR=11.3
Pod documented
156 1 my $raw = '';
157 1 ▶ if (open my $fh, '<:raw', '/dev/urandom') {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<:raw", "/dev/urandom") 1 0 1
158 1 read $fh, $raw, 16;
159 }
160 1 ▶ $raw .= pack 'C', int rand 256 while length $raw < 16;
Branch: 1 branch
BranchTrueFalseTotal
length $raw < 16 and do { $raw .= pack("C", int rand 256) } 0 1 1
161 1 unpack 'H32', $raw;
162 }
163  
164 1 ▶sub pub_header ($msg_id) { "NATS/1.0\r\nNats-Msg-Id: $msg_id\r\n\r\n" }
Subroutine pub_header: called CC=1 SCAR=0.0
Pod undocumented
165  
166 6 ▶sub format_human ($r) {
Subroutine format_human: called CC=8 SCAR=20.8
Pod undocumented
167 6 my $h = "--- #$r->{seq} $r->{time} $r->{from} -> $r->{to} $r->{kind}";
168 6 ▶ $h .= " re=$r->{re}" if defined $r->{re};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"re"} 1 5 6
169 6 ▶ $h .= " thread=$r->{thread}" if defined $r->{thread};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"thread"} 2 4 6
170 6 ▶ $h .= " via=$r->{via}" if defined $r->{via};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"via"} 3 3 6
171 6 ▶ $h .= " delivered=$r->{delivered}" if ($r->{delivered} // 0) > 1;
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"delivered"} // 0) > 1 2 4 6
Condition100%2/2
$r->{"delivered"} // 0
l!l
33
MC/DC100%1/1
$r->{"delivered"} // 0
$r->{"delivered"}
Truth table100%2/2
A
A= $r->{"delivered"}
Aresult
11
00
172 6 ▶ $h .= ' status=' . $chars_json->encode($r->{status}) if defined $r->{status};
Branch: 1 branch
BranchTrueFalseTotal
if defined $r->{"status"} 1 5 6
173 6 ▶ my $body = $r->{body} // '';
Condition50%1/2
$r->{"body"} // ""
l!l
60
MC/DC0%0/1
$r->{"body"} // ""
$r->{"body"}
Truth table50%1/2
A
A= $r->{"body"}
Aresult
11
00
174 6 $body =~ s/\n+\z//;
175 6 "$h\n$body\n";
176 }
177  
178 3 ▶sub format_json ($r) {
Subroutine format_json: called CC=2 SCAR=6.9
Pod undocumented
179 3 ▶ my %h = map { defined $r->{$_} ? ($_ => $r->{$_}) : () } @JSON_KEYS;
Branch: 1 branch
BranchTrueFalseTotal
defined $r->{$_} ? : 10 29 39
180 3 $chars_json->encode(\%h);
181 }
182  
183 42 1;
184 __END__
« lib/App/teai/Lock.pm ↑ Summary bin/teai »