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

filter: Statementstmt 100% 31 / 31 Branchbran 75.0% 12 / 16 Conditioncond 69.2% 9 / 13 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 83.7% 62 / 74 CC 14 SCAR 20.2
CC
14
Cov
87%
_build_definition
11.7
_frame
4.1
BEGIN
1.0
CRAP 7.5
« bench/run-native-framers-microbench.pl ↑ Summary blib/lib/Linux/Event/_Socket/Descriptor.pm »
1 package Linux::Event::Framer::DecimalLength;
2 9 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 our $VERSION = '0.120';
7  
8 9 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use bytes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 11 ▶sub _build_definition ($class, @args) {
Subroutine _build_definition: called CC=11 SCAR=24.6
12 11 ▶ croak 'DecimalLength options must be key/value pairs' if @args % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 0 11 11
13 11 my %opt = @args;
14 11 ▶ my $separator = delete $opt{separator} // ' ';
Condition100%2/2
delete $opt{"separator"} // " "
l!l
74
MC/DC100%1/1
delete $opt{"separator"} // " "
delete $opt{"separator"}
Truth table100%2/2
A
A= delete $opt{"separator"}
Aresult
11
00
15 11 ▶ croak 'separator must be exactly one byte'
Branch: 1 branch
BranchTrueFalseTotal
if &bytes::length($separator) != 1 1 10 11
16 if bytes::length($separator) != 1;
17 10 ▶ croak 'separator must not be an ASCII digit' if $separator =~ /[0-9]/;
Branch: 1 branch
BranchTrueFalseTotal
if $separator =~ /[0-9]/u 1 9 10
18 9 ▶ my $include_prefix = delete $opt{include_prefix} // 0;
Condition100%2/2
delete $opt{"include_prefix"} // 0
l!l
18
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
19 9 my $max_frame = delete $opt{max_frame};
20 9 ▶ 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 9 9
Condition50%3/6
defined $max_frame and !($max_frame =~ /\A\d+\z/u) || $max_frame < 0
!ll&&!rl&&r
810
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
21 if defined($max_frame) && ($max_frame !~ /\A\d+\z/ || $max_frame < 0);
22 9 ▶ croak 'unknown DecimalLength options: ' . join(', ', sort keys %opt) if %opt;
Branch: 1 branch
BranchTrueFalseTotal
if %opt 0 9 9
23  
24 9 ▶ my $native = {
Branch: 1 branch
BranchTrueFalseTotal
$include_prefix ? : 1 8 9
25 read_mode => 7,
26 delimiter => $separator,
27 include_prefix => $include_prefix ? 1 : 0,
28 max_frame => $max_frame,
29 };
30 9 return { native => $native, frame => \&_frame };
31 }
32  
33 4 ▶sub _frame ($config, $payload) {
Subroutine _frame: called CC=4 SCAR=14.1
34 4 ▶ $payload = '' if !defined $payload;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $payload 0 4 4
35 4 my $length = bytes::length($payload);
36 croak "send(): payload length $length exceeds max_frame=$config->{max_frame}"
37 4 ▶ if defined($config->{max_frame}) && $length > $config->{max_frame};
Branch: 1 branch
BranchTrueFalseTotal
if defined $config->{"max_frame"} and $length > $config->{"max_frame"} 1 3 4
Condition66%2/3
defined $config->{"max_frame"} and $length > $config->{"max_frame"}
!ll&&!rl&&r
301
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
38 3 return $length . $config->{delimiter} . $payload;
39 }
40  
41 9 1;
42  
43 __END__
« bench/run-native-framers-microbench.pl ↑ Summary blib/lib/Linux/Event/_Socket/Descriptor.pm »