blib/lib/KiokuDB/Backend/Redis.pm

filter: Statementstmt 27.0% 13 / 48 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 3 / 8 Podpod 0.0% 0 / 5 totaltotal 23.1% 16 / 69 CC 9 SCAR 22.3
CC
9
Cov
23%
delete
12.0
exists
12.0
insert
12.0
CRAP 9.3
↑ Summary
1 package KiokuDB::Backend::Redis;
2 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Redis;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '0.02';
8  
9 2 has '_redis' => (
10 is => 'rw',
11 isa => 'Redis'
12 );
13  
14 2 with qw(
15 KiokuDB::Backend
16 KiokuDB::Backend::Serialize::Delegate
17 );
18  
19 0 ▶sub new_from_dsn_params {
Subroutine new_from_dsn_params: not called CC=1 SCAR=6.9
Pod undocumented
20 0 my ( $self, %args ) = @_;
21  
22 0 $args{debug} = 1;
23  
24 0 $self->new(_redis => Redis->new(%args));
25 }
26  
27 0 ▶sub delete {
Subroutine delete: not called CC=3 SCAR=24.8
Pod undocumented
28 0 my ($self, @ids_or_entries) = @_;
29  
30 0 my $redis = $self->_redis;
31  
32 0 ▶ my @uids = map { ref($_) ? $_->id : $_ } @ids_or_entries;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
33  
34 0 foreach my $id ( @uids ) {
35  
36 0 $redis->del($id);
37 # TODO Error checking
38 }
39  
40 0 return;
41 }
42  
43 0 ▶sub exists {
Subroutine exists: not called CC=3 SCAR=24.8
Pod undocumented
44 0 my ($self, @ids) = @_;
45  
46 0 my @exists;
47  
48 0 my $redis = $self->_redis;
49 0 foreach my $id (@ids) {
50  
51 0 ▶ if($redis->exists($id)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($redis->exists($id)) { } 0 0 0
52 0 push(@exists, 1);
53 } else {
54 0 push(@exists, 0);
55 }
56 }
57 # TODO Error checking
58 0 return @exists;
59 }
60  
61 0 ▶sub insert {
Subroutine insert: not called CC=3 SCAR=24.8
Pod undocumented
62 0 my ($self, @entries) = @_;
63  
64 0 my $redis = $self->_redis;
65  
66 0 my @exists = $self->exists(@entries);
67  
68 0 foreach my $entry ( @entries ) {
69  
70 0 ▶ if($entry->has_prev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->has_prev) { } 0 0 0
71 0 my $ret = $redis->set(
72 $entry->id => $self->serialize($entry),
73 );
74 # TODO Error checking
75 } else {
76 0 my $ret = $redis->setnx(
77 $entry->id => $self->serialize($entry),
78 );
79 # TODO Error checking
80 }
81 }
82 }
83  
84 0 ▶sub get {
Subroutine get: not called CC=3 SCAR=24.8
Pod undocumented
85 0 my ($self, @ids) = @_;
86  
87 0 my ( $var, @ret );
88  
89 0 my $redis = $self->_redis;
90  
91 0 foreach my $id ( @ids ) {
92 0 my $val = $redis->get($id);
93 # TODO Error checking
94 0 ▶ if(defined($val)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
95 0 push @ret, $val;
96 } else {
97 0 return;
98 }
99 }
100  
101 0 return map { $self->deserialize($_) } @ret;
102 }
103  
104 2 1;
105  
106 __END__
↑ Summary