blib/lib/DTL/Fast/Cache/Compressed.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 52 SCAR 30.0
CC
4
Cov
0%
write_serialized_data
6.0
compress
6.0
decompress
6.0
CRAP 20.0
1 package DTL::Fast::Cache::Compressed;
2 use strict; use warnings FATAL => 'all';
3 use parent 'DTL::Fast::Cache::Serialized';
4  
5 our %CACHE;
6  
7 #@Override
8 sub new
9 {
10 my( $proto, %kwargs ) = @_;
11 require Compress::Zlib;
12  
13 return $proto->SUPER::new(%kwargs);
14 }
15  
16 #@Override
17 sub read_serialized_data
18 {
19 my( $self, $key ) = @_;
20  
21 return
22 $self->decompress(
23 $self->read_compressed_data(
24 $key
25 )
26 );
27 }
28  
29 #@Override
30 sub write_serialized_data
31 {
32 my( $self, $key, $data ) = @_;
33  
34 $self->write_compressed_data(
35 $key,
36 $self->compress(
37 $data
38 )
39 ) if defined $data; # don't store undef values
40 return $self;
41 }
42  
43  
44 sub read_compressed_data{ return shift->SUPER::read_serialized_data(@_) };
45  
46 sub write_compressed_data{ return shift->SUPER::write_serialized_data(@_) };
47  
48 sub compress
49 {
50 my( $self, $data ) = @_;
51 return if not defined $data;
52 return Compress::Zlib::memGzip($data);
53 }
54  
55 sub decompress
56 {
57 my( $self, $data ) = @_;
58 return if not defined $data;
59 return Compress::Zlib::memGunzip($data);
60 }
61  
62  
63  
64 1;