| 1 | package Linux::Event::Framer::LengthPrefix; | ||||||||||||||||||||||||||||||||||||||||||
| 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.105'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use bytes (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | sub _build_definition ($class, @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_definition: called CC=16 SCAR=30.6
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | ▶ | croak 'LengthPrefix options must be key/value pairs' if @args % 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 9 | my %opt = @args; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 9 | ▶ | 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 | 9 | ▶ | 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 | 9 | ▶ | 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 | 9 | ▶ | 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 | 9 | ▶ | 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 | 9 | my $max_frame = delete $opt{max_frame}; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 9 | ▶ | 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 | 9 | ▶ | croak 'unknown LengthPrefix options: ' . join(', ', sort keys %opt) if %opt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 9 | ▶ | my $native = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | read_mode => 4, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | prefix_bytes => 0 + $bytes, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | prefix_little => $endian eq 'little' ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | include_prefix => $include_prefix ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | max_frame => $max_frame, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 9 | return { native => $native, frame => \&_frame }; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | sub _frame ($config, $payload) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_frame: called CC=9 SCAR=22.8
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | $payload = '' if !defined $payload; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | my $length = bytes::length($payload); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | my $bytes = $config->{prefix_bytes}; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | ▶ | my $max = $bytes == 1 ? 0xff : $bytes == 2 ? 0xffff : 0xffffffff; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | croak "send(): payload length $length exceeds prefix capacity $max" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | if $length > $max; | ||||||||||||||||||||||||||||||||||||||||||
| 43 | croak "send(): payload length $length exceeds max_frame=$config->{max_frame}" | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | my @octets; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | my $value = $length; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | for (1 .. $bytes) { | |||||||||||||||||||||||||||||||||||||||||
| 49 | 8 | unshift @octets, $value & 0xff; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 8 | $value >>= 8; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | ▶ | @octets = reverse @octets if $config->{prefix_little}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | return pack('C*', @octets) . $payload; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||||||||||||||||||||||||||