| 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
Condition100%3/3
defined $s and not ref $s
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$id // ""
MC/DC0%0/1
$id // ""
$id
Truth table50%1/2
A
A= $id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%2/2
$id // ""
MC/DC100%1/1
$id // ""
$id
Truth table100%2/2
A
A= $id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $s and $s =~ /\Ateai\.([sp])\.($ID)\.($ID)\z/u
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | return { type => 'p', project => $2, to => "project:$2", from => $3 } if $1 eq 'p'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
defined $text and not ref $text
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 35 | ▶ | return { type => 'session', id => $1 } if $text =~ /\Asession:($ID)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 32 | ▶ | return { type => 'live', project => $1 } if $text =~ /\Alive:($ID)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 29 | ▶ | return { type => 'role', project => $1, role => $2 } if $text =~ m{\Arole:($ID)/($ID)\z}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 26 | ▶ | return { type => 'project', project => $1 } if $text =~ /\Aproject:($ID)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} // ""
MC/DC100%1/1
$addr->{"type"} // ""
$addr->{"type"}
Truth table100%2/2
A
A= $addr->{"type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 6 | ▶ | return "session:$addr->{id}" if $type eq 'session'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | ▶ | return "live:$addr->{project}" if $type eq 'live'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | return "role:$addr->{project}/$addr->{role}" if $type eq 'role'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | return "project:$addr->{project}" if $type eq 'project'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition77%7/9
ref $p eq "HASH" and defined $p->{"kind"} and not ref $p->{"kind"} and $KINDS{$p->{"kind"}}
ref $p eq "HASH" and defined $p->{"kind"} and not ref $p->{"kind"}
ref $p eq "HASH" and defined $p->{"kind"}
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"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 39 | ▶ | return undef if grep { exists $p->{$_} && !defined $p->{$_} } @NOT_NULL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $p->{$_} && !defined($p->{$_})
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->{$_})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 35 | delete @$p{ grep { !defined $p->{$_} } @PAYLOAD_KEYS }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 35 | ▶ | if (exists $p->{re}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 8 | ▶ | return undef if ref $p->{re} || $p->{re} !~ /\A[1-9][0-9]{0,15}\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $p->{"re"} or not $p->{"re"} =~ /\A[1-9][0-9]{0,15}\z/u
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | $p->{re} += 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 29 | ▶ | return undef if exists $p->{thread} && !valid_id($p->{thread}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $p->{"thread"} and not valid_id($p->{"thread"})
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 26 | ▶ | return undef if exists $p->{body} && !_json_string($types->{body}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $p->{"body"} and not _json_string($types->{"body"})
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 19 | ▶ | return undef if exists $p->{status} && ref $p->{status} ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $p->{"status"} and ref $p->{"status"} ne "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 17 | ▶ | if (exists $p->{via}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 11 | my $addr = parse_address($p->{via}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 11 | ▶ | delete $p->{via} unless $addr && $addr->{type} ne 'session'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$addr and $addr->{"type"} ne "session"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $type and not ref $type
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%4/6
@t == 9 and $t[0] eq "\$JS" and $t[1] eq "ACK"
@t == 9 and $t[0] eq "\$JS"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | return undef if grep { !/\A[0-9]+\z/ } @t[4 .. 8]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%2/2
$t // ""
MC/DC100%1/1
$t // ""
$t
Truth table100%2/2
A
A= $t
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 3 | ▶ | $secs -= ($sign eq '-' ? -1 : 1) * ($oh * 3600 + $om * 60) unless $zone; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 3 | ▶ | _iso($secs, substr(($frac // '') . '000', 0, 3)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$frac // ""
MC/DC100%1/1
$frac // ""
$frac
Truth table100%2/2
A
A= $frac
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%2/2
$t // ""
MC/DC100%1/1
$t // ""
$t
Truth table100%2/2
A
A= $t
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | read $fh, $raw, 16; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | ▶ | $raw .= pack 'C', int rand 256 while length $raw < 16; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 6 | ▶ | $h .= " thread=$r->{thread}" if defined $r->{thread}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 6 | ▶ | $h .= " via=$r->{via}" if defined $r->{via}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 6 | ▶ | $h .= " delivered=$r->{delivered}" if ($r->{delivered} // 0) > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$r->{"delivered"} // 0
MC/DC100%1/1
$r->{"delivered"} // 0
$r->{"delivered"}
Truth table100%2/2
A
A= $r->{"delivered"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 6 | ▶ | $h .= ' status=' . $chars_json->encode($r->{status}) if defined $r->{status}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 6 | ▶ | my $body = $r->{body} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$r->{"body"} // ""
MC/DC0%0/1
$r->{"body"} // ""
$r->{"body"}
Truth table50%1/2
A
A= $r->{"body"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | $chars_json->encode(\%h); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 42 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||