blib/lib/KiokuDB/Backend/CHI.pm

filter: Statementstmt 100% 48 / 48 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 6 totaltotal 89.3% 67 / 75 CC 6 SCAR 5.6
CC
6
Cov
97%
insert
3.0
delete
2.0
get
2.0
CRAP 1.8
↑ Summary
1 package KiokuDB::Backend::CHI;
2 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 $KiokuDB::Backend::CHI::VERSION = '0.01';
4 }
5  
6 # ABSTRACT: CHI backend for KiokuDB
7  
8 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use CHI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Data::Stream::Bulk::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 with qw/
14 KiokuDB::Backend
15 KiokuDB::Backend::Serialize::Delegate
16 KiokuDB::Backend::Role::Clear
17 KiokuDB::Backend::Role::Scan
18 /;
19  
20 2 has cache => (
21 is => 'ro',
22 isa => 'Object',
23 lazy => 1,
24 required => 1,
25 builder => '_build_cache',
26 );
27  
28 2 has check_duplicates => (
29 is => 'ro',
30 isa => 'Bool',
31 default => 1,
32 );
33  
34 1 ▶sub _build_cache {
Subroutine _build_cache: called CC=1 SCAR=0.0
35 1 my ($self) = @_;
36  
37 1 return CHI->new (driver => 'Memory',datastore => {});
38 }
39  
40 35 ▶sub insert {
Subroutine insert: called CC=3 SCAR=11.0
Pod undocumented
41 35 my ($self,@entries) = @_;
42  
43 35 ▶ if ($self->check_duplicates) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->check_duplicates) 35 0 35
44 35 my @create = map { $_->id } grep { ! $_->has_prev } @entries;
45  
46 35 ▶ confess "Cannot insert duplicate key" if scalar grep { $_ } $self->exists (@create);
Branch: 1 branch
BranchTrueFalseTotal
if scalar grep({$_;} $self->exists(@create)) 1 34 35
47 }
48  
49 34 $self->cache->set_multi ({ map { $_->id => $self->serialize ($_) } @entries });
50  
51 34 return;
52 }
53  
54 1 ▶sub delete {
Subroutine delete: called CC=2 SCAR=7.0
Pod undocumented
55 1 my ($self,@ids_or_entries) = @_;
56  
57 1 ▶ my @ids = map { ref ($_) ? $_->id : $_ } @ids_or_entries;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 1 0 1
58  
59 1 $self->cache->remove_multi (\@ids);
60  
61 1 return;
62 }
63  
64 99 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod undocumented
65 99 my ($self,@ids) = @_;
66  
67 99 ▶ return map { defined $_ ? $self->deserialize ($_) : undef } @{ $self->cache->get_multi_arrayref (\@ids) };
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 1131 1078 2209
68 }
69  
70 43 ▶sub exists {
Subroutine exists: called CC=2 SCAR=6.9
Pod undocumented
71 43 my ($self,@ids) = @_;
72  
73 43 ▶ return $self->cache->is_valid (@ids) if scalar @ids == 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @ids == 1 13 30 43
74  
75 30 return map { ! ! $_ } $self->get (@ids);
76 }
77  
78 6 ▶sub all_entries {
Subroutine all_entries: called CC=1 SCAR=0.0
Pod undocumented
79 6 my ($self) = @_;
80  
81 6 my @entries = map { $self->deserialize ($_) } grep { defined $_ } values %{ $self->cache->dump_as_hash };
82  
83 6 return Data::Stream::Bulk::Array->new (array => \@entries);
84 }
85  
86 2 ▶sub clear {
Subroutine clear: called CC=1 SCAR=0.0
Pod undocumented
87 2 my ($self) = @_;
88  
89 2 $self->cache->clear;
90  
91 2 return;
92 }
93  
94 2 1;
95  
96  
97  
98 __END__
↑ Summary