| 1 | package Linux::Event::Framer::Fixed; | ||||||||||||||||||||||||||||
| 2 | 19 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 19 | our $VERSION = '0.120'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 19 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 19 | ▶ | use bytes (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 20 | ▶ | sub _build_definition ($class, @args) { | ||||||||||||||||||||||||||
|
Subroutine
_build_definition: called CC=8 SCAR=22.6
| |||||||||||||||||||||||||||||
| 12 | 20 | ▶ | croak 'Fixed options must be key/value pairs' if @args != 1 && @args % 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@args != 1 and @args % 2
MC/DC0%0/2
@args != 1 and @args % 2
@args != 1
@args % 2
Truth table33%1/3
A and B
A= @args != 1B= @args % 2
| |||||||||||||||||||||||||||||
| 13 | 20 | ▶ | my %opt = @args == 1 ? (size => $args[0]) : @args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 20 | my $size = delete $opt{size}; | |||||||||||||||||||||||||||
| 15 | 20 | ▶ | croak 'Fixed requires size' if !defined $size; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 20 | ▶ | croak 'size must be a positive integer' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $size =~ /\A\d+\z/u or $size <= 0
MC/DC50%1/2
not $size =~ /\A\d+\z/u or $size <= 0
not $size =~ /\A\d+\z/u
$size <= 0
Truth table66%2/3
not(A) or B
A= not $size =~ /\A\d+\z/uB= $size <= 0
| |||||||||||||||||||||||||||||
| 17 | if $size !~ /\A\d+\z/ || $size <= 0; | ||||||||||||||||||||||||||||
| 18 | 19 | ▶ | croak 'unknown Fixed options: ' . join(', ', sort keys %opt) if %opt; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 19 | my $native = { read_mode => 3, fixed_size => 0 + $size }; | |||||||||||||||||||||||||||
| 21 | 19 | return { native => $native, frame => \&_frame }; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | sub _frame ($config, $payload) { | ||||||||||||||||||||||||||
|
Subroutine
_frame: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | $payload = '' if !defined $payload; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 2 | my $length = bytes::length($payload); | |||||||||||||||||||||||||||
| 27 | croak "send(): payload length $length does not equal fixed size $config->{fixed_size}" | ||||||||||||||||||||||||||||
| 28 | 2 | ▶ | if $length != $config->{fixed_size}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 1 | return $payload; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 19 | 1; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | __END__ | ||||||||||||||||||||||||||||