blib/lib/Linux/Event/Framer/Varint.pm

filter: Statementstmt 100% 36 / 36 Branchbran 77.7% 14 / 18 Conditioncond 63.6% 7 / 11 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 84.6% 66 / 78 CC 14 SCAR 18.4
CC
14
Cov
88%
_build_definition
9.0
_frame
7.0
BEGIN
1.0
CRAP 6.3
« blib/lib/Linux/Event/TLS.pm ↑ Summary bench/run-signal-microbench.pl »
1 package Linux::Event::Framer::Varint;
2 10 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 our $VERSION = '0.119';
7  
8 10 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use bytes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 ▶sub _build_definition ($class, @args) {
Subroutine _build_definition: called CC=8 SCAR=22.0
12 10 ▶ croak 'Varint options must be key/value pairs' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 10 10
13 10 my %opt = @args;
14 10 ▶ my $include_prefix = delete $opt{include_prefix} // 0;
Condition100%2/2
delete $opt{"include_prefix"} // 0
l!l
19
MC/DC100%1/1
delete $opt{"include_prefix"} // 0
delete $opt{"include_prefix"}
Truth table100%2/2
A
A= delete $opt{"include_prefix"}
Aresult
11
00
15 10 my $max_frame = delete $opt{max_frame};
16 10 ▶ croak 'max_frame must be a non-negative integer'
Branch: 1 branch
BranchTrueFalseTotal
if defined $max_frame and !($max_frame =~ /\A\d+\z/u) || $max_frame < 0 0 10 10
Condition50%3/6
defined $max_frame and !($max_frame =~ /\A\d+\z/u) || $max_frame < 0
!ll&&!rl&&r
910
not $max_frame =~ /\A\d+\z/u or $max_frame < 0
l!l&&r!l&&!r
001
MC/DC0%0/3
defined $max_frame and !($max_frame =~ /\A\d+\z/u) || $max_frame < 0
defined $max_frame not $max_frame =~ /\A\d+\z/u $max_frame < 0
Truth table50%2/4
A and not(B) or C
A= defined $max_frameB= not $max_frame =~ /\A\d+\z/uC= $max_frame < 0
ABCresult
0XX0
1000
11X1
1011
17 if defined($max_frame) && ($max_frame !~ /\A\d+\z/ || $max_frame < 0);
18 10 ▶ croak 'unknown Varint options: ' . join(', ', sort keys %opt) if %opt;
Branch: 1 branch
BranchTrueFalseTotal
if %opt 0 10 10
19  
20 10 ▶ my $native = {
Branch: 1 branch
BranchTrueFalseTotal
$include_prefix ? : 1 9 10
21 read_mode => 6,
22 include_prefix => $include_prefix ? 1 : 0,
23 max_frame => $max_frame,
24 };
25 10 return { native => $native, frame => \&_frame };
26 }
27  
28 26 ▶sub _frame ($config, $payload) {
Subroutine _frame: called CC=7 SCAR=19.5
29 26 ▶ $payload = '' if !defined $payload;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $payload 0 26 26
30 26 my $length = bytes::length($payload);
31 croak "send(): payload length $length exceeds max_frame=$config->{max_frame}"
32 26 ▶ if defined($config->{max_frame}) && $length > $config->{max_frame};
Branch: 1 branch
BranchTrueFalseTotal
if defined $config->{"max_frame"} and $length > $config->{"max_frame"} 1 25 26
Condition66%2/3
defined $config->{"max_frame"} and $length > $config->{"max_frame"}
!ll&&!rl&&r
2501
MC/DC50%1/2
defined $config->{"max_frame"} and $length > $config->{"max_frame"}
defined $config->{"max_frame"} $length > $config->{"max_frame"}
Truth table66%2/3
A and B
A= defined $config->{"max_frame"}B= $length > $config->{"max_frame"}
ABresult
0X0
100
111
33  
34 25 ▶ return pack('C', $length) . $payload if $length < 128;
Branch: 1 branch
BranchTrueFalseTotal
if $length < 128 16 9 25
35  
36 9 my @octets;
37 9 my $value = $length;
38 9 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$value and do { do { my $byte = $value & 127; $value >>= 7; $byte |= 128 if $value; push @octets, $byte } } 13 9 22
39 22 my $byte = $value & 0x7f;
40 22 $value >>= 7;
41 22 ▶ $byte |= 0x80 if $value;
Branch: 1 branch
BranchTrueFalseTotal
if $value 13 9 22
42 22 push @octets, $byte;
43 } while ($value);
44 9 return pack('C*', @octets) . $payload;
45 }
46  
47 10 1;
48  
49 __END__
« blib/lib/Linux/Event/TLS.pm ↑ Summary bench/run-signal-microbench.pl »