| 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.120'; | |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 18 | my %opt = @args; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 18 | ▶ | my $bytes = delete $opt{bytes} // 4; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $opt{"bytes"} // 4
MC/DC0%0/1
delete $opt{"bytes"} // 4
delete $opt{"bytes"}
Truth table50%1/2
A
A= delete $opt{"bytes"}
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 18 | ▶ | croak 'bytes must be 1, 2, or 4' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$bytes != 1 and $bytes != 2 and $bytes != 4
$bytes != 1 and $bytes != 2
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
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | if $bytes != 1 && $bytes != 2 && $bytes != 4; | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 18 | ▶ | my $endian = delete $opt{endian} // 'big'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $opt{"endian"} // "big"
MC/DC100%1/1
delete $opt{"endian"} // "big"
delete $opt{"endian"}
Truth table100%2/2
A
A= delete $opt{"endian"}
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 18 | ▶ | croak 'endian must be big or little' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$endian ne "big" and $endian ne "little"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
delete $opt{"include_prefix"} // 0
delete $opt{"include_prefix"}
Truth table50%1/2
A
A= delete $opt{"include_prefix"}
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 18 | my $max_frame = delete $opt{max_frame}; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 18 | ▶ | croak 'max_frame must be a non-negative integer' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $max_frame and !($max_frame =~ /\A\d+\z/u) || $max_frame < 0
not $max_frame =~ /\A\d+\z/u or $max_frame < 0
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 18 | ▶ | my $little = $endian eq 'little' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 18 | ▶ | my $template = $bytes == 1 ? 'C' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | : $bytes == 2 ? ($little ? 'v' : 'n') | ||||||||||||||||||||||||||||||||||||||||||
| 29 | : ($little ? 'V' : 'N'); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 18 | ▶ | my $native = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $config->{"max_frame"} and $length > $config->{"max_frame"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 61 | return pack($config->{prefix_template}, $length) . $payload; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||||||||||||||||