| 1 | package Zuzu::Marshal::CBOR; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | our $VERSION = '0.007002'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use B qw( SVf_IOK SVf_NOK SVf_POK svref_2object ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use Types::Serialiser (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Zuzu::Util::Number qw( is_finite_number ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use CBOR::Free (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | ▶ | use CBOR::Free::Decoder (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 18 | byte_string | ||||||||||||||||||||||||||||||||||||||||||
| 19 | bytes_value | ||||||||||||||||||||||||||||||||||||||||||
| 20 | cbor_false | ||||||||||||||||||||||||||||||||||||||||||
| 21 | cbor_true | ||||||||||||||||||||||||||||||||||||||||||
| 22 | decode_one | ||||||||||||||||||||||||||||||||||||||||||
| 23 | encode_one | ||||||||||||||||||||||||||||||||||||||||||
| 24 | is_byte_string | ||||||||||||||||||||||||||||||||||||||||||
| 25 | is_cbor_bool | ||||||||||||||||||||||||||||||||||||||||||
| 26 | is_tagged | ||||||||||||||||||||||||||||||||||||||||||
| 27 | is_text_string | ||||||||||||||||||||||||||||||||||||||||||
| 28 | tag | ||||||||||||||||||||||||||||||||||||||||||
| 29 | tag_number | ||||||||||||||||||||||||||||||||||||||||||
| 30 | tag_value | ||||||||||||||||||||||||||||||||||||||||||
| 31 | text_string | ||||||||||||||||||||||||||||||||||||||||||
| 32 | text_value | ||||||||||||||||||||||||||||||||||||||||||
| 33 | validate_profile | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 8 | ▶ | use constant MAX_SAFE_INTEGER => 9007199254740991; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||||||||||||
| 39 | package Zuzu::Marshal::CBOR::TextString; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 8 | has 'value' => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | package Zuzu::Marshal::CBOR::ByteString; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 8 | has 'bytes' => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 8 | package Zuzu::Marshal::CBOR::Tagged; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 8 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 8 | has 'tag' => ( is => 'ro', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 8 | has 'value' => ( is => 'ro' ); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 111 | ▶ | sub text_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text_string: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 111 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 111 | ▶ | $value //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$value //= ""
MC/DC0%0/1
$value //= ""
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 111 | return Zuzu::Marshal::CBOR::TextString->new( value => "$value" ); | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | ▶ | sub byte_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
byte_string: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 6 | my ( $bytes ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 6 | ▶ | $bytes //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$bytes //= ""
MC/DC0%0/1
$bytes //= ""
$bytes
Truth table50%1/2
A
A= $bytes
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 6 | return Zuzu::Marshal::CBOR::ByteString->new( | |||||||||||||||||||||||||||||||||||||||||
| 67 | bytes => _bytes_scalar($bytes), | ||||||||||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 39 | ▶ | sub tag { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 39 | my ( $tag, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 39 | return Zuzu::Marshal::CBOR::Tagged->new( | |||||||||||||||||||||||||||||||||||||||||
| 74 | tag => 0 + $tag, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | value => $value, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | ▶ | sub cbor_true { Types::Serialiser::true() } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cbor_true: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | sub cbor_false { Types::Serialiser::false() } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cbor_false: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 321 | ▶ | sub is_cbor_bool { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_cbor_bool: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 321 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 321 | ▶ | return Types::Serialiser::is_bool($value) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 480 | ▶ | sub is_text_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_text_string: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 480 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 480 | ▶ | return blessed($value) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($value) and $value->isa("Zuzu::Marshal::CBOR::TextString")
MC/DC100%2/2
builtin::blessed($value) and $value->isa("Zuzu::Marshal::CBOR::TextString")
builtin::blessed($value)
$value->isa("Zuzu::Marshal::CBOR::TextString")
Truth table100%3/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Marshal::CBOR::TextString")
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | && $value->isa('Zuzu::Marshal::CBOR::TextString') ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 307 | ▶ | sub is_byte_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_byte_string: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 307 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 307 | ▶ | return blessed($value) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($value) and $value->isa("Zuzu::Marshal::CBOR::ByteString")
MC/DC100%2/2
builtin::blessed($value) and $value->isa("Zuzu::Marshal::CBOR::ByteString")
builtin::blessed($value)
$value->isa("Zuzu::Marshal::CBOR::ByteString")
Truth table100%3/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Marshal::CBOR::ByteString")
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | && $value->isa('Zuzu::Marshal::CBOR::ByteString') ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 715 | ▶ | sub is_tagged { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_tagged: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 715 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 715 | ▶ | return blessed($value) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($value) and $value->isa("Zuzu::Marshal::CBOR::Tagged")
MC/DC100%2/2
builtin::blessed($value) and $value->isa("Zuzu::Marshal::CBOR::Tagged")
builtin::blessed($value)
$value->isa("Zuzu::Marshal::CBOR::Tagged")
Truth table100%3/3
A and B
A= builtin::blessed($value)B= $value->isa("Zuzu::Marshal::CBOR::Tagged")
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | && $value->isa('Zuzu::Marshal::CBOR::Tagged') ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 69 | ▶ | sub text_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text_value: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 69 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 69 | ▶ | die "Not a CBOR text string" if !is_text_string($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 69 | return $value->value; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | ▶ | sub bytes_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bytes_value: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | ▶ | die "Not a CBOR byte string" if !is_byte_string($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | return $value->bytes; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 28 | ▶ | sub tag_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag_number: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 28 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 28 | ▶ | die "Not a CBOR tagged value" if !is_tagged($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 28 | return $value->tag; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 29 | ▶ | sub tag_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag_value: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 29 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 29 | ▶ | die "Not a CBOR tagged value" if !is_tagged($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 29 | return $value->value; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 21 | ▶ | sub encode_one { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_one: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 21 | my ( $item ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 21 | my $bytes = CBOR::Free::encode( _to_cbor_free($item) ); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 21 | validate_profile($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 133 | 20 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 35 | ▶ | sub decode_one { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_one: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 35 | my ( $bytes ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 35 | $bytes = _bytes_scalar($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 35 | validate_profile($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 140 | my $decoder = CBOR::Free::Decoder->new->set_tag_handlers( | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 10 | ▶ | 55799 => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 10 | return Zuzu::Marshal::CBOR::Tagged->new( | |||||||||||||||||||||||||||||||||||||||||
| 143 | tag => 55799, | ||||||||||||||||||||||||||||||||||||||||||
| 144 | value => $_[0], | ||||||||||||||||||||||||||||||||||||||||||
| 145 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 146 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 20 | ); | |||||||||||||||||||||||||||||||||||||||||
| 148 | 20 | return _from_cbor_free( $decoder->decode($bytes) ); | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 57 | ▶ | sub validate_profile { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_profile: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 57 | my ( $bytes ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 57 | $bytes = _bytes_scalar($bytes); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 57 | my $offset = _scan_item( \$bytes, 0, 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 155 | 42 | ▶ | if ( $offset != length($bytes) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | die "Invalid Zuzu Marshal CBOR: trailing bytes after item"; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 41 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 675 | ▶ | sub _scan_item { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scan_item: called CC=16 SCAR=27.9
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 675 | my ( $bytes_ref, $offset, $top_level ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 675 | _require_available( $bytes_ref, $offset, 1, 'initial byte' ); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 675 | my $initial = unpack( 'C', substr( $$bytes_ref, $offset, 1 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 167 | 675 | $offset++; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 675 | my $major = int( $initial / 32 ); | |||||||||||||||||||||||||||||||||||||||||
| 170 | 675 | my $ai = $initial % 32; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 675 | ▶ | die "Invalid Zuzu Marshal CBOR: indefinite-length item" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | if $ai == 31; | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 673 | ▶ | die "Invalid Zuzu Marshal CBOR: reserved additional information" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ai >= 28 and $ai <= 30
MC/DC0%0/2
$ai >= 28 and $ai <= 30
$ai >= 28
$ai <= 30
Truth table33%1/3
A and B
A= $ai >= 28B= $ai <= 30
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | if $ai >= 28 and $ai <= 30; | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 673 | ▶ | if ( $major == 7 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 34 | return _scan_simple_or_float( $bytes_ref, $offset, $ai ); | |||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 639 | my ( $value, $next ) = _read_argument( $bytes_ref, $offset, $ai ); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 637 | $offset = $next; | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 637 | ▶ | if ( $major == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 230 | _assert_unsigned_number_range($value); | |||||||||||||||||||||||||||||||||||||||||
| 185 | 229 | return $offset; | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 407 | ▶ | if ( $major == 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | _assert_negative_number_range($value); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | return $offset; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 406 | ▶ | if ( $major == 2 or $major == 3 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$major == 2 or $major == 3
MC/DC100%2/2
$major == 2 or $major == 3
$major == 2
$major == 3
Truth table100%3/3
A or B
A= $major == 2B= $major == 3
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 77 | _require_available( $bytes_ref, $offset, $value, 'string payload' ); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 77 | return $offset + $value; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 329 | ▶ | if ( $major == 4 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 282 | for ( 1 .. $value ) { | |||||||||||||||||||||||||||||||||||||||||
| 197 | 589 | $offset = _scan_item( $bytes_ref, $offset, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 281 | return $offset; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 47 | ▶ | if ( $major == 5 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 23 | for ( 1 .. $value ) { | |||||||||||||||||||||||||||||||||||||||||
| 203 | 4 | $offset = _scan_item( $bytes_ref, $offset, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 204 | 4 | $offset = _scan_item( $bytes_ref, $offset, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 23 | return $offset; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 24 | ▶ | if ( $major == 6 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 24 | ▶ | die "Invalid Zuzu Marshal CBOR: unsupported tag $value" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $top_level or $value != 55799
MC/DC100%2/2
not $top_level or $value != 55799
not $top_level
$value != 55799
Truth table100%3/3
not(A) or B
A= not $top_levelB= $value != 55799
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | if !$top_level or $value != 55799; | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 21 | return _scan_item( $bytes_ref, $offset, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | die "Invalid Zuzu Marshal CBOR: unsupported major type"; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 34 | ▶ | sub _scan_simple_or_float { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scan_simple_or_float: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 34 | my ( $bytes_ref, $offset, $ai ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 34 | ▶ | return $offset if $ai == 20 or $ai == 21 or $ai == 22; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$ai == 20 or $ai == 21 or $ai == 22
$ai == 20 or $ai == 21
MC/DC100%3/3
$ai == 20 or $ai == 21 or $ai == 22
$ai == 20
$ai == 21
$ai == 22
Truth table100%4/4
A or B or C
A= $ai == 20B= $ai == 21C= $ai == 22
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 8 | ▶ | die "Invalid Zuzu Marshal CBOR: unsupported simple value" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ai < 24 or $ai == 24
MC/DC100%2/2
$ai < 24 or $ai == 24
$ai < 24
$ai == 24
Truth table100%3/3
A or B
A= $ai < 24B= $ai == 24
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | if $ai < 24 or $ai == 24; | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 6 | ▶ | die "Invalid Zuzu Marshal CBOR: half-precision float is invalid" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | if $ai == 25; | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 5 | ▶ | die "Invalid Zuzu Marshal CBOR: single-precision float is invalid" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | if $ai == 26; | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | ▶ | if ( $ai == 27 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 4 | _require_available( $bytes_ref, $offset, 8, 'binary64 float' ); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 4 | my $float = unpack( 'd>', substr( $$bytes_ref, $offset, 8 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 4 | ▶ | die "Invalid Zuzu Marshal CBOR: NaN is invalid" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | if $float != $float; | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 3 | ▶ | die "Invalid Zuzu Marshal CBOR: infinite float is invalid" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | if !is_finite_number($float); | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 2 | return $offset + 8; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | die "Invalid Zuzu Marshal CBOR: unsupported simple value"; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 639 | ▶ | sub _read_argument { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_argument: called CC=6 SCAR=18.4
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 639 | my ( $bytes_ref, $offset, $ai ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 639 | ▶ | return ( $ai, $offset ) if $ai < 24; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 34 | ▶ | if ( $ai == 24 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 8 | _require_available( $bytes_ref, $offset, 1, 'uint8 argument' ); | |||||||||||||||||||||||||||||||||||||||||
| 246 | 7 | my $value = unpack( 'C', substr( $$bytes_ref, $offset, 1 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 247 | 7 | _assert_shortest_argument( $value, 24 ); | |||||||||||||||||||||||||||||||||||||||||
| 248 | 6 | return ( $value, $offset + 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 26 | ▶ | if ( $ai == 25 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 24 | _require_available( $bytes_ref, $offset, 2, 'uint16 argument' ); | |||||||||||||||||||||||||||||||||||||||||
| 252 | 24 | my $value = unpack( 'n', substr( $$bytes_ref, $offset, 2 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 253 | 24 | _assert_shortest_argument( $value, 256 ); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 24 | return ( $value, $offset + 2 ); | |||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | ▶ | if ( $ai == 26 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | _require_available( $bytes_ref, $offset, 4, 'uint32 argument' ); | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my $value = unpack( 'N', substr( $$bytes_ref, $offset, 4 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | _assert_shortest_argument( $value, 65536 ); | |||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | return ( $value, $offset + 4 ); | |||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 2 | ▶ | if ( $ai == 27 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 2 | _require_available( $bytes_ref, $offset, 8, 'uint64 argument' ); | |||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | my ( $hi, $lo ) = unpack( 'NN', substr( $$bytes_ref, $offset, 8 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 265 | 2 | my $value = $hi * 4294967296 + $lo; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | _assert_shortest_argument( $value, 4294967296 ); | |||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | return ( $value, $offset + 8 ); | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | die "Invalid Zuzu Marshal CBOR: unsupported argument width"; | |||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 33 | ▶ | sub _assert_shortest_argument { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_shortest_argument: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 33 | my ( $value, $minimum ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 33 | ▶ | die "Invalid Zuzu Marshal CBOR: non-shortest integer or length" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | if $value < $minimum; | ||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 230 | ▶ | sub _assert_unsigned_number_range { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_unsigned_number_range: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 230 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 230 | ▶ | die "Invalid Zuzu Marshal CBOR: integer outside Zuzu Number range" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | if $value > MAX_SAFE_INTEGER; | ||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | ▶ | sub _assert_negative_number_range { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_negative_number_range: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | ▶ | die "Invalid Zuzu Marshal CBOR: integer outside Zuzu Number range" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | if $value > MAX_SAFE_INTEGER - 1; | ||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 790 | ▶ | sub _require_available { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_require_available: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 790 | my ( $bytes_ref, $offset, $length, $label ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 790 | ▶ | die "Invalid Zuzu Marshal CBOR: incomplete $label" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$length < 0 or $offset + $length > length $$bytes_ref
MC/DC50%1/2
$length < 0 or $offset + $length > length $$bytes_ref
$length < 0
$offset + $length > length $$bytes_ref
Truth table66%2/3
A or B
A= $length < 0B= $offset + $length > length $$bytes_ref
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | if $length < 0 or $offset + $length > length($$bytes_ref); | ||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | 325 | ▶ | sub _to_cbor_free { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_cbor_free: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 325 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 325 | ▶ | return undef if !defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 316 | ▶ | return CBOR::Free::tag( $value->tag, _to_cbor_free( $value->value ) ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | if is_tagged($value); | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 305 | ▶ | return _text_scalar( $value->value ) if is_text_string($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 271 | ▶ | return _bytes_scalar( $value->bytes ) if is_byte_string($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 268 | ▶ | return $value if is_cbor_bool($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 265 | ▶ | if ( ref($value) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 139 | return [ map { _to_cbor_free($_) } @{ $value } ]; | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 126 | ▶ | if ( ref($value) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 316 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 2 | _text_scalar($_) => _to_cbor_free( $value->{$_} ) | |||||||||||||||||||||||||||||||||||||||||
| 318 | 11 | } sort CORE::keys %{ $value } | |||||||||||||||||||||||||||||||||||||||||
| 319 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 115 | ▶ | if ( ref($value) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | die "Unsupported CBOR adapter value: " . ref($value); | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 115 | ▶ | return $value if _scalar_is_number($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | return _text_scalar($value); | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 323 | ▶ | sub _from_cbor_free { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_from_cbor_free: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 323 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 323 | ▶ | return undef if !defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 314 | ▶ | if ( is_tagged($value) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 10 | return tag( $value->tag, _from_cbor_free( $value->value ) ); | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 304 | ▶ | if ( ref($value) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 139 | return [ map { _from_cbor_free($_) } @{ $value } ]; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 165 | ▶ | if ( ref($value) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 341 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 2 | $_ => _from_cbor_free( $value->{$_} ) | |||||||||||||||||||||||||||||||||||||||||
| 343 | 11 | } sort CORE::keys %{ $value } | |||||||||||||||||||||||||||||||||||||||||
| 344 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 154 | ▶ | if ( ref($value) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 3 | ▶ | return $value if is_cbor_bool($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | die "Unsupported decoded CBOR adapter value: " . ref($value); | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 151 | ▶ | return $value if _scalar_is_number($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 36 | ▶ | return utf8::is_utf8($value) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | ? text_string($value) | ||||||||||||||||||||||||||||||||||||||||||
| 354 | : byte_string($value); | ||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 36 | ▶ | sub _text_scalar { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_text_scalar: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 36 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 36 | ▶ | $value //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$value //= ""
MC/DC0%0/1
$value //= ""
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 36 | return Encode::decode( | |||||||||||||||||||||||||||||||||||||||||
| 361 | 'UTF-8', | ||||||||||||||||||||||||||||||||||||||||||
| 362 | Encode::encode( 'UTF-8', "$value", Encode::FB_CROAK ), | ||||||||||||||||||||||||||||||||||||||||||
| 363 | Encode::FB_CROAK, | ||||||||||||||||||||||||||||||||||||||||||
| 364 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 101 | ▶ | sub _bytes_scalar { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bytes_scalar: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 101 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 369 | 101 | ▶ | $value //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$value //= ""
MC/DC0%0/1
$value //= ""
$value
Truth table50%1/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 101 | my $bytes = "$value"; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 101 | ▶ | utf8::encode($bytes) if utf8::is_utf8($bytes); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 101 | ▶ | utf8::downgrade( $bytes, 1 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | or die "CBOR byte string contains non-byte characters"; | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 101 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 266 | ▶ | sub _scalar_is_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scalar_is_number: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 266 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 266 | ▶ | return 0 if ref($value); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 266 | my $flags = svref_2object(\$value)->FLAGS; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 266 | ▶ | return ( $flags & ( SVf_IOK | SVf_NOK ) ) && !( $flags & SVf_POK ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$flags & 768 and not $flags & 1024
MC/DC50%1/2
$flags & 768 and not $flags & 1024
$flags & 768
not $flags & 1024
Truth table66%2/3
A and not(B)
A= $flags & 768B= not $flags & 1024
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | ? 1 | ||||||||||||||||||||||||||||||||||||||||||
| 383 | : 0; | ||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | Zuzu::Marshal::CBOR - narrow CBOR adapter for Zuzu Marshal | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | Wraps C<CBOR::Free> behind explicit operations for the CBOR data types | ||||||||||||||||||||||||||||||||||||||||||
| 397 | used by Zuzu Marshal. | ||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||
| 399 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | B<< Zuzu::Marshal::CBOR >> is copyright Toby Inkster. | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | It is free software; you may redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 404 | the terms of either the Artistic License 1.0 or the GNU General Public | ||||||||||||||||||||||||||||||||||||||||||
| 405 | License version 2. | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | =cut | ||||||||||||||||||||||||||||||||||||||||||