Stream/Codec/Line.pm

filter: Statementstmt 94.2% 33 / 35 Branchbran 56.2% 9 / 16 Conditioncond 38.4% 5 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 68.7% 55 / 80 CC 14 SCAR 17.5
CC
14
Cov
73%
_decode
8.6
_encode
6.6
new
4.3
CRAP 5.7
« Stream/Codec/U32BE.pm ↑ Summary
1 package Linux::Event::Stream::Codec::Line;
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: called CC=4 SCAR=14.6
Pod documented
11 3 ▶ my $chomp = delete $opt{chomp} // 1;
Condition50%1/2
delete $opt{"chomp"} // 1
l!l
03
MC/DC0%0/1
delete $opt{"chomp"} // 1
delete $opt{"chomp"}
Truth table50%1/2
A
A= delete $opt{"chomp"}
Aresult
11
00
12 3 my $max_line = delete $opt{max_line};
13 3 ▶ my $append_nl = delete $opt{append_newline} // 1;
Condition50%1/2
delete $opt{"append_newline"} // 1
l!l
03
MC/DC0%0/1
delete $opt{"append_newline"} // 1
delete $opt{"append_newline"}
Truth table50%1/2
A
A= delete $opt{"append_newline"}
Aresult
11
00
14  
15 3 ▶ croak 'unknown options: ' . join(', ', sort keys %opt) if %opt;
Branch: 1 branch
BranchTrueFalseTotal
if %opt 0 3 3
16  
17 3 return bless {
18 chomp => $chomp,
19 max_line => $max_line,
20 append_newline => $append_nl,
21  
22 decode => \&_decode,
23 encode => \&_encode,
24 }, $class;
25 }
26  
27 ▶sub _decode ($self, $inref, $outref) {
Subroutine _decode: called CC=7 SCAR=21.5
28 # Consume complete lines ending with "\n".
29 2 while (1) {
30 5 my $idx = index($$inref, "\n");
31 5 ▶ last if $idx < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $idx < 0 2 3 5
32  
33 3 my $max = $self->{max_line};
34 3 ▶ if (defined($max) && $idx + 1 > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and $idx + 1 > $max) 0 3 3
Condition33%1/3
defined $max and $idx + 1 > $max
!ll&&!rl&&r
300
MC/DC0%0/2
defined $max and $idx + 1 > $max
defined $max $idx + 1 > $max
Truth table33%1/3
A and B
A= defined $maxB= $idx + 1 > $max
ABresult
0X0
100
111
35 0 return (0, "line too long (>$max bytes)");
36 }
37  
38 3 my $line = substr($$inref, 0, $idx + 1, '');
39  
40 3 ▶ if ($self->{chomp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"chomp"}) 3 0 3
41 3 ▶ substr($line, -1, 1, '') if length($line) && substr($line, -1, 1) eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if length $line and substr($line, -1, 1) eq "\n" 3 0 3
Condition33%1/3
length $line and substr($line, -1, 1) eq "\n"
!ll&&!rl&&r
003
MC/DC0%0/2
length $line and substr($line, -1, 1) eq "\n"
length $line substr($line, -1, 1) eq "\n"
Truth table33%1/3
A and B
A= length $lineB= substr($line, -1, 1) eq "\n"
ABresult
0X0
100
111
42 }
43  
44 3 push @$outref, $line;
45 }
46  
47 2 return 1;
48 }
49  
50 ▶sub _encode ($self, $msg) {
Subroutine _encode: called CC=5 SCAR=18.9
51 1 ▶ $msg = '' if !defined $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $msg 0 1 1
52 1 $msg = "$msg";
53  
54 1 ▶ if ($self->{append_newline}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"append_newline"}) 1 0 1
55 1 ▶ return $msg if length($msg) && substr($msg, -1, 1) eq "\n";
Branch: 1 branch
BranchTrueFalseTotal
if length $msg and substr($msg, -1, 1) eq "\n" 0 1 1
Condition33%1/3
length $msg and substr($msg, -1, 1) eq "\n"
!ll&&!rl&&r
010
MC/DC0%0/2
length $msg and substr($msg, -1, 1) eq "\n"
length $msg substr($msg, -1, 1) eq "\n"
Truth table33%1/3
A and B
A= length $msgB= substr($msg, -1, 1) eq "\n"
ABresult
0X0
100
111
56 1 return $msg . "\n";
57 }
58  
59 0 return $msg;
60 }
61  
62 7 1;
63  
64 __END__
« Stream/Codec/U32BE.pm ↑ Summary