File Coverage

blib/lib/Sereal.pm
Criterion Covered Total %
statement 32 32 100.0
branch 2 2 100.0
condition 4 6 66.6
subroutine 12 12 100.0
pod 5 5 100.0
total 55 57 96.4


line stmt bran cond sub pod time code
1             package Sereal;
2 4     4   422308 use 5.008;
  4         44  
3 4     4   21 use strict;
  4         8  
  4         92  
4 4     4   20 use warnings;
  4         8  
  4         296  
5             our $VERSION= '5.004';
6             our $XS_VERSION= $VERSION; $VERSION= eval $VERSION;
7 4         491 use Sereal::Encoder 5.004 qw(
8             encode_sereal
9             sereal_encode_with_object
10             SRL_UNCOMPRESSED
11             SRL_SNAPPY
12             SRL_ZLIB
13             SRL_ZSTD
14 4     4   28 );
  4         71  
15 4         386 use Sereal::Decoder 5.004 qw(
16             decode_sereal
17             looks_like_sereal
18             decode_sereal_with_header_data
19             scalar_looks_like_sereal
20             sereal_decode_with_object
21             sereal_decode_with_header_with_object
22             sereal_decode_only_header_with_object
23             sereal_decode_only_header_with_offset_with_object
24             sereal_decode_with_header_and_offset_with_object
25             sereal_decode_with_offset_with_object
26 4     4   31 );
  4         65  
27              
28 4     4   30 use Exporter 'import';
  4         7  
  4         1972  
29             our @EXPORT_OK= qw(
30             get_sereal_decoder
31             get_sereal_encoder
32             clear_sereal_object_cache
33              
34             encode_sereal
35             decode_sereal
36              
37             read_sereal
38             read_sereal_file
39             write_sereal
40             write_sereal_file
41              
42             looks_like_sereal
43             scalar_looks_like_sereal
44              
45             sereal_encode_with_object
46             sereal_decode_with_object
47             decode_sereal_with_header_data
48              
49             sereal_decode_with_header_with_object
50             sereal_decode_only_header_with_object
51             sereal_decode_only_header_with_offset_with_object
52             sereal_decode_with_header_and_offset_with_object
53             sereal_decode_with_offset_with_object
54              
55             SRL_UNCOMPRESSED
56             SRL_SNAPPY
57             SRL_ZLIB
58             SRL_ZSTD
59             );
60             our %EXPORT_TAGS= ( all => \@EXPORT_OK );
61              
62             # export by default if run from command line
63             our @EXPORT= ( ( caller() )[1] eq '-e' ? @EXPORT_OK : () );
64              
65             our %ENCODERS;
66             our %DECODERS;
67              
68             sub _key {
69 14     14   21 join "\t", map { $_ => $_[0]->{$_} } sort keys %{ $_[0] };
  8         53  
  14         916  
70             }
71              
72             sub clear_sereal_object_cache {
73 1     1 1 1559 my $count= keys(%DECODERS) + keys(%ENCODERS);
74 1         3 %ENCODERS= ();
75 1         3 %DECODERS= ();
76 1         4 return $count;
77             }
78              
79             sub get_sereal_encoder {
80 5     5 1 3235 my ($opts)= @_;
81 5   66     10 return $ENCODERS{ _key($opts) } ||= Sereal::Encoder->new($opts);
82             }
83              
84             sub get_sereal_decoder {
85 9     9 1 29 my ($opts)= @_;
86 9   66     17 return $DECODERS{ _key($opts) } ||= Sereal::Decoder->new($opts);
87             }
88              
89             sub write_sereal_file {
90 2     2 1 1368 my ( $file, $struct, $append, $opts )= @_;
91 2         8 get_sereal_encoder($opts)->encode_to_file( $file, $_[1], $append );
92             }
93              
94             sub read_sereal_file {
95 6     6 1 3010 my ( $file, $opts )= @_;
96 6 100       17 get_sereal_decoder($opts)->decode_from_file( $file, @_ > 2 ? $_[2] : () );
97             }
98              
99             *read_sereal= *read_sereal= *read_sereal_file;
100             *write_sereal= *write_sereal= *write_sereal_file;
101              
102             1;
103              
104             __END__