Engine/Data/Memcached.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 62 CC 4 SCAR 21.5
CC
4
Cov
0%
new
20.0
handle
2.0
BEGIN
2.0
CRAP 8.5
1 package Service::Engine::Data::Memcached;
2  
3 use 5.010;
4 use strict;
5 use warnings;
6 use Data::Dumper;
7  
8 use Service::Engine;
9 use Cache::Memcached::Fast;
10  
11 our $Config;
12 our $Log;
13  
14 sub new {
15
16 my ($class,$options) = @_;
17
18 # set some defaults
19 my $attributes = {'handle'=>''};
20
21 # load options
22 if (ref($options) eq 'HASH') {
23 foreach my $option (keys %{$options}) {
24 $attributes->{$option} = $options->{$option};
25 }
26 }
27
28 # pull in some Service::Engine globals
29 $Config = $Service::Engine::Config;
30 $Log = $Service::Engine::Log;
31
32 if (!$attributes->{ip} || !$attributes->{port}) {
33 $Log->log({msg=>"memcached requires a port and ip",level=>1});
34 } else {
35 my $thismemd =
36 new Cache::Memcached::Fast {
37 'servers' => [ $attributes->{ip}.':'.$attributes->{port} ],
38 'compress_threshold' => 10_000,
39 };
40 $thismemd->enable_compress(1) if $thismemd;
41 $attributes->{'handle'} = $thismemd;
42 }
43
44 my $self = bless $attributes, $class;
45
46 return $self;
47  
48 }
49  
50 sub handle {
51 my ($self) = @_;
52 $Log->log({msg=>'memcache_ip: ' . $self->{'ip'} . ' port: ' . $self->{'port'},level=>3});
53 return $self->{'handle'};
54 }
55  
56 1;