« lib/Skilletor/Apply.pm
↑ Summary
/usr/local/lib/perl5/site_perl/5.44.0/x86_64-linux/Sereal/Encoder.pm »
| 1 | package Sereal::Decoder; | ||||||||||||||||||||||||||||
| 2 | use 5.014; | ||||||||||||||||||||||||||||
| 3 | use strict; | ||||||||||||||||||||||||||||
| 4 | use warnings; | ||||||||||||||||||||||||||||
| 5 | use Carp qw/croak/; | ||||||||||||||||||||||||||||
| 6 | use XSLoader; | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | our $VERSION = '5.011'; | ||||||||||||||||||||||||||||
| 9 | our $XS_VERSION = $VERSION; $VERSION = eval $VERSION; | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | use Exporter 'import'; | ||||||||||||||||||||||||||||
| 12 | our @EXPORT_OK = qw( | ||||||||||||||||||||||||||||
| 13 | decode_sereal | ||||||||||||||||||||||||||||
| 14 | looks_like_sereal | ||||||||||||||||||||||||||||
| 15 | decode_sereal_with_header_data | ||||||||||||||||||||||||||||
| 16 | scalar_looks_like_sereal | ||||||||||||||||||||||||||||
| 17 | sereal_decode_with_object | ||||||||||||||||||||||||||||
| 18 | sereal_decode_with_header_with_object | ||||||||||||||||||||||||||||
| 19 | sereal_decode_only_header_with_object | ||||||||||||||||||||||||||||
| 20 | sereal_decode_only_header_with_offset_with_object | ||||||||||||||||||||||||||||
| 21 | sereal_decode_with_header_and_offset_with_object | ||||||||||||||||||||||||||||
| 22 | sereal_decode_with_offset_with_object | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | our %EXPORT_TAGS = ( all => \@EXPORT_OK ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # export by default if run from command line | ||||||||||||||||||||||||||||
| 27 | our @EXPORT = ( ( caller() )[1] eq '-e' ? @EXPORT_OK : () ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub CLONE_SKIP { 1 } | ||||||||||||||||||||||||||
|
Subroutine
CLONE_SKIP: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 30 | XSLoader::load( 'Sereal::Decoder', $XS_VERSION ); | ||||||||||||||||||||||||||||
| 31 | #start-no-tidy | ||||||||||||||||||||||||||||
| 32 | use constant #begin generated | ||||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||
| 34 | 'SRL_F_DECODER_ALIAS_CHECK_FLAGS' => 28672, | ||||||||||||||||||||||||||||
| 35 | 'SRL_F_DECODER_ALIAS_SMALLINT' => 4096, | ||||||||||||||||||||||||||||
| 36 | 'SRL_F_DECODER_ALIAS_VARINT' => 8192, | ||||||||||||||||||||||||||||
| 37 | 'SRL_F_DECODER_DECOMPRESS_SNAPPY' => 8, | ||||||||||||||||||||||||||||
| 38 | 'SRL_F_DECODER_DECOMPRESS_ZLIB' => 16, | ||||||||||||||||||||||||||||
| 39 | 'SRL_F_DECODER_DECOMPRESS_ZSTD' => 131072, | ||||||||||||||||||||||||||||
| 40 | 'SRL_F_DECODER_DESTRUCTIVE_INCREMENTAL' => 1024, | ||||||||||||||||||||||||||||
| 41 | 'SRL_F_DECODER_DIRTY' => 2, | ||||||||||||||||||||||||||||
| 42 | 'SRL_F_DECODER_NEEDS_FINALIZE' => 4, | ||||||||||||||||||||||||||||
| 43 | 'SRL_F_DECODER_NO_BLESS_OBJECTS' => 512, | ||||||||||||||||||||||||||||
| 44 | 'SRL_F_DECODER_NO_THAW_OBJECTS' => 524288, | ||||||||||||||||||||||||||||
| 45 | 'SRL_F_DECODER_PROTOCOL_V1' => 2048, | ||||||||||||||||||||||||||||
| 46 | 'SRL_F_DECODER_READONLY_FLAGS' => 98304, | ||||||||||||||||||||||||||||
| 47 | 'SRL_F_DECODER_REFUSE_OBJECTS' => 128, | ||||||||||||||||||||||||||||
| 48 | 'SRL_F_DECODER_REFUSE_SNAPPY' => 32, | ||||||||||||||||||||||||||||
| 49 | 'SRL_F_DECODER_REFUSE_ZLIB' => 64, | ||||||||||||||||||||||||||||
| 50 | 'SRL_F_DECODER_REFUSE_ZSTD' => 262144, | ||||||||||||||||||||||||||||
| 51 | 'SRL_F_DECODER_REUSE' => 1, | ||||||||||||||||||||||||||||
| 52 | 'SRL_F_DECODER_SET_READONLY' => 32768, | ||||||||||||||||||||||||||||
| 53 | 'SRL_F_DECODER_SET_READONLY_SCALARS' => 65536, | ||||||||||||||||||||||||||||
| 54 | 'SRL_F_DECODER_THAW_DENY_RAW' => 1048576, | ||||||||||||||||||||||||||||
| 55 | 'SRL_F_DECODER_USE_UNDEF' => 16384, | ||||||||||||||||||||||||||||
| 56 | 'SRL_F_DECODER_VALIDATE_UTF8' => 256, | ||||||||||||||||||||||||||||
| 57 | 'SRL_F_DECODER_VOLATILE_FLAGS' => 133150, | ||||||||||||||||||||||||||||
| 58 | '_FLAG_NAME' => [ | ||||||||||||||||||||||||||||
| 59 | 'REUSE', | ||||||||||||||||||||||||||||
| 60 | 'DIRTY', | ||||||||||||||||||||||||||||
| 61 | 'NEEDS_FINALIZE', | ||||||||||||||||||||||||||||
| 62 | 'DECOMPRESS_SNAPPY', | ||||||||||||||||||||||||||||
| 63 | 'DECOMPRESS_ZLIB', | ||||||||||||||||||||||||||||
| 64 | 'REFUSE_SNAPPY', | ||||||||||||||||||||||||||||
| 65 | 'REFUSE_ZLIB', | ||||||||||||||||||||||||||||
| 66 | 'REFUSE_OBJECTS', | ||||||||||||||||||||||||||||
| 67 | 'VALIDATE_UTF8', | ||||||||||||||||||||||||||||
| 68 | 'NO_BLESS_OBJECTS', | ||||||||||||||||||||||||||||
| 69 | 'DESTRUCTIVE_INCREMENTAL', | ||||||||||||||||||||||||||||
| 70 | 'PROTOCOL_V1', | ||||||||||||||||||||||||||||
| 71 | 'ALIAS_SMALLINT', | ||||||||||||||||||||||||||||
| 72 | 'ALIAS_VARINT', | ||||||||||||||||||||||||||||
| 73 | 'USE_UNDEF', | ||||||||||||||||||||||||||||
| 74 | 'SET_READONLY', | ||||||||||||||||||||||||||||
| 75 | 'SET_READONLY_SCALARS', | ||||||||||||||||||||||||||||
| 76 | 'DECOMPRESS_ZSTD', | ||||||||||||||||||||||||||||
| 77 | 'REFUSE_ZSTD', | ||||||||||||||||||||||||||||
| 78 | 'NO_THAW_OBJECTS', | ||||||||||||||||||||||||||||
| 79 | 'THAW_DENY_RAW' | ||||||||||||||||||||||||||||
| 80 | ], | ||||||||||||||||||||||||||||
| 81 | '_FLAG_NAME_STATIC' => [ | ||||||||||||||||||||||||||||
| 82 | 'REUSE', | ||||||||||||||||||||||||||||
| 83 | undef, | ||||||||||||||||||||||||||||
| 84 | undef, | ||||||||||||||||||||||||||||
| 85 | undef, | ||||||||||||||||||||||||||||
| 86 | undef, | ||||||||||||||||||||||||||||
| 87 | 'REFUSE_SNAPPY', | ||||||||||||||||||||||||||||
| 88 | 'REFUSE_ZLIB', | ||||||||||||||||||||||||||||
| 89 | 'REFUSE_OBJECTS', | ||||||||||||||||||||||||||||
| 90 | 'VALIDATE_UTF8', | ||||||||||||||||||||||||||||
| 91 | 'NO_BLESS_OBJECTS', | ||||||||||||||||||||||||||||
| 92 | 'DESTRUCTIVE_INCREMENTAL', | ||||||||||||||||||||||||||||
| 93 | undef, | ||||||||||||||||||||||||||||
| 94 | 'ALIAS_SMALLINT', | ||||||||||||||||||||||||||||
| 95 | 'ALIAS_VARINT', | ||||||||||||||||||||||||||||
| 96 | 'USE_UNDEF', | ||||||||||||||||||||||||||||
| 97 | 'SET_READONLY', | ||||||||||||||||||||||||||||
| 98 | 'SET_READONLY_SCALARS', | ||||||||||||||||||||||||||||
| 99 | undef, | ||||||||||||||||||||||||||||
| 100 | 'REFUSE_ZSTD', | ||||||||||||||||||||||||||||
| 101 | 'NO_THAW_OBJECTS', | ||||||||||||||||||||||||||||
| 102 | 'THAW_DENY_RAW' | ||||||||||||||||||||||||||||
| 103 | ], | ||||||||||||||||||||||||||||
| 104 | '_FLAG_NAME_VOLATILE' => [ | ||||||||||||||||||||||||||||
| 105 | undef, | ||||||||||||||||||||||||||||
| 106 | 'DIRTY', | ||||||||||||||||||||||||||||
| 107 | 'NEEDS_FINALIZE', | ||||||||||||||||||||||||||||
| 108 | 'DECOMPRESS_SNAPPY', | ||||||||||||||||||||||||||||
| 109 | 'DECOMPRESS_ZLIB', | ||||||||||||||||||||||||||||
| 110 | undef, | ||||||||||||||||||||||||||||
| 111 | undef, | ||||||||||||||||||||||||||||
| 112 | undef, | ||||||||||||||||||||||||||||
| 113 | undef, | ||||||||||||||||||||||||||||
| 114 | undef, | ||||||||||||||||||||||||||||
| 115 | undef, | ||||||||||||||||||||||||||||
| 116 | 'PROTOCOL_V1', | ||||||||||||||||||||||||||||
| 117 | undef, | ||||||||||||||||||||||||||||
| 118 | undef, | ||||||||||||||||||||||||||||
| 119 | undef, | ||||||||||||||||||||||||||||
| 120 | undef, | ||||||||||||||||||||||||||||
| 121 | undef, | ||||||||||||||||||||||||||||
| 122 | 'DECOMPRESS_ZSTD', | ||||||||||||||||||||||||||||
| 123 | undef, | ||||||||||||||||||||||||||||
| 124 | undef, | ||||||||||||||||||||||||||||
| 125 | undef | ||||||||||||||||||||||||||||
| 126 | ] | ||||||||||||||||||||||||||||
| 127 | }; #end generated | ||||||||||||||||||||||||||||
| 128 | #end-no-tidy | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | sub decode_from_file { | ||||||||||||||||||||||||||||
| 131 | 0 | ▶ | my ( $self, $file, ) = @_; # pos 3 is "target var" if one is provided | ||||||||||||||||||||||||||
|
Subroutine
decode_from_file: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | $self = $self->new() unless ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | open my $fh, "<", $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | or die "Failed to open '$file' for read: $!"; | ||||||||||||||||||||||||||||
| 135 | 0 | my $buf = do { local $/; <$fh> }; | |||||||||||||||||||||||||||
| 136 | 0 | ▶ | close $fh | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | or die "Failed to close '$file': $!"; | ||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ( wantarray && ( $self->flags & SRL_F_DECODER_DESTRUCTIVE_INCREMENTAL ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
wantarray and $self->flags & 1024
MC/DC0%0/2
wantarray and $self->flags & 1024
wantarray
$self->flags & 1024
Truth table0%0/3
A and B
A= wantarrayB= $self->flags & 1024
| |||||||||||||||||||||||||||||
| 139 | 0 | my @ret; | |||||||||||||||||||||||||||
| 140 | 0 | ▶ | while ( length $buf ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | push @ret, $self->decode($buf); | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 0 | return @ret; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | 0 | ▶ | return $self->decode( $buf, @_ > 2 ? $_[2] : () ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | my $flags = sub { | ||||||||||||||||||||||||||||
| 149 | my ( $int, $ary ) = @_; | ||||||||||||||||||||||||||||
| 150 | return map { ( $ary->[$_] and $int & ( 1 << $_ ) ) ? $ary->[$_] : () } ( 0 .. $#$ary ); | ||||||||||||||||||||||||||||
| 151 | }; | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | sub flag_names { | ||||||||||||||||||||||||||||
| 154 | 0 | ▶ | my ( $self, $val ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
flag_names: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | return $flags->( defined $val ? $val : $self->flags, _FLAG_NAME ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | sub flag_names_volatile { | ||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my ( $self, $val ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
flag_names_volatile: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | return $flags->( $val // $self->flags, _FLAG_NAME_VOLATILE ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$val // $self->flags
MC/DC0%0/2
$val // $self->flags
$val
$self->flags
Truth table0%0/3
A // B
A= $valB= $self->flags
| |||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | sub flag_names_static { | ||||||||||||||||||||||||||||
| 164 | 0 | ▶ | my ( $self, $val ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
flag_names_static: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | return $flags->( $val // $self->flags, _FLAG_NAME_STATIC ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$val // $self->flags
MC/DC0%0/2
$val // $self->flags
$val
$self->flags
Truth table0%0/3
A // B
A= $valB= $self->flags
| |||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 1; | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | __END__ | ||||||||||||||||||||||||||||