blib/lib/MojoX/Session/Store/Libmemcached.pm

filter: Statementstmt 45.1% 23 / 51 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 6 / 12 Podpod 100% 5 / 5 totaltotal 43.5% 34 / 78 CC 7 SCAR 19.4
CC
7
Cov
38%
new
20.0
create
6.0
update
6.0
CRAP 7.0
↑ Summary
1 package MojoX::Session::Store::Libmemcached;
2 1 $MojoX::Session::Store::Libmemcached::VERSION = 0.17;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use base 'MojoX::Session::Store';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Memcached::libmemcached;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Storable qw/nfreeze thaw/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 __PACKAGE__->attr('servers');
14 0 ▶__PACKAGE__->attr('_handle' => sub { Memcached::libmemcached->new });
Subroutine __ANON__: not called CC=1 SCAR=1.2
15 1 __PACKAGE__->attr('___expiration___');
16  
17 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
18 0 my $class = shift;
19  
20 0 my $self = $class->SUPER::new(@_);
21 0 bless $self, $class;
22  
23 0 ▶ my $servers = ref $self->servers ?
Branch: 1 branch
BranchTrueFalseTotal
ref $self->servers ? : 0 0 0
24 $self->servers : [ split(/ /, $self->servers) ];
25  
26 0 foreach my $server (@$servers) {
27 0 my ($host, $port) = split(/:/, $server);
28  
29 0 ▶ unless ($self->_handle->memcached_server_add($host, $port)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_handle->memcached_server_add($host, $port)) 0 0 0
30 0 print STDERR "failed to add server $host:$port\n";
31 }
32 }
33  
34 0 return $self;
35 }
36  
37 0 ▶sub create {
Subroutine create: not called CC=2 SCAR=17.9
Pod documented
38 0 my ($self, $sid, $expires, $data) = @_;
39  
40 0 ▶ if ($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 0 0 0
41 0 $data->{___expiration___} = $expires;
42 0 $data = encode_base64(nfreeze($data));
43 }
44  
45 0 return $self->_handle->memcached_set($sid, $data, $expires);
46 }
47  
48 0 ▶sub update {
Subroutine update: not called CC=2 SCAR=17.9
Pod documented
49 0 my ($self, $sid, $expires, $data) = @_;
50  
51 0 ▶ if ($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 0 0 0
52 0 $data->{___expiration___} = $expires;
53 0 $data = encode_base64(nfreeze($data));
54 }
55  
56 0 return $self->_handle->memcached_replace($sid, $data, $expires);
57 }
58  
59 0 ▶sub load {
Subroutine load: not called CC=2 SCAR=17.9
Pod documented
60 0 my ($self, $sid) = @_;
61  
62 0 my $data_base64 = $self->_handle->memcached_get($sid);
63 0 ▶ return unless $data_base64;
Branch: 1 branch
BranchTrueFalseTotal
unless $data_base64 0 0 0
64  
65 0 my $data = thaw(decode_base64($data_base64));
66  
67 0 $self->___expiration___(delete $data->{___expiration___});
68  
69 0 return ($self->___expiration___, $data);
70 }
71  
72 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
73 0 my ($self, $sid) = @_;
74  
75 0 return $self->_handle->memcached_delete($sid);
76 }
77  
78 1 1;
79 __END__
↑ Summary