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

filter: Statementstmt 100% 31 / 31 Branchbran 62.5% 10 / 16 Conditioncond 63.6% 7 / 11 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 80.2% 57 / 71 CC 14 SCAR 21.1
CC
14
Cov
83%
_build_definition
13.1
_frame
4.1
BEGIN
1.0
CRAP 8.3
« bench/run-framing-microbench.pl ↑ Summary bench/run-first-class-framed-callback-bench.pl »
1 package Linux::Event::Framer::Delimiter;
2 45 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 45 our $VERSION = '0.120';
7  
8 45 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 45 ▶use bytes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 83 ▶sub _build_definition ($class, $delimiter = undef, @args) {
Subroutine _build_definition: called CC=11 SCAR=25.7
12 83 ▶ croak 'Delimiter requires a delimiter byte string' if !defined $delimiter;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $delimiter 0 83 83
13 83 ▶ croak 'Delimiter must not be empty' if $delimiter eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $delimiter eq "" 0 83 83
14 83 ▶ croak 'Delimiter options must be key/value pairs' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 83 83
15 83 my %opt = @args;
16 83 ▶ my $include_delimiter = delete $opt{include_delimiter} // 0;
Condition100%2/2
delete $opt{"include_delimiter"} // 0
l!l
182
MC/DC100%1/1
delete $opt{"include_delimiter"} // 0
delete $opt{"include_delimiter"}
Truth table100%2/2
A
A= delete $opt{"include_delimiter"}
Aresult
11
00
17 83 my $max_frame = delete $opt{max_frame};
18 83 ▶ 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 83 83
Condition50%3/6
defined $max_frame and !($max_frame =~ /\A\d+\z/u) || $max_frame < 0
!ll&&!rl&&r
7850
not $max_frame =~ /\A\d+\z/u or $max_frame < 0
l!l&&r!l&&!r
005
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
19 if defined($max_frame) && ($max_frame !~ /\A\d+\z/ || $max_frame < 0);
20 83 ▶ croak 'unknown Delimiter options: ' . join(', ', sort keys %opt) if %opt;
Branch: 1 branch
BranchTrueFalseTotal
if %opt 0 83 83
21  
22 83 ▶ my $native = {
Branch: 1 branch
BranchTrueFalseTotal
$include_delimiter ? : 1 82 83
23 read_mode => 2,
24 delimiter => $delimiter,
25 include_delimiter => $include_delimiter ? 1 : 0,
26 max_frame => $max_frame,
27 };
28 83 return { native => $native, frame => \&_frame };
29 }
30  
31 16326 ▶sub _frame ($config, $payload) {
Subroutine _frame: called CC=4 SCAR=14.1
32 16326 ▶ $payload = '' if !defined $payload;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $payload 0 16326 16326
33 16326 my $length = bytes::length($payload);
34 croak "send(): payload length $length exceeds max_frame=$config->{max_frame}"
35 16326 ▶ if defined($config->{max_frame}) && $length > $config->{max_frame};
Branch: 1 branch
BranchTrueFalseTotal
if defined $config->{"max_frame"} and $length > $config->{"max_frame"} 1 16325 16326
Condition66%2/3
defined $config->{"max_frame"} and $length > $config->{"max_frame"}
!ll&&!rl&&r
1632501
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
36 16325 return $payload . $config->{delimiter};
37 }
38  
39 45 1;
40  
41 __END__
« bench/run-framing-microbench.pl ↑ Summary bench/run-first-class-framed-callback-bench.pl »