« /usr/local/lib/perl5/site_perl/5.44.0/x86_64-linux/Sereal/Decoder.pm
↑ Summary
/usr/local/lib/perl5/site_perl/5.44.0/Sub/Defer.pm »
| 1 | package Sereal::Encoder; | ||||||||||||||
| 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 | # Make sure to keep these constants in sync with the C code in srl_encoder.c. | ||||||||||||||
| 12 | # I know they could be exported from C using things like ExtUtils::Constant, | ||||||||||||||
| 13 | # but that's too much of a hassle for just three numbers. | ||||||||||||||
| 14 | #start-no-tidy | ||||||||||||||
| 15 | my ($compress_consts, $full_consts); | ||||||||||||||
| 16 | BEGIN { | ||||||||||||||
| 17 | $compress_consts= { | ||||||||||||||
| 18 | SRL_UNCOMPRESSED => 0, | ||||||||||||||
| 19 | SRL_SNAPPY => 1, | ||||||||||||||
| 20 | SRL_ZLIB => 2, | ||||||||||||||
| 21 | SRL_ZSTD => 3, | ||||||||||||||
| 22 | }; | ||||||||||||||
| 23 | $full_consts= | ||||||||||||||
| 24 | #begin generated | ||||||||||||||
| 25 | { | ||||||||||||||
| 26 | 'SRL_F_ALIASED_DEDUPE_STRINGS' => 4096, | ||||||||||||||
| 27 | 'SRL_F_CANONICAL_REFS' => 32768, | ||||||||||||||
| 28 | 'SRL_F_COMPRESS_SNAPPY' => 64, | ||||||||||||||
| 29 | 'SRL_F_COMPRESS_SNAPPY_INCREMENTAL' => 128, | ||||||||||||||
| 30 | 'SRL_F_COMPRESS_ZLIB' => 256, | ||||||||||||||
| 31 | 'SRL_F_COMPRESS_ZSTD' => 262144, | ||||||||||||||
| 32 | 'SRL_F_CROAK_ON_BLESS' => 4, | ||||||||||||||
| 33 | 'SRL_F_DEDUPE_STRINGS' => 2048, | ||||||||||||||
| 34 | 'SRL_F_ENABLE_FREEZE_SUPPORT' => 16384, | ||||||||||||||
| 35 | 'SRL_F_ENCODER_COMPRESS_FLAGS_MASK' => 262592, | ||||||||||||||
| 36 | 'SRL_F_FREEZE_DENY_SERIALIZE' => 1048576, | ||||||||||||||
| 37 | 'SRL_F_NOWARN_UNKNOWN_OVERLOAD' => 512, | ||||||||||||||
| 38 | 'SRL_F_NO_BLESS_OBJECTS' => 8192, | ||||||||||||||
| 39 | 'SRL_F_REUSE_ENCODER' => 2, | ||||||||||||||
| 40 | 'SRL_F_SHARED_HASHKEYS' => 1, | ||||||||||||||
| 41 | 'SRL_F_SORT_KEYS' => 1024, | ||||||||||||||
| 42 | 'SRL_F_SORT_KEYS_PERL' => 65536, | ||||||||||||||
| 43 | 'SRL_F_SORT_KEYS_PERL_REV' => 131072, | ||||||||||||||
| 44 | 'SRL_F_STRINGIFY_UNKNOWN' => 16, | ||||||||||||||
| 45 | 'SRL_F_UNDEF_UNKNOWN' => 8, | ||||||||||||||
| 46 | 'SRL_F_USE_STANDARD_DOUBLE' => 524288, | ||||||||||||||
| 47 | 'SRL_F_WARN_UNKNOWN' => 32, | ||||||||||||||
| 48 | '_FLAG_NAME' => [ | ||||||||||||||
| 49 | 'COMPRESS_SNAPPY', | ||||||||||||||
| 50 | 'COMPRESS_SNAPPY_INCREMENTAL', | ||||||||||||||
| 51 | 'COMPRESS_ZLIB', | ||||||||||||||
| 52 | 'COMPRESS_ZSTD', | ||||||||||||||
| 53 | 'SHARED_HASHKEYS', | ||||||||||||||
| 54 | 'REUSE', | ||||||||||||||
| 55 | 'CROAK_ON_BLESS', | ||||||||||||||
| 56 | 'UNDEF_UNKNOWN', | ||||||||||||||
| 57 | 'STRINGIFY_UNKNOWN', | ||||||||||||||
| 58 | 'WARN_UNKNOWN', | ||||||||||||||
| 59 | 'COMPRESS_SNAPPY', | ||||||||||||||
| 60 | 'COMPRESS_SNAPPY_INCREMENTAL', | ||||||||||||||
| 61 | 'COMPRESS_ZLIB', | ||||||||||||||
| 62 | 'NOWARN_UNKNOWN_OVERLOAD', | ||||||||||||||
| 63 | 'SORT_KEYS', | ||||||||||||||
| 64 | 'DEDUPE_STRINGS', | ||||||||||||||
| 65 | 'ALIASED_DEDUPE_STRINGS', | ||||||||||||||
| 66 | 'NO_BLESS_OBJECTS', | ||||||||||||||
| 67 | 'ENABLE_FREEZE_SUPPORT', | ||||||||||||||
| 68 | 'CANONICAL_REFS', | ||||||||||||||
| 69 | 'SORT_KEYS_PERL', | ||||||||||||||
| 70 | 'SORT_KEYS_PERL_REV', | ||||||||||||||
| 71 | 'COMPRESS_ZSTD', | ||||||||||||||
| 72 | 'USE_STANDARD_DOUBLE' | ||||||||||||||
| 73 | ] | ||||||||||||||
| 74 | }; #end generated | ||||||||||||||
| 75 | } | ||||||||||||||
| 76 | use constant $compress_consts; | ||||||||||||||
| 77 | use constant $full_consts; | ||||||||||||||
| 78 | #end-no-tidy | ||||||||||||||
| 79 | |||||||||||||||
| 80 | use Exporter 'import'; | ||||||||||||||
| 81 | our @EXPORT_OK = ( qw( | ||||||||||||||
| 82 | encode_sereal | ||||||||||||||
| 83 | encode_sereal_with_header_data | ||||||||||||||
| 84 | sereal_encode_with_object | ||||||||||||||
| 85 | ), | ||||||||||||||
| 86 | sort { $a cmp $b } ( | ||||||||||||||
| 87 | keys(%$compress_consts), | ||||||||||||||
| 88 | keys(%$full_consts) ) ); | ||||||||||||||
| 89 | our %EXPORT_TAGS = ( | ||||||||||||||
| 90 | all => \@EXPORT_OK, | ||||||||||||||
| 91 | compress_const => [ sort keys %$compress_consts ], | ||||||||||||||
| 92 | full_const => [ sort( keys(%$compress_consts), keys(%$full_consts) ) ], | ||||||||||||||
| 93 | ); | ||||||||||||||
| 94 | |||||||||||||||
| 95 | # export by default if run from command line | ||||||||||||||
| 96 | our @EXPORT = ( ( caller() )[1] eq '-e' ? @EXPORT_OK : () ); | ||||||||||||||
| 97 | |||||||||||||||
| 98 | 0 | ▶ | sub CLONE_SKIP { 1 } | ||||||||||||
|
Subroutine
CLONE_SKIP: not called CC=1 SCAR=6.9
| |||||||||||||||
| 99 | |||||||||||||||
| 100 | XSLoader::load( 'Sereal::Encoder', $XS_VERSION ); | ||||||||||||||
| 101 | |||||||||||||||
| 102 | sub encode_to_file { | ||||||||||||||
| 103 | 0 | ▶ | my ( $self, $file, $struct, $append ) = @_; | ||||||||||||
|
Subroutine
encode_to_file: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||
| 104 | 0 | ▶ | $self = $self->new() unless ref $self; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 105 | 0 | ▶ | my $mode = $append ? ">>" : ">"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 106 | 0 | ▶ | open my $fh, $mode, $file | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 107 | or die "Failed to open '$file' for " . ( $append ? "append" : "write" ) . ": $!"; | ||||||||||||||
| 108 | 0 | ▶ | print $fh $self->encode($struct) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 109 | or die "Failed to print to '$file': $!"; | ||||||||||||||
| 110 | 0 | ▶ | close $fh | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 111 | or die "Failed to close '$file': $!"; | ||||||||||||||
| 112 | } | ||||||||||||||
| 113 | |||||||||||||||
| 114 | my $flags = sub { | ||||||||||||||
| 115 | my ( $int, $ary ) = @_; | ||||||||||||||
| 116 | return map { ( $ary->[$_] and $int & ( 1 << $_ ) ) ? $ary->[$_] : () } ( 0 .. $#$ary ); | ||||||||||||||
| 117 | }; | ||||||||||||||
| 118 | |||||||||||||||
| 119 | sub flag_names { | ||||||||||||||
| 120 | 0 | ▶ | my ( $self, $val ) = @_; | ||||||||||||
|
Subroutine
flag_names: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 121 | 0 | ▶ | return $flags->( defined $val ? $val : $self->flags, _FLAG_NAME ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 122 | } | ||||||||||||||
| 123 | |||||||||||||||
| 124 | 1; | ||||||||||||||
| 125 | |||||||||||||||
| 126 | __END__ | ||||||||||||||