blib/lib/Sereal.pm

filter: Statementstmt 90.9% 10 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 93.3% 14 / 15 CC 1 SCAR 0.1
CC
1
Cov
91%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 package Sereal;
2 5 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 our $VERSION = '7.003';
6 our $XS_VERSION = $VERSION; $VERSION = eval $VERSION;
7 0 ▶use Sereal::Encoder 7.003 qw(
Subroutine BEGIN: called CC=1 SCAR=0.4
8 encode_sereal
9 sereal_encode_with_object
10 SRL_UNCOMPRESSED
11 SRL_SNAPPY
12 SRL_ZLIB
13 SRL_ZSTD
14 5 );
15 use Sereal::Decoder 7.003 qw(
16 get_sereal_checksum
17 validate_sereal_checksum
18 decode_sereal
19 looks_like_sereal
20 decode_sereal_with_header_data
21 scalar_looks_like_sereal
22 sereal_decode_with_object
23 sereal_decode_with_header_with_object
24 sereal_decode_only_header_with_object
25 sereal_decode_only_header_with_offset_with_object
26 sereal_decode_with_header_and_offset_with_object
27 sereal_decode_with_offset_with_object
28 );
29  
30 use Exporter 'import';
31 our @EXPORT_OK = qw(
32 get_sereal_checksum
33 validate_sereal_checksum
34 get_sereal_decoder
35 get_sereal_encoder
36 clear_sereal_object_cache
37  
38 encode_sereal
39 decode_sereal
40  
41 read_sereal
42 read_sereal_file
43 write_sereal
44 write_sereal_file
45  
46 looks_like_sereal
47 scalar_looks_like_sereal
48  
49 sereal_encode_with_object
50 sereal_decode_with_object
51 decode_sereal_with_header_data
52  
53 sereal_decode_with_header_with_object
54 sereal_decode_only_header_with_object
55 sereal_decode_only_header_with_offset_with_object
56 sereal_decode_with_header_and_offset_with_object
57 sereal_decode_with_offset_with_object
58  
59 SRL_UNCOMPRESSED
60 SRL_SNAPPY
61 SRL_ZLIB
62 SRL_ZSTD
63 );
64 our %EXPORT_TAGS = ( all => \@EXPORT_OK );
65  
66 # export by default if run from command line
67 our @EXPORT = ( ( caller() )[1] eq '-e' ? @EXPORT_OK : () );
68  
69 our %ENCODERS;
70 our %DECODERS;
71  
72 sub _key {
73 join "\t", map { $_ => $_[0]->{$_} } sort keys %{ $_[0] };
74 }
75  
76 sub clear_sereal_object_cache {
77 my $count = keys(%DECODERS) + keys(%ENCODERS);
78 %ENCODERS = ();
79 %DECODERS = ();
80 return $count;
81 }
82  
83 sub get_sereal_encoder {
84 my ($opts) = @_;
85 return $ENCODERS{ _key($opts) } ||= Sereal::Encoder->new($opts);
86 }
87  
88 sub get_sereal_decoder {
89 my ($opts) = @_;
90 return $DECODERS{ _key($opts) } ||= Sereal::Decoder->new($opts);
91 }
92  
93 sub write_sereal_file {
94 my ( $file, $struct, $append, $opts ) = @_;
95 get_sereal_encoder($opts)->encode_to_file( $file, $_[1], $append );
96 }
97  
98 sub read_sereal_file {
99 my ( $file, $opts ) = @_;
100 get_sereal_decoder($opts)->decode_from_file( $file, @_ > 2 ? $_[2] : () );
101 }
102  
103 *read_sereal = *read_sereal = *read_sereal_file;
104 *write_sereal = *write_sereal = *write_sereal_file;
105  
106 1;
107  
108 __END__
↑ Summary