Stream/Codec/U32BE.pm

filter: Statementstmt 41.9% 13 / 31 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 4 / 7 Podpod 100% 1 / 1 totaltotal 33.3% 18 / 54 CC 7 SCAR 26.2
CC
7
Cov
30%
_decode
30.0
new
6.0
_encode
6.0
CRAP 13.7
« Stream/Codec.pm ↑ Summary Stream/Codec/Line.pm »
1 package Linux::Event::Stream::Codec::U32BE;
2 7 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 our $VERSION = '0.002';
7  
8 7 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 ▶sub new ($class, %opt) {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
11 0 my $max_frame = delete $opt{max_frame};
12 0 ▶ croak 'unknown options: ' . join(', ', sort keys %opt) if %opt;
Branch: 1 branch
BranchTrueFalseTotal
if %opt 0 0 0
13  
14 0 return bless {
15 max_frame => $max_frame,
16 decode => \&_decode,
17 encode => \&_encode,
18 }, $class;
19 }
20  
21 ▶sub _decode ($self, $inref, $outref) {
Subroutine _decode: not called CC=5 SCAR=34.0
22 0 while (1) {
23 0 ▶ last if length($$inref) < 4;
Branch: 1 branch
BranchTrueFalseTotal
if length $$inref < 4 0 0 0
24  
25 0 my $len = unpack('N', substr($$inref, 0, 4));
26  
27 0 my $max = $self->{max_frame};
28 0 ▶ if (defined($max) && $len > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and $len > $max) 0 0 0
Condition0%0/3
defined $max and $len > $max
!ll&&!rl&&r
000
MC/DC0%0/2
defined $max and $len > $max
defined $max $len > $max
Truth table0%0/3
A and B
A= defined $maxB= $len > $max
ABresult
0X0
100
111
29 0 return (0, "frame too large (>$max bytes)");
30 }
31  
32 0 my $need = 4 + $len;
33 0 ▶ last if length($$inref) < $need;
Branch: 1 branch
BranchTrueFalseTotal
if length $$inref < $need 0 0 0
34  
35 0 my $payload = substr($$inref, 4, $len);
36 0 substr($$inref, 0, $need, '');
37  
38 0 push @$outref, $payload;
39 }
40  
41 0 return 1;
42 }
43  
44 ▶sub _encode ($self, $msg) {
Subroutine _encode: not called CC=2 SCAR=17.9
45 0 ▶ $msg = '' if !defined $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $msg 0 0 0
46 0 $msg = "$msg";
47 0 return pack('N', length($msg)) . $msg;
48 }
49  
50 7 1;
51  
52 __END__
« Stream/Codec.pm ↑ Summary Stream/Codec/Line.pm »