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

filter: Statementstmt 100% 36 / 36 Branchbran 71.8% 23 / 32 Conditioncond 62.5% 15 / 24 MC/DCmcdc 7.6% 1 / 13 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 73.2% 82 / 112 CC 26 SCAR 29.7
CC
26
Cov
80%
_build_definition
26.7
_frame
5.9
BEGIN
1.0
CRAP 19.4
« blib/lib/Linux/Event/_Socket/Stream.pm ↑ Summary blib/lib/Linux/Event/_ByteStream.pm »
1 package Linux::Event::Framer::LengthPrefix;
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 18 ▶sub _build_definition ($class, @args) {
Subroutine _build_definition: called CC=22 SCAR=32.8
12 18 ▶ croak 'LengthPrefix options must be key/value pairs' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 18 18
13 18 my %opt = @args;
14 18 ▶ my $bytes = delete $opt{bytes} // 4;
Condition50%1/2
delete $opt{"bytes"} // 4
l!l
180
MC/DC0%0/1
delete $opt{"bytes"} // 4
delete $opt{"bytes"}
Truth table50%1/2
A
A= delete $opt{"bytes"}
Aresult
11
00
15 18 ▶ croak 'bytes must be 1, 2, or 4'
Branch: 1 branch
BranchTrueFalseTotal
if $bytes != 1 and $bytes != 2 and $bytes != 4 0 18 18
Condition83%5/6
$bytes != 1 and $bytes != 2 and $bytes != 4
!ll&&!rl&&r
1080
$bytes != 1 and $bytes != 2
!ll&&!rl&&r
558
MC/DC0%0/3
$bytes != 1 and $bytes != 2 and $bytes != 4
$bytes != 1 $bytes != 2 $bytes != 4
Truth table75%3/4
A and B and C
A= $bytes != 1B= $bytes != 2C= $bytes != 4
ABCresult
0XX0
10X0
1100
1111
16 if $bytes != 1 && $bytes != 2 && $bytes != 4;
17 18 ▶ my $endian = delete $opt{endian} // 'big';
Condition100%2/2
delete $opt{"endian"} // "big"
l!l
144
MC/DC100%1/1
delete $opt{"endian"} // "big"
delete $opt{"endian"}
Truth table100%2/2
A
A= delete $opt{"endian"}
Aresult
11
00
18 18 ▶ croak 'endian must be big or little'
Branch: 1 branch
BranchTrueFalseTotal
if $endian ne "big" and $endian ne "little" 0 18 18
Condition66%2/3
$endian ne "big" and $endian ne "little"
!ll&&!rl&&r
1440
MC/DC0%0/2
$endian ne "big" and $endian ne "little"
$endian ne "big" $endian ne "little"
Truth table66%2/3
A and B
A= $endian ne "big"B= $endian ne "little"
ABresult
0X0
100
111
19 if $endian ne 'big' && $endian ne 'little';
20 18 ▶ my $include_prefix = delete $opt{include_prefix} // 0;
Condition50%1/2
delete $opt{"include_prefix"} // 0
l!l
018
MC/DC0%0/1
delete $opt{"include_prefix"} // 0
delete $opt{"include_prefix"}
Truth table50%1/2
A
A= delete $opt{"include_prefix"}
Aresult
11
00
21 18 my $max_frame = delete $opt{max_frame};
22 18 ▶ 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 18 18
Condition50%3/6
defined $max_frame and !($max_frame =~ /\A\d+\z/u) || $max_frame < 0
!ll&&!rl&&r
1710
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
23 if defined($max_frame) && ($max_frame !~ /\A\d+\z/ || $max_frame < 0);
24 18 ▶ croak 'unknown LengthPrefix options: ' . join(', ', sort keys %opt) if %opt;
Branch: 1 branch
BranchTrueFalseTotal
if %opt 0 18 18
25  
26 18 ▶ my $little = $endian eq 'little' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$endian eq 'little' ? : 4 14 18
27 18 ▶ my $template = $bytes == 1 ? 'C'
Branch: 4 branches
BranchTrueFalseTotal
$bytes == 1 ? : 5 13 18
$bytes == 2 ? : 5 8 13
$little ? : 2 3 5
$little ? : 1 7 8
28 : $bytes == 2 ? ($little ? 'v' : 'n')
29 : ($little ? 'V' : 'N');
30 18 ▶ my $native = {
Branch: 3 branches
BranchTrueFalseTotal
$include_prefix ? : 0 18 18
$bytes == 1 ? : 5 13 18
$bytes == 2 ? : 5 8 13
31 read_mode => 4,
32 prefix_bytes => 0 + $bytes,
33 prefix_little => $little,
34 include_prefix => $include_prefix ? 1 : 0,
35 max_frame => $max_frame,
36 prefix_template => $template,
37 prefix_max => $bytes == 1 ? 0xff
38 : $bytes == 2 ? 0xffff : 0xffff_ffff,
39 };
40 18 return { native => $native, frame => \&_frame };
41 }
42  
43 61 ▶sub _frame ($config, $payload) {
Subroutine _frame: called CC=5 SCAR=17.8
44 61 ▶ $payload = '' if !defined $payload;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $payload 0 61 61
45 61 my $length = bytes::length($payload);
46 61 my $max = $config->{prefix_max};
47 61 ▶ croak "send(): payload length $length exceeds prefix capacity $max"
Branch: 1 branch
BranchTrueFalseTotal
if $length > $max 0 61 61
48 if $length > $max;
49 croak "send(): payload length $length exceeds max_frame=$config->{max_frame}"
50 61 ▶ if defined($config->{max_frame}) && $length > $config->{max_frame};
Branch: 1 branch
BranchTrueFalseTotal
if defined $config->{"max_frame"} and $length > $config->{"max_frame"} 0 61 61
Condition33%1/3
defined $config->{"max_frame"} and $length > $config->{"max_frame"}
!ll&&!rl&&r
6100
MC/DC0%0/2
defined $config->{"max_frame"} and $length > $config->{"max_frame"}
defined $config->{"max_frame"} $length > $config->{"max_frame"}
Truth table33%1/3
A and B
A= defined $config->{"max_frame"}B= $length > $config->{"max_frame"}
ABresult
0X0
100
111
51  
52 61 return pack($config->{prefix_template}, $length) . $payload;
53 }
54  
55 10 1;
56  
57 __END__
« blib/lib/Linux/Event/_Socket/Stream.pm ↑ Summary blib/lib/Linux/Event/_ByteStream.pm »