FollowLinks/Rule/Fresh/Cache.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 45 CC 3 SCAR 13.9
CC
3
Cov
0%
new
6.0
put
6.0
get
2.0
CRAP 4.0
1 # $Id: /mirror/perl/GunghoX-FollowLinks/trunk/lib/GunghoX/FollowLinks/Rule/Fresh/Cache.pm 40502 2008-01-24T04:50:29.650533Z daisuke $
2 #
3 # Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp>
4 # All rights reserved.
5  
6 package GunghoX::FollowLinks::Rule::Fresh::Cache;
7 use strict;
8 use warnings;
9 use base qw(Class::Accessor::Fast);
10  
11 __PACKAGE__->mk_accessors($_) for qw(cache _memcached_managed_hack);
12  
13 sub new
14 {
15 my $class = shift;
16 my %args = @_;
17  
18 my $cache_config = delete $args{cache};
19 my $cache_module = Gungho::Util::load_module(
20 $cache_config->{module} || die "No cache module specified"
21 );
22
23 my $hashref = delete $cache_config->{config}->{hashref};
24 my %cache_args = %{ $cache_config->{config} || {} } ;
25 my $cache = $cache_module->new( $hashref ? \%cache_args : %cache_args);
26 return bless {
27 cache => $cache,
28 _memcached_managed_hack => $cache->isa('Cache::Memcached::Managed'),
29 }, $class;
30 }
31  
32 sub put
33 {
34 my ($self, $url) = @_;
35  
36 if ($self->_memcached_managed_hack) {
37 $self->cache->set(1, $url);
38 } else {
39 $self->cache->set($url, 1);
40 }
41 }
42  
43 sub get
44 {
45 my ($self, $url) = @_;
46  
47 $self->cache->get($url);
48 }
49  
50 1;
51  
52 __END__