| 1 | 2 | ▶ | use v5.40; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | 2 | package Archive::CAR::Utils v0.0.4 { | |||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | our @EXPORT_OK = qw[encode_varint decode_varint decode_cid systell]; | |||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | 151 | ▶ | sub systell ($fh) { | ||||||||||||||||||||||||||
|
Subroutine
systell: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 8 | 151 | return tell($fh); | |||||||||||||||||||||||||||
| 9 | } | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 21 | ▶ | sub encode_varint ($val) { | ||||||||||||||||||||||||||
|
Subroutine
encode_varint: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 21 | my $out = ''; | |||||||||||||||||||||||||||
| 13 | 21 | ▶ | while ( $val >= 0x80 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 5 | $out .= chr( ( $val & 0x7f ) | 0x80 ); | |||||||||||||||||||||||||||
| 15 | 5 | $val >>= 7; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | 21 | $out .= chr($val); | |||||||||||||||||||||||||||
| 18 | 21 | return $out; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 133 | ▶ | sub decode_varint ( $str_or_fh, $offset //= 0 ) { | ||||||||||||||||||||||||||
|
Subroutine
decode_varint: called CC=8 SCAR=21.5
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use Scalar::Util qw[openhandle]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # Handles both scalar strings and filehandles | ||||||||||||||||||||||||||||
| 25 | 133 | my $is_fh = openhandle($str_or_fh); | |||||||||||||||||||||||||||
| 26 | 133 | my ( $val, $shift, $bytes_read ) = ( 0, 0, 0 ); | |||||||||||||||||||||||||||
| 27 | 133 | my $initial_offset = $offset; | |||||||||||||||||||||||||||
| 28 | 133 | while (1) { | |||||||||||||||||||||||||||
| 29 | 139 | my $byte_val; | |||||||||||||||||||||||||||
| 30 | 139 | ▶ | if ($is_fh) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 139 | my $byte_char; | |||||||||||||||||||||||||||
| 32 | 139 | my $bytes_read_now = read( $str_or_fh, $byte_char, 1 ); | |||||||||||||||||||||||||||
| 33 | 139 | ▶ | return ( undef, 0 ) unless defined $bytes_read_now && $bytes_read_now == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $bytes_read_now and $bytes_read_now == 1
MC/DC50%1/2
defined $bytes_read_now and $bytes_read_now == 1
defined $bytes_read_now
$bytes_read_now == 1
Truth table66%2/3
A and B
A= defined $bytes_read_nowB= $bytes_read_now == 1
| |||||||||||||||||||||||||||||
| 34 | 136 | $byte_val = ord($byte_char); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | else { | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | return ( undef, 0 ) unless $offset < length($str_or_fh); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | $byte_val = ord( substr( $str_or_fh, $offset++, 1 ) ); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 136 | $bytes_read++; | |||||||||||||||||||||||||||
| 41 | 136 | $val |= ( $byte_val & 0x7f ) << $shift; | |||||||||||||||||||||||||||
| 42 | 136 | ▶ | return ( $val, $bytes_read ) unless $byte_val & 0x80; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 6 | $shift += 7; | |||||||||||||||||||||||||||
| 44 | 6 | ▶ | return ( undef, $bytes_read ) if $shift >= 64; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 28 | ▶ | sub decode_cid ($fh) { | ||||||||||||||||||||||||||
|
Subroutine
decode_cid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 28 | require Archive::CAR::CID; | |||||||||||||||||||||||||||
| 50 | 28 | return Archive::CAR::CID->decode($fh); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | }; | ||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||
| 54 | 2 | 1; | |||||||||||||||||||||||||||