| 1 | package Cache::Memcached::Tie; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use 5.8.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use Cache::Memcached::Fast; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | $VERSION = '0.09'; | |||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use fields qw(default_expire_seconds); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | sub TIEHASH{ | ||||||||
|
Subroutine
TIEHASH: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | my ($package, $default_expire_seconds, @params) = @_; | |||||||||
| 15 | 1 | my $self = {}; | |||||||||
| 16 | 1 | bless $self, $package; | |||||||||
| 17 | 1 | my $memd = Cache::Memcached::Fast->new(@params); | |||||||||
| 18 | 1 | $self->{'memd'} = $memd; | |||||||||
| 19 | 1 | $self->{'default_expire_seconds'} = $default_expire_seconds; | |||||||||
| 20 | 1 | return $self; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | sub memd { | ||||||||
|
Subroutine
memd: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | 1 | my $self = shift; | |||||||||
| 25 | 1 | return $self->{memd}; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub STORE{ | ||||||||
|
Subroutine
STORE: not called CC=1 SCAR=6.9
| |||||||||||
| 29 | 0 | my ($self, $key, $value) = @_; | |||||||||
| 30 | 0 | $self->memd->set($key, $value, $self->{'default_expire_seconds'}); | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | # Check for the existence of a value - same as fetch, but sadly this is | ||||||||||
| 34 | # necessary for when the hash is used by libraries that need EXISTS | ||||||||||
| 35 | # functionality | ||||||||||
| 36 | 0 | ▶ | sub EXISTS { | ||||||||
|
Subroutine
EXISTS: not called CC=1 SCAR=6.9
| |||||||||||
| 37 | 0 | my ($self, $key) = @_; | |||||||||
| 38 | 0 | my $val = $self->FETCH($key); | |||||||||
| 39 | 0 | return defined($val); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | # Returns value or hashref (key=>$value) | ||||||||||
| 43 | 0 | ▶ | sub FETCH { | ||||||||
|
Subroutine
FETCH: not called CC=2 SCAR=17.9
| |||||||||||
| 44 | 0 | my $self=shift; | |||||||||
| 45 | 0 | my @keys=split "\x1C", shift; # Some hack for multiple keys | |||||||||
| 46 | 0 | my $val; | |||||||||
| 47 | 0 | ▶ | if (@keys==1){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | $val = $self->memd->get($keys[0]); | |||||||||
| 49 | } else { | ||||||||||
| 50 | 0 | $val = $self->memd->get_multi(@keys); | |||||||||
| 51 | } | ||||||||||
| 52 | 0 | return $val; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | sub DELETE{ | ||||||||
|
Subroutine
DELETE: not called CC=1 SCAR=6.9
| |||||||||||
| 56 | 0 | my $self=shift; | |||||||||
| 57 | 0 | my $key=shift; | |||||||||
| 58 | 0 | $self->memd->delete($key); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | sub UNTIE{ | ||||||||
|
Subroutine
UNTIE: not called CC=1 SCAR=6.9
| |||||||||||
| 62 | 0 | my $self=shift; | |||||||||
| 63 | 0 | $self->disconnect_all(); | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | sub CLEAR{ | ||||||||
|
Subroutine
CLEAR: not called CC=1 SCAR=6.9
| |||||||||||
| 67 | 0 | my $self=shift; | |||||||||
| 68 | 0 | $self->memd->flush_all(); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 1 | 1; | |||||||||
| 72 | __END__ | ||||||||||