2ch/Cache.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 43 CC 6 SCAR 21.0
CC
6
Cov
0%
new
12.0
get
12.0
set
6.0
CRAP 8.2
1 package WWW::2ch::Cache;
2 use strict;
3  
4 use Storable qw(freeze thaw);
5  
6 use WWW::2ch::Cache::File;
7  
8 sub new {
9 my $class = shift;
10 my $cache = shift;
11  
12 my $self = bless {}, $class;
13  
14 if (ref($cache) =~ /^Cache::/) {
15 $self->{cache} = $cache;
16 } elsif ($cache) {
17 $self->{cache} = WWW::2ch::Cache::File->new($cache);
18 }
19 $self;
20 }
21  
22 sub set {
23 my ($self, $key, $data) = @_;
24 return unless $self->{cache};
25 $self->{cache}->set($key, freeze $data);
26 }
27  
28 sub get {
29 my ($self, $key) = @_;
30 return +{} unless $self->{cache};
31  
32 my $data = $self->{cache}->get($key);
33 return +{} unless $data;
34 thaw $data;
35 }
36  
37 1;