| 1 | 9 | ▶ | use 5.008008; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | package Data::Smile::PP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Scalar::Util qw( blessed dualvar looks_like_number ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use constant HEADER => "\x3A\x29\x0A\x03"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use constant MAX_SAFE_INT_DOUBLE => 9_007_199_254_740_992; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use constant MIN_SIGNED_64BIT => -9_223_372_036_854_775_808; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use constant MAX_UNSIGNED_64BIT => 18_446_744_073_709_551_615; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 9 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 9 | our $VERSION = '0.001000'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use Exporter::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | our @ISA = qw( Exporter::Tiny ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | our @EXPORT_OK = qw( encode_smile decode_smile dump_smile load_smile ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 9 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=10 SCAR=23.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 9 | my @HELPERS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | _is_arrayref => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | [ 'Ref::Util::XS', 'is_plain_arrayref' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | [ 'Type::Tiny::XS', 'ArrayRef' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | q{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | my ( $v ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ref( $v ) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | _is_hashref => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | [ 'Ref::Util::XS', 'is_plain_hashref' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | [ 'Type::Tiny::XS', 'HashRef' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | q{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | my ( $v ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ref( $v ) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | _is_dual => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | [ 'Scalar::Util', 'isdual' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | q{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | use B (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | my $f = B::svref_2object(\$_[0])->FLAGS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | my $SVp_POK = eval { B::SVp_POK() } || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | my $SVp_IOK = eval { B::SVp_IOK() } || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | my $SVp_NOK = eval { B::SVp_NOK() } || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | my $pok = $f & ( B::SVf_POK | $SVp_POK ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | my $niok = $f & ( B::SVf_IOK | B::SVf_NOK | $SVp_IOK | $SVp_NOK ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | !!( $pok and $niok ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | _is_bool => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | [ 'builtin', 'is_bool' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | q{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | my $value = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | return !!0 unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | return !!0 if ref $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | return !!0 unless _is_dual( $value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | return !!1 if $value and "$value" eq '1' and $value + 0 == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | return !!1 if not $value and "$value" eq q'' and $value + 0 == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | return !!0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | _created_as_number => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | [ 'builtin', 'created_as_number' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | q{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | use B (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | my $value = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | return !!0 unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | return !!0 if ref $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | return !!0 if utf8::is_utf8( $value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | my $b_obj = B::svref_2object(\$value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | my $flags = $b_obj->FLAGS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | return !!1 if $flags & ( B::SVp_IOK() | B::SVp_NOK() ) and not( $flags & B::SVp_POK() ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | return !!0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | _created_as_string => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | [ 'builtin', 'created_as_string' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | q{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | my $value = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | defined $value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | and not ref $value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | and not _is_bool( $value ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | and not _created_as_number( $value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 9 | ▶ | HELPER: while ( @HELPERS ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 54 | my ( $name, $implementation_list ) = splice @HELPERS, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 54 | IMPLEMENTATION: for my $i ( @$implementation_list ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 54 | ▶ | if ( ref $i ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 54 | my ( $module, $external_function_name ) = @$i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 54 | ▶ | if ( $module eq 'builtin' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 27 | ▶ | $] >= 5.038 or next IMPLEMENTATION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 27 | require experimental; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 27 | experimental->import( 'builtin' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 27 | ▶ | if ( defined &{"builtin::$external_function_name"} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 27 | *$name = \&{"builtin::$external_function_name"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 27 | next HELPER; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 27 | ▶ | eval "require $module; 1" or next IMPLEMENTATION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 27 | ▶ | my $f = $module->can( $external_function_name ) or next IMPLEMENTATION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 27 | *$name = $f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 27 | next HELPER; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | next HELPER if eval "sub $name { $i }; 1"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 46 | ▶ | sub _check_opts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_opts: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 46 | my ( $name, $opts, $allowed ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 46 | ▶ | return {} if not defined $opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 13 | ▶ | die 'Options must be a hash reference' if not _is_hashref( $opts ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 13 | for my $k ( keys %$opts ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 14 | ▶ | die "Unknown option for $name: $k" if not $allowed->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 10 | return $opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub _pack_u32 { pack('N', $_[0]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pack_u32: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub _unpack_u32 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unpack_u32: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my ( $buf, $pos ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | die 'Unexpected EOF' if $$pos + 4 > length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $v = unpack('N', substr($$buf, $$pos, 4)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $$pos += 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | return $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub _pack_str { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pack_str: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my ( $s ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | my $flag = utf8::is_utf8( $s ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $bytes = $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | utf8::encode( $bytes ) if $flag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | return chr( $flag ) . _pack_u32( length( $bytes ) ) . $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub _unpack_str { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unpack_str: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my ( $buf, $pos ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | die 'Unexpected EOF' if $$pos >= length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $flag = ord substr( $$buf, $$pos++, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $len = _unpack_u32( $buf, $pos ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | die 'Unexpected EOF' if $$pos + $len > length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my $s = substr( $$buf, $$pos, $len ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $$pos += $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | utf8::decode( $s ) if $flag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 49 | ▶ | sub _maybe_to_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_maybe_to_json: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 49 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 49 | ▶ | return $v if not ref $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 19 | ▶ | return $v if not blessed $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | ▶ | return $v if not $v->can( 'TO_JSON' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | return $v->TO_JSON; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub _encode_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_value: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $v = _maybe_to_json( $v ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if ( not defined $v ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | return 'U'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if ( _is_arrayref( $v ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my $out = 'A' . _pack_u32(scalar @$v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $out .= _encode_value( $_ ) for @$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | if ( _is_hashref( $v ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my @keys = keys %$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $out = 'H' . _pack_u32(scalar @keys); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | for my $k (@keys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $out .= _pack_str( $k ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $out .= _encode_value( $v->{$k} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | die 'Unsupported reference in encode_smile' if ref $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | if ( _is_bool( $v ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | return 'b' . ($v ? "\x01" : "\x00"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if ( _created_as_string( $v ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | return 'S' . _pack_str( $v ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if ( _created_as_number( $v ) or looks_like_number( $v ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
&_created_as_number($v) or &looks_like_number($v)
MC/DC0%0/2
&_created_as_number($v) or &looks_like_number($v)
&_created_as_number($v)
&looks_like_number($v)
Truth table0%0/3
A or B
A= &_created_as_number($v)B= &looks_like_number($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if ( $v =~ /\A-?[0-9]+\z/ and $v >= -9_223_372_036_854_775_808 and $v <= 9_223_372_036_854_775_807 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$v =~ /\A-?[0-9]+\z/ and $v >= '-9223372036854775808' and $v <= '9223372036854775807'
$v =~ /\A-?[0-9]+\z/ and $v >= '-9223372036854775808'
MC/DC0%0/3
$v =~ /\A-?[0-9]+\z/ and $v >= '-9223372036854775808' and $v <= '9223372036854775807'
$v =~ /\A-?[0-9]+\z/
$v >= '-9223372036854775808'
$v <= '9223372036854775807'
Truth table0%0/4
A and B and C
A= $v =~ /\A-?[0-9]+\z/B= $v >= '-9223372036854775808'C= $v <= '9223372036854775807'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | return 'I' . pack('q>', 0 + $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | my $n = "$v"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | return 'N' . _pack_str( $n ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return 'S' . _pack_str( "$v" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 9 | my ( $jppT, $jppF ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | sub _decode_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_value: not called CC=19 SCAR=59.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my ( $buf, $pos, $json_bool, $use_bigint ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | die 'Unexpected EOF' if $$pos >= length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $tag = substr $$buf, $$pos++, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | return undef if $tag eq 'U'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if ( $tag eq 'b' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | die 'Unexpected EOF' if $$pos >= length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if ( $json_bool ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if ( not defined $jppT ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | require JSON::PP; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $jppT = JSON::PP::true(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | $jppF = JSON::PP::false(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | return ord substr( $$buf, $$pos++, 1 ) ? $jppT : $jppF; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | return ord substr( $$buf, $$pos++, 1 ) ? !!1 : !!0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if ( $tag eq 'S' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return _unpack_str( $buf, $pos ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | if ( $tag eq 'I' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | die 'Unexpected EOF' if $$pos + 8 > length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $v = unpack( 'q>', substr( $$buf, $$pos, 8 ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $$pos += 8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | return 0 + $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if ( $tag eq 'N' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | my $s = _unpack_str( $buf, $pos ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | if ( $use_bigint and $s =~ /\A-?[0-9]{19,}\z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$use_bigint and $s =~ /\A-?[0-9]{19,}\z/
MC/DC0%0/2
$use_bigint and $s =~ /\A-?[0-9]{19,}\z/
$use_bigint
$s =~ /\A-?[0-9]{19,}\z/
Truth table0%0/3
A and B
A= $use_bigintB= $s =~ /\A-?[0-9]{19,}\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | require Math::BigInt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | return Math::BigInt->new( $s ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | return 0 + $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if ( $tag eq 'A' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $n = _unpack_u32( $buf, $pos ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my @a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | push @a, _decode_value( $buf, $pos, $json_bool, $use_bigint ) for 1..$n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | return \@a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ( $tag eq 'H' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $n = _unpack_u32( $buf, $pos ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my %h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | for (1..$n) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my $k = _unpack_str( $buf, $pos ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $h{$k} = _decode_value( $buf, $pos, $json_bool, $use_bigint ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | return \%h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | die "Unknown type tag in payload"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 5133 | ▶ | sub _normalize_smile_float { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_smile_float: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 5133 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 5133 | my $text = "$v"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 5133 | my $num = 0 + $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 5133 | my $integer_text = sprintf '%.0f', $num; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 5133 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$num == 0 + $integer_text and abs $num >= '9007199254740992' and $num >= '-9223372036854775808' and $num <= '18446744073709551615'
$num == 0 + $integer_text and abs $num >= '9007199254740992' and $num >= '-9223372036854775808'
$num == 0 + $integer_text and abs $num >= '9007199254740992'
MC/DC100%4/4
$num == 0 + $integer_text and abs $num >= '9007199254740992' and $num >= '-9223372036854775808' and $num <= '18446744073709551615'
$num == 0 + $integer_text
abs $num >= '9007199254740992'
$num >= '-9223372036854775808'
$num <= '18446744073709551615'
Truth table100%5/5
A and B and C and D
A= $num == 0 + $integer_textB= abs $num >= '9007199254740992'C= $num >= '-9223372036854775808'D= $num <= '18446744073709551615'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | $num == 0 + $integer_text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | and abs( $num ) >= MAX_SAFE_INT_DOUBLE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | and $num >= MIN_SIGNED_64BIT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | and $num <= MAX_UNSIGNED_64BIT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 198 | return dualvar( $num, $integer_text ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 4935 | return dualvar( $num, $text ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 8596 | ▶ | sub _decode_vint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_vint: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 8596 | my ( $buf, $pos ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 8596 | my $v = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 8596 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 21929 | ▶ | die 'Unexpected EOF' if $$pos >= length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 21929 | my $byte = ord substr( $$buf, $$pos++, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 21929 | ▶ | if ( $byte & 0x80 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 8596 | $v = ( $v << 6 ) | ( $byte & 0x3F ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 8596 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 13333 | $v = ( $v << 7 ) | ( $byte & 0x7F ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 8596 | return $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 11865 | ▶ | sub _zigzag_decode { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_zigzag_decode: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 11865 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 11865 | ▶ | return ( $v & 1 ) ? -( ( $v + 1 ) >> 1 ) : ( $v >> 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 5133 | ▶ | sub _decode_fixed_7bit_bytes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_fixed_7bit_bytes: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 5133 | my ( $buf, $pos, $groups, $bits_needed ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 5133 | my $bits = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 5133 | for ( 1 .. $groups ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 51330 | ▶ | die 'Unexpected EOF' if $$pos >= length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 51330 | my $byte = ord substr( $$buf, $$pos++, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 51330 | $bits .= sprintf '%07b', $byte & 0x7F; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 5133 | ▶ | if ( defined $bits_needed and length( $bits ) > $bits_needed ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $bits_needed and length $bits > $bits_needed
MC/DC0%0/2
defined $bits_needed and length $bits > $bits_needed
defined $bits_needed
length $bits > $bits_needed
Truth table33%1/3
A and B
A= defined $bits_neededB= length $bits > $bits_needed
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 5133 | $bits = substr( $bits, -$bits_needed ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 5133 | my $out = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 5133 | ▶ | for ( my $i = 0; $i < length $bits; $i += 8 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 41064 | $out .= chr oct( '0b' . substr( $bits, $i, 8 ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 5133 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 4 | ▶ | sub _decode_7bit_binary { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_7bit_binary: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 4 | my ( $buf, $pos, $len ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 4 | my $bits = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 4 | ▶ | while ( length $bits < $len * 8 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 60 | ▶ | die 'Unexpected EOF' if $$pos >= length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 60 | my $byte = ord substr( $$buf, $$pos++, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 60 | $bits .= sprintf '%07b', $byte & 0x7F; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 4 | $bits = substr( $bits, 0, $len * 8 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 4 | my $out = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 4 | ▶ | for ( my $i = 0; $i < length $bits; $i += 8 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 52 | $out .= chr oct( '0b' . substr( $bits, $i, 8 ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 4 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 2 | ▶ | sub _raw_bytes_to_native_number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_raw_bytes_to_native_number: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 2 | my ( $raw ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 2 | my $v = 0.0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 2 | for my $byte ( unpack 'C*', $raw ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 26 | $v = ( $v * 256 ) + $byte; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 2 | return 0 + $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 472 | ▶ | sub _decode_long_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_long_text: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 472 | my ( $buf, $pos, $utf8 ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 472 | my $s = q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 472 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 178546 | ▶ | die 'Unexpected EOF' if $$pos >= length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 178546 | my $byte = ord substr( $$buf, $$pos++, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 178546 | ▶ | last if $byte == 0xFC; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 178074 | $s .= chr $byte; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 472 | ▶ | utf8::decode( $s ) if $utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 472 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 4046 | ▶ | sub _shared_push { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_shared_push: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 4046 | my ( $ary, $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 4046 | ▶ | return if not defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 4046 | ▶ | if ( @$ary >= 1024 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 1 | @$ary = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 4046 | push @$ary, $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 53161 | ▶ | sub _decode_value_smile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_value_smile: called CC=53 SCAR=46.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 53161 | my ( $buf, $pos, $ctx, $json_bool, $use_bigint ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 53161 | ▶ | die 'Unexpected EOF' if $$pos >= length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 53161 | my $t = ord substr( $$buf, $$pos++, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 53161 | ▶ | if ( $t <= 0x1F ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 11414 | ▶ | die 'Invalid shared value reference' if $t == 0 or not defined $ctx->{shared_values}[ $t - 1 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$t == 0 or not defined $ctx->{"shared_values"}[$t - 1]
MC/DC0%0/2
$t == 0 or not defined $ctx->{"shared_values"}[$t - 1]
$t == 0
not defined $ctx->{"shared_values"}[$t - 1]
Truth table33%1/3
A or not(B)
A= $t == 0B= not defined $ctx->{"shared_values"}[$t - 1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 11414 | return $ctx->{shared_values}[ $t - 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 41747 | ▶ | if ( $t == 0x20 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 3 | ▶ | _shared_push( $ctx->{shared_values}, q{} ) if $ctx->{enable_shared_values}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 3 | return q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 41744 | ▶ | if ( $t == 0x21 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 6 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 41738 | ▶ | if ( $t == 0x22 or $t == 0x23 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$t == 34 or $t == 35
MC/DC100%2/2
$t == 34 or $t == 35
$t == 34
$t == 35
Truth table100%3/3
A or B
A= $t == 34B= $t == 35
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 5 | my $is_true = $t == 0x23; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 5 | ▶ | if ( $json_bool ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 5 | ▶ | if ( not defined $jppT ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 1 | require JSON::PP; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 1 | $jppT = JSON::PP::true(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | $jppF = JSON::PP::false(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 5 | ▶ | return $is_true ? $jppT : $jppF; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | return $is_true ? !!1 : !!0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 41733 | ▶ | if ( $t == 0x24 or $t == 0x25 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t == 36 or $t == 37
MC/DC50%1/2
$t == 36 or $t == 37
$t == 36
$t == 37
Truth table66%2/3
A or B
A= $t == 36B= $t == 37
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 8592 | my $v = _zigzag_decode( _decode_vint( $buf, $pos ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 8592 | return $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 33141 | ▶ | if ( $t == 0x26 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 4 | my $len = _decode_vint( $buf, $pos ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 4 | my $raw = _decode_7bit_binary( $buf, $pos, $len ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 4 | my $hex = unpack 'H*', $raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 4 | ▶ | if ( $use_bigint ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 2 | require Math::BigInt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 2 | ▶ | return Math::BigInt->from_hex( '0x' . ( $hex or '0' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$hex || '0'
MC/DC0%0/1
$hex || '0'
$hex
Truth table50%1/2
A
A= $hex
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 2 | return _raw_bytes_to_native_number( $raw ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 33137 | ▶ | if ( $t == 0x2A ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | my $scale = _zigzag_decode( _decode_vint( $buf, $pos ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | my $len = _decode_vint( $buf, $pos ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my $raw = _decode_7bit_binary( $buf, $pos, $len ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | require Math::BigInt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | require Math::BigFloat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my $hex = unpack 'H*', $raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | my $unscaled = Math::BigInt->from_hex( '0x' . ( $hex or '0' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$hex || '0'
MC/DC0%0/1
$hex || '0'
$hex
Truth table0%0/2
A
A= $hex
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my $v = Math::BigFloat->new( $unscaled ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | if ( $scale > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | $v->bdiv( Math::BigFloat->new( 10 )->bpow( $scale ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | elsif ( $scale < 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | $v->bmul( Math::BigFloat->new( 10 )->bpow( -$scale ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | return $use_bigint ? $v : 0 + $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 33137 | ▶ | if ( $t == 0x28 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | my $raw = _decode_fixed_7bit_bytes( $buf, $pos, 5, 32 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | my $v = unpack( 'f>', $raw ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | return _normalize_smile_float( $v ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 33137 | ▶ | if ( $t == 0x29 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 5133 | my $raw = _decode_fixed_7bit_bytes( $buf, $pos, 10, 64 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 5133 | my $v = unpack( 'd>', $raw ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 5133 | return _normalize_smile_float( $v ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 28004 | ▶ | if ( $t >= 0x40 and $t <= 0x7F ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t >= 64 and $t <= 127
MC/DC50%1/2
$t >= 64 and $t <= 127
$t >= 64
$t <= 127
Truth table66%2/3
A and B
A= $t >= 64B= $t <= 127
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 3316 | ▶ | my $len = ( $t <= 0x5F ) ? ( ( $t & 0x1F ) + 1 ) : ( ( $t & 0x1F ) + 33 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 3316 | ▶ | die 'Unexpected EOF' if $$pos + $len > length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 3316 | my $s = substr( $$buf, $$pos, $len ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 3316 | $$pos += $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 3316 | ▶ | _shared_push( $ctx->{shared_values}, $s ) if $ctx->{enable_shared_values}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 3316 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 24688 | ▶ | if ( $t >= 0x80 and $t <= 0xBF ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t >= 128 and $t <= 191
MC/DC50%1/2
$t >= 128 and $t <= 191
$t >= 128
$t <= 191
Truth table66%2/3
A and B
A= $t >= 128B= $t <= 191
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 16 | ▶ | my $len = ( $t <= 0x9F ) ? ( ( $t & 0x1F ) + 2 ) : ( ( $t & 0x1F ) + 34 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 16 | ▶ | die 'Unexpected EOF' if $$pos + $len > length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 16 | my $s = substr( $$buf, $$pos, $len ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 16 | $$pos += $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 16 | utf8::decode( $s ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 16 | ▶ | _shared_push( $ctx->{shared_values}, $s ) if $ctx->{enable_shared_values}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 16 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 24672 | ▶ | if ( $t >= 0xC0 and $t <= 0xDF ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t >= 192 and $t <= 223
MC/DC50%1/2
$t >= 192 and $t <= 223
$t >= 192
$t <= 223
Truth table66%2/3
A and B
A= $t >= 192B= $t <= 223
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 3273 | return _zigzag_decode( $t & 0x1F ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 21399 | ▶ | if ( $t >= 0xE0 and $t <= 0xE3 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t >= 224 and $t <= 227
MC/DC50%1/2
$t >= 224 and $t <= 227
$t >= 224
$t <= 227
Truth table66%2/3
A and B
A= $t >= 224B= $t <= 227
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 454 | return _decode_long_text( $buf, $pos, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 20945 | ▶ | if ( $t >= 0xE4 and $t <= 0xE7 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t >= 228 and $t <= 231
MC/DC50%1/2
$t >= 228 and $t <= 231
$t >= 228
$t <= 231
Truth table66%2/3
A and B
A= $t >= 228B= $t <= 231
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 18 | return _decode_long_text( $buf, $pos, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 20927 | ▶ | if ( $t == 0xE8 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | my $len = _decode_vint( $buf, $pos ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | return _decode_7bit_binary( $buf, $pos, $len ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 20927 | ▶ | if ( $t >= 0xEC and $t <= 0xEF ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t >= 236 and $t <= 239
MC/DC50%1/2
$t >= 236 and $t <= 239
$t >= 236
$t <= 239
Truth table66%2/3
A and B
A= $t >= 236B= $t <= 239
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 9606 | ▶ | die 'Unexpected EOF' if $$pos >= length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 9606 | my $lsb = ord substr( $$buf, $$pos++, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 9606 | my $idx = ( ( $t & 0x03 ) << 8 ) | $lsb; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 9606 | ▶ | die 'Invalid shared value reference' if $idx < 31 or not defined $ctx->{shared_values}[$idx]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$idx < 31 or not defined $ctx->{"shared_values"}[$idx]
MC/DC0%0/2
$idx < 31 or not defined $ctx->{"shared_values"}[$idx]
$idx < 31
not defined $ctx->{"shared_values"}[$idx]
Truth table33%1/3
A or not(B)
A= $idx < 31B= not defined $ctx->{"shared_values"}[$idx]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 9606 | return $ctx->{shared_values}[$idx]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 11321 | ▶ | if ( $t == 0xF8 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 734 | my @a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 734 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 20260 | ▶ | die 'Unexpected EOF' if $$pos >= length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 20260 | ▶ | last if ord substr( $$buf, $$pos, 1 ) == 0xF9; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 19526 | push @a, _decode_value_smile( $buf, $pos, $ctx, $json_bool, $use_bigint ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 734 | $$pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 734 | return \@a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 10587 | ▶ | if ( $t == 0xFA ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 10587 | my %h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 10587 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 44192 | my $k = _decode_key_smile( $buf, $pos, $ctx ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 44192 | ▶ | last if not defined $k; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 33605 | $h{$k} = _decode_value_smile( $buf, $pos, $ctx, $json_bool, $use_bigint ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 10587 | return \%h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | die "Unknown type tag in payload"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 44192 | ▶ | sub _decode_key_smile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_key_smile: called CC=23 SCAR=38.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 44192 | my ( $buf, $pos, $ctx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 44192 | ▶ | die 'Unexpected EOF' if $$pos >= length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 44192 | my $t = ord substr( $$buf, $$pos++, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 44192 | ▶ | return undef if $t == 0xFB; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 33605 | ▶ | if ( $t == 0x20 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | _shared_push( $ctx->{shared_names}, q{} ) if $ctx->{enable_shared_names}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | return q{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 33605 | ▶ | if ( $t >= 0x30 and $t <= 0x33 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t >= 48 and $t <= 51
MC/DC50%1/2
$t >= 48 and $t <= 51
$t >= 48
$t <= 51
Truth table66%2/3
A and B
A= $t >= 48B= $t <= 51
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 9884 | ▶ | die 'Unexpected EOF' if $$pos >= length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 9884 | my $lsb = ord substr( $$buf, $$pos++, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 9884 | my $idx = ( ( $t & 0x03 ) << 8 ) | $lsb; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 9884 | ▶ | die 'Invalid shared name reference' if $idx < 64 or not defined $ctx->{shared_names}[$idx]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$idx < 64 or not defined $ctx->{"shared_names"}[$idx]
MC/DC0%0/2
$idx < 64 or not defined $ctx->{"shared_names"}[$idx]
$idx < 64
not defined $ctx->{"shared_names"}[$idx]
Truth table33%1/3
A or not(B)
A= $idx < 64B= not defined $ctx->{"shared_names"}[$idx]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 9884 | return $ctx->{shared_names}[$idx]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 23721 | ▶ | if ( $t >= 0x40 and $t <= 0x7F ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t >= 64 and $t <= 127
MC/DC50%1/2
$t >= 64 and $t <= 127
$t >= 64
$t <= 127
Truth table66%2/3
A and B
A= $t >= 64B= $t <= 127
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 23005 | my $idx = $t & 0x3F; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 23005 | ▶ | die 'Invalid shared name reference' if not defined $ctx->{shared_names}[$idx]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 23005 | return $ctx->{shared_names}[$idx]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 716 | ▶ | if ( $t >= 0x80 and $t <= 0xBF ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$t >= 128 and $t <= 191
MC/DC50%1/2
$t >= 128 and $t <= 191
$t >= 128
$t <= 191
Truth table66%2/3
A and B
A= $t >= 128B= $t <= 191
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 715 | my $len = ( $t & 0x3F ) + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 715 | ▶ | die 'Unexpected EOF' if $$pos + $len > length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 715 | my $k = substr( $$buf, $$pos, $len ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 715 | $$pos += $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 715 | ▶ | _shared_push( $ctx->{shared_names}, $k ) if $ctx->{enable_shared_names}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 715 | return $k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 1 | ▶ | if ( $t >= 0xC0 and $t <= 0xF7 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$t >= 192 and $t <= 247
MC/DC0%0/2
$t >= 192 and $t <= 247
$t >= 192
$t <= 247
Truth table33%1/3
A and B
A= $t >= 192B= $t <= 247
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 1 | my $len = ( $t & 0x3F ) + 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 1 | ▶ | die 'Unexpected EOF' if $$pos + $len > length $$buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 1 | my $k = substr( $$buf, $$pos, $len ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 1 | $$pos += $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 1 | utf8::decode( $k ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 1 | ▶ | _shared_push( $ctx->{shared_names}, $k ) if $ctx->{enable_shared_names}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 1 | return $k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | if ( $t == 0x34 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | my $k = _decode_long_text( $buf, $pos, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | _shared_push( $ctx->{shared_names}, $k ) if $ctx->{enable_shared_names}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | return $k; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | die 'Invalid object key token'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | ▶ | sub _contains_shared_name_pattern { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_contains_shared_name_pattern: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | return 0 if not _is_arrayref( $v ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | for my $e ( @$v ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | ▶ | next if not _is_hashref( $e ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | for my $k ( keys %$e ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | ▶ | return 1 if ++$seen{$k} > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | ▶ | sub _contains_shared_short_string_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_contains_shared_short_string_value: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | return 0 if not _is_arrayref( $v ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | for my $e ( @$v ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | next if ref $e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | next if not defined( $e ) or utf8::is_utf8( $e ) or length( $e ) > 64; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not defined $e or utf8::is_utf8($e) or length $e > 64
not defined $e or utf8::is_utf8($e)
MC/DC0%0/3
not defined $e or utf8::is_utf8($e) or length $e > 64
not defined $e
utf8::is_utf8($e)
length $e > 64
Truth table0%0/4
not(A) or B or C
A= not defined $eB= utf8::is_utf8($e)C= length $e > 64
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | ▶ | return 1 if ++$seen{$e} > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | ▶ | sub _encode_vint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_vint: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | my @groups; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | unshift @groups, $v & 0x7F; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | $v >>= 7; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } while ( $v > 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | $groups[-1] |= 0x80; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | return pack 'C*', @groups; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 15 | ▶ | sub _zigzag_encode { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_zigzag_encode: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 15 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 15 | ▶ | return ( $v < 0 ) ? ( ( -$v ) * 2 - 1 ) : ( $v * 2 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | ▶ | sub _encode_7bit_binary { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_7bit_binary: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | my ( $raw ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | my $bits = join q{}, map { sprintf '%08b', $_ } unpack 'C*', $raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | my $pad = ( 7 - ( length( $bits ) % 7 ) ) % 7; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | $bits .= '0' x $pad; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | my @bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | for ( my $i = 0; $i < length $bits; $i += 7 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | push @bytes, oct '0b' . substr( $bits, $i, 7 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | return pack 'C*', @bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 9 | ▶ | sub _encode_short_or_long_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_short_or_long_text: called CC=14 SCAR=34.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 9 | my ( $bytes, $is_utf8 ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 9 | my $len = length $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 9 | ▶ | if ( not $is_utf8 and $len >= 1 and $len <= 32 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not $is_utf8 and $len >= 1 and $len <= 32
not $is_utf8 and $len >= 1
MC/DC33%1/3
not $is_utf8 and $len >= 1 and $len <= 32
not $is_utf8
$len >= 1
$len <= 32
Truth table50%2/4
not(A) and B and C
A= not $is_utf8B= $len >= 1C= $len <= 32
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 8 | return chr( 0x40 + $len - 1 ) . $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 1 | ▶ | if ( not $is_utf8 and $len >= 33 and $len <= 64 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not $is_utf8 and $len >= 33 and $len <= 64
not $is_utf8 and $len >= 33
MC/DC0%0/3
not $is_utf8 and $len >= 33 and $len <= 64
not $is_utf8
$len >= 33
$len <= 64
Truth table25%1/4
not(A) and B and C
A= not $is_utf8B= $len >= 33C= $len <= 64
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | return chr( 0x60 + $len - 33 ) . $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 1 | ▶ | if ( $is_utf8 and $len >= 2 and $len <= 33 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$is_utf8 and $len >= 2 and $len <= 33
$is_utf8 and $len >= 2
MC/DC0%0/3
$is_utf8 and $len >= 2 and $len <= 33
$is_utf8
$len >= 2
$len <= 33
Truth table25%1/4
A and B and C
A= $is_utf8B= $len >= 2C= $len <= 33
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | return chr( 0x80 + $len - 2 ) . $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 1 | ▶ | if ( $is_utf8 and $len >= 34 and $len <= 65 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$is_utf8 and $len >= 34 and $len <= 65
$is_utf8 and $len >= 34
MC/DC0%0/3
$is_utf8 and $len >= 34 and $len <= 65
$is_utf8
$len >= 34
$len <= 65
Truth table25%1/4
A and B and C
A= $is_utf8B= $len >= 34C= $len <= 65
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | return chr( 0xA0 + $len - 34 ) . $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 1 | ▶ | my $marker = $is_utf8 ? 0xE4 : 0xE0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 1 | return chr( $marker ) . $bytes . "\xFC"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 23 | ▶ | sub _encode_key_smile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_key_smile: called CC=15 SCAR=36.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 23 | my ( $key, $ctx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 23 | ▶ | if ( defined $ctx->{name_to_idx}{$key} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 1 | my $idx = $ctx->{name_to_idx}{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 1 | ▶ | if ( $idx <= 63 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 1 | return chr( 0x40 + $idx ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | ▶ | if ( $idx <= 1023 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | my $msb = ( $idx >> 8 ) & 0x03; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | my $lsb = $idx & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | return chr( 0x30 + $msb ) . chr( $lsb ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 22 | ▶ | if ( $ctx->{enable_shared_names} and @{$ctx->{shared_names}} < 1024 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ctx->{"enable_shared_names"} and @{$ctx->{"shared_names"};} < 1024
MC/DC50%1/2
$ctx->{"enable_shared_names"} and @{$ctx->{"shared_names"};} < 1024
$ctx->{"enable_shared_names"}
@{$ctx->{"shared_names"};} < 1024
Truth table66%2/3
A and B
A= $ctx->{"enable_shared_names"}B= @{$ctx->{"shared_names"};} < 1024
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 19 | ▶ | if ( @{$ctx->{shared_names}} >= 1024 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | $ctx->{shared_names} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | $ctx->{name_to_idx} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 19 | my $idx = scalar @{$ctx->{shared_names}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 19 | $ctx->{name_to_idx}{$key} = $idx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 19 | push @{$ctx->{shared_names}}, $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 22 | ▶ | return "\x20" if $key eq q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 22 | my $bytes = $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 22 | my $is_utf8 = utf8::is_utf8 $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 22 | ▶ | utf8::encode( $bytes ) if $is_utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 22 | my $len = length $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 22 | ▶ | if ( not $is_utf8 and $len >= 1 and $len <= 64 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not $is_utf8 and $len >= 1 and $len <= 64
not $is_utf8 and $len >= 1
MC/DC0%0/3
not $is_utf8 and $len >= 1 and $len <= 64
not $is_utf8
$len >= 1
$len <= 64
Truth table25%1/4
not(A) and B and C
A= not $is_utf8B= $len >= 1C= $len <= 64
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 22 | return chr( 0x80 + $len - 1 ) . $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | ▶ | if ( $is_utf8 and $len >= 2 and $len <= 65 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$is_utf8 and $len >= 2 and $len <= 65
$is_utf8 and $len >= 2
MC/DC0%0/3
$is_utf8 and $len >= 2 and $len <= 65
$is_utf8
$len >= 2
$len <= 65
Truth table0%0/4
A and B and C
A= $is_utf8B= $len >= 2C= $len <= 65
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | return chr( 0xC0 + $len - 2 ) . $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | return "\x34" . $bytes . "\xFC"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 49 | ▶ | sub _encode_value_smile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_encode_value_smile: called CC=23 SCAR=34.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 49 | my ( $v, $ctx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 49 | $v = _maybe_to_json( $v ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 49 | ▶ | if ( not defined $v ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 1 | return "\x21"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 48 | ▶ | if ( _is_arrayref( $v ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 6 | my $out = "\xF8"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 6 | $out .= _encode_value_smile( $_, $ctx ) for @$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 6 | $out .= "\xF9"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 6 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 42 | ▶ | if ( _is_hashref( $v ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 13 | my @keys = keys %$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 13 | ▶ | @keys = sort @keys if $ctx->{canonical}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 13 | my $out = "\xFA"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 13 | for my $k ( @keys ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 23 | $out .= _encode_key_smile( $k, $ctx ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 23 | $out .= _encode_value_smile( $v->{$k}, $ctx ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 13 | $out .= "\xFB"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 13 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 29 | ▶ | die 'Unsupported reference in encode_smile' if ref $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 29 | ▶ | if ( _is_bool( $v ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | ▶ | return $v ? "\x23" : "\x22"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 29 | ▶ | if ( _created_as_number( $v ) or looks_like_number( $v ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
&_created_as_number($v) or &looks_like_number($v)
MC/DC50%1/2
&_created_as_number($v) or &looks_like_number($v)
&_created_as_number($v)
&looks_like_number($v)
Truth table66%2/3
A or B
A= &_created_as_number($v)B= &looks_like_number($v)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 15 | ▶ | if ( $v =~ /\A-?[0-9]+\z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 15 | my $n = 0 + $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 15 | ▶ | if ( $n >= -16 and $n <= 15 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$n >= -16 and $n <= 15
MC/DC0%0/2
$n >= -16 and $n <= 15
$n >= -16
$n <= 15
Truth table33%1/3
A and B
A= $n >= -16B= $n <= 15
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 15 | return chr( 0xC0 + _zigzag_encode( $n ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | return "\x24" . _encode_vint( _zigzag_encode( $n ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | my $raw = pack 'd>', 0 + $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | return "\x29" . _encode_7bit_binary( $raw ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 14 | my $text = "$v"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 14 | ▶ | my $cache_key = utf8::is_utf8( $text ) ? "u\0$text" : "b\0$text"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 14 | ▶ | if ( $ctx->{enable_shared_values} and defined $ctx->{value_to_idx}{$cache_key} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ctx->{"enable_shared_values"} and defined $ctx->{"value_to_idx"}{$cache_key}
MC/DC100%2/2
$ctx->{"enable_shared_values"} and defined $ctx->{"value_to_idx"}{$cache_key}
$ctx->{"enable_shared_values"}
defined $ctx->{"value_to_idx"}{$cache_key}
Truth table100%3/3
A and B
A= $ctx->{"enable_shared_values"}B= defined $ctx->{"value_to_idx"}{$cache_key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 5 | my $idx = $ctx->{value_to_idx}{$cache_key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 5 | ▶ | if ( $idx <= 30 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 5 | return chr( $idx + 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 0 | ▶ | if ( $idx <= 1023 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | my $msb = ( $idx >> 8 ) & 0x03; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | my $lsb = $idx & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 0 | return chr( 0xEC + $msb ) . chr( $lsb ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 9 | ▶ | if ( $ctx->{enable_shared_values} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 7 | ▶ | if ( @{$ctx->{shared_values}} >= 1024 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 0 | $ctx->{shared_values} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | $ctx->{value_to_idx} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 7 | my $idx = scalar @{$ctx->{shared_values}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 7 | $ctx->{value_to_idx}{$cache_key} = $idx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 7 | push @{$ctx->{shared_values}}, $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 9 | my $bytes = $text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 9 | my $is_utf8 = utf8::is_utf8 $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 9 | ▶ | utf8::encode( $bytes ) if $is_utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 9 | return _encode_short_or_long_text( $bytes, $is_utf8 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 14 | ▶ | sub encode_smile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_smile: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 14 | my ( $data, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 14 | ▶ | die 'encode_smile expects at most 2 arguments' if @_ > 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 14 | $opts = _check_opts( 'encode_smile', $opts, { write_header => 1, shared_values => 1, shared_names => 1, canonical => 1 } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 12 | ▶ | my $write_header = exists $opts->{write_header} ? !!$opts->{write_header} : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 12 | ▶ | my $shared_values = exists $opts->{shared_values} ? !!$opts->{shared_values} : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 12 | ▶ | my $shared_names = exists $opts->{shared_names} ? !!$opts->{shared_names} : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 12 | ▶ | my $canonical = exists $opts->{canonical} ? !!$opts->{canonical} : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 12 | my %ctx = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | shared_names => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | name_to_idx => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | shared_values => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | value_to_idx => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | enable_shared_names => !!$shared_names, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | enable_shared_values => !!$shared_values, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | canonical => $canonical, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 12 | my $payload = _encode_value_smile( $data, \%ctx ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 12 | ▶ | my $out = $write_header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | ? substr( HEADER, 0, 3 ) . chr( $shared_names | ( $shared_values << 1 ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 12 | $out .= $payload; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 12 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 32 | ▶ | sub decode_smile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_smile: called CC=22 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 32 | my ( $bytes, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 32 | ▶ | die 'decode_smile expects at most 2 arguments' if @_ > 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 32 | $opts = _check_opts( 'decode_smile', $opts, { use_bigint => 1, require_header => 1, json_bool => 1 } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 31 | ▶ | my $use_bigint = exists $opts->{use_bigint} ? !!$opts->{use_bigint} : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 31 | ▶ | my $require_header = exists $opts->{require_header} ? !!$opts->{require_header} : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 31 | ▶ | my $json_bool = exists $opts->{json_bool} ? !!$opts->{json_bool} : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 31 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 31 | my $has_header = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 31 | ▶ | if ( substr( $bytes, 0, 3 ) eq "\x3A\x29\x0A" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 27 | $pos = 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 27 | $has_header = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | elsif ( $require_header ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 1 | die 'Smile header required'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 30 | ▶ | if ( $pos < length $bytes and substr( $bytes, $pos, 1 ) eq "\x7A" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pos < length $bytes and substr($bytes, $pos, 1) eq "z"
MC/DC0%0/2
$pos < length $bytes and substr($bytes, $pos, 1) eq "z"
$pos < length $bytes
substr($bytes, $pos, 1) eq "z"
Truth table33%1/3
A and B
A= $pos < length $bytesB= substr($bytes, $pos, 1) eq "z"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | ▶ | die 'Unexpected EOF' if $pos >= length $bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | my $flags = ord substr( $bytes, $pos++, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | ▶ | $pos++ if $flags & 0x01; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | ▶ | $pos++ if $flags & 0x02; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | my $len = _unpack_u32( \$bytes, \$pos ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | ▶ | die 'Unexpected EOF' if $pos + $len > length $bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | my $payload = substr( $bytes, $pos, $len ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | $pos += $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 0 | my $inner = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 0 | my $value = _decode_value( \$payload, \$inner, $json_bool, $use_bigint ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 30 | ▶ | my $flags = $has_header ? ord substr( $bytes, 3, 1 ) : 0x01; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 30 | ▶ | my %ctx = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | shared_names => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | shared_values => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | enable_shared_names => $has_header ? !!($flags & 0x01) : !!1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | enable_shared_values => $has_header ? !!($flags & 0x02) : !!0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 30 | my $value = _decode_value_smile( \$bytes, \$pos, \%ctx, $json_bool, $use_bigint ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 30 | ▶ | while ( $pos < length $bytes ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 2 | my $rest = ord substr( $bytes, $pos, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 2 | ▶ | last if $rest == 0xFF; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 2 | ▶ | if ( $rest == 0x0A or $rest == 0x0D or $rest == 0x09 or $rest == 0x20 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$rest == 10 or $rest == 13 or $rest == 9 or $rest == 32
$rest == 10 or $rest == 13 or $rest == 9
$rest == 10 or $rest == 13
MC/DC0%0/4
$rest == 10 or $rest == 13 or $rest == 9 or $rest == 32
$rest == 10
$rest == 13
$rest == 9
$rest == 32
Truth table20%1/5
A or B or C or D
A= $rest == 10B= $rest == 13C= $rest == 9D= $rest == 32
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 2 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | die 'Invalid payload'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 30 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 24 | ▶ | sub _is_pathish_filename { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_pathish_filename: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 24 | my ( $x ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 24 | ▶ | return 0 if not ref $x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 19 | ▶ | return 1 if eval { $x->isa('Path::Tiny') } or eval { $x->isa('Path::Class::File') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
eval {
do {
$x->isa("Path::Tiny")
}
} or eval {
do {
$x->isa("Path::Class::File")
}
}
MC/DC50%1/2
eval {
do {
$x->isa("Path::Tiny")
}
} or eval {
do {
$x->isa("Path::Class::File")
}
}
eval {
do {
$x->isa("Path::Tiny")
}
}
eval {
do {
$x->isa("Path::Class::File")
}
}
Truth table66%2/3
A or B
A= eval {
do {
$x->isa("Path::Tiny")
}
}B= eval {
do {
$x->isa("Path::Class::File")
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 19 | ▶ | sub _open_for_read { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_open_for_read: called CC=7 SCAR=29.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 19 | my ( $file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 19 | ▶ | if ( _is_pathish_filename( $file ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 17 | $file = "$file"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 19 | ▶ | if ( not ref $file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 19 | ▶ | open my $fh, '<:raw', $file or die "open($file) for read: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 19 | return ( $fh, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | ▶ | if ( eval { $file->can('read') } or eval { $file->can('getline') } or ref( $file ) eq 'GLOB' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
eval {
do {
$file->can("read")
}
} or eval {
do {
$file->can("getline")
}
} or ref $file eq "GLOB"
eval {
do {
$file->can("read")
}
} or eval {
do {
$file->can("getline")
}
}
MC/DC0%0/3
eval {
do {
$file->can("read")
}
} or eval {
do {
$file->can("getline")
}
} or ref $file eq "GLOB"
eval {
do {
$file->can("read")
}
}
eval {
do {
$file->can("getline")
}
}
ref $file eq "GLOB"
Truth table0%0/4
A or B or C
A= eval {
do {
$file->can("read")
}
}B= eval {
do {
$file->can("getline")
}
}C= ref $file eq "GLOB"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 0 | binmode( $file, ':raw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 0 | return ( $file, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | die "Unsupported file argument for read"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 5 | ▶ | sub _open_for_write { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_open_for_write: called CC=7 SCAR=21.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 5 | my ( $file ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 5 | ▶ | if ( _is_pathish_filename( $file ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 1 | $file = "$file"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 5 | ▶ | if ( not ref $file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 4 | ▶ | open my $fh, '>:raw', $file or die "open($file) for write: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 4 | return ( $fh, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 1 | ▶ | if ( eval { $file->can('print') } or eval { $file->can('write') } or ref( $file ) eq 'GLOB' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
eval {
do {
$file->can("print")
}
} or eval {
do {
$file->can("write")
}
} or ref $file eq "GLOB"
eval {
do {
$file->can("print")
}
} or eval {
do {
$file->can("write")
}
}
MC/DC0%0/3
eval {
do {
$file->can("print")
}
} or eval {
do {
$file->can("write")
}
} or ref $file eq "GLOB"
eval {
do {
$file->can("print")
}
}
eval {
do {
$file->can("write")
}
}
ref $file eq "GLOB"
Truth table25%1/4
A or B or C
A= eval {
do {
$file->can("print")
}
}B= eval {
do {
$file->can("write")
}
}C= ref $file eq "GLOB"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 1 | binmode( $file, ':raw' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 1 | return ( $file, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 0 | die "Unsupported file argument for write"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 5 | ▶ | sub dump_smile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_smile: called CC=10 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 5 | my ( $file, $data, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 5 | ▶ | die 'dump_smile expects at most 3 arguments' if @_ > 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 5 | ▶ | if ( @_ >= 3 and defined $opts ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ >= 3 and defined $opts
MC/DC50%1/2
@_ >= 3 and defined $opts
@_ >= 3
defined $opts
Truth table66%2/3
A and B
A= @_ >= 3B= defined $opts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 2 | ▶ | die 'Options must be a hash reference' if not _is_hashref( $opts ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 5 | my ( $fh, $close ) = _open_for_write( $file ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 5 | my $bytes = encode_smile( $data, $opts ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 4 | ▶ | my $ok = eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 4 | ▶ | print {$fh} $bytes or die "write: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 4 | ▶ | if ( $close ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 3 | ▶ | close $fh or $ok = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 4 | ▶ | return $ok ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 19 | ▶ | sub load_smile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_smile: called CC=8 SCAR=21.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 19 | my ( $file, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 19 | ▶ | die 'load_smile expects at most 2 arguments' if @_ > 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 19 | ▶ | if ( @_ >= 2 and defined $opts ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ >= 2 and defined $opts
MC/DC50%1/2
@_ >= 2 and defined $opts
@_ >= 2
defined $opts
Truth table66%2/3
A and B
A= @_ >= 2B= defined $opts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 1 | ▶ | die 'Options must be a hash reference' if not _is_hashref( $opts ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 19 | my ( $fh, $close ) = _open_for_read( $file ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 19 | my $buf = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 19 | ▶ | die "read failed" if not defined $buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 19 | ▶ | if ( $close ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 19 | ▶ | close $fh or die "close: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 19 | return decode_smile( $buf, $opts ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||