KiokuDB/Backend/Hash.pm

filter: Statementstmt 100% 46 / 46 Branchbran 100% 8 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 5 totaltotal 93.2% 69 / 74 CC 7 SCAR 9.7
CC
7
Cov
100%
commit_entries
5.0
get_from_storage
3.0
BEGIN
1.0
CRAP 2.6
« KiokuDB/TypeMap/Entry/Callback.pm ↑ Summary KiokuDB/Test/Fixture/Sets.pm »
1 #!/usr/bin/perl
2  
3 package KiokuDB::Backend::Hash;
4 21 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 21 ▶use Data::Stream::Bulk::Util qw(bulk);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 21 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 21 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 21 with (
13 'KiokuDB::Backend::Serialize::Delegate',
14 'KiokuDB::Backend',
15 'KiokuDB::Backend::Role::Query::Simple::Linear',
16 'KiokuDB::Backend::Role::TXN::Memory::Scan',
17 );
18  
19 has storage => (
20 isa => "HashRef",
21 is => "rw",
22 99 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
23 21 );
24  
25 sub clear_storage {
26 166 ▶ my $self = shift;
Subroutine clear_storage: called CC=1 SCAR=0.0
Pod undocumented
27 166 %{ $self->storage } = ();
28 }
29  
30 sub get_from_storage {
31 2769 ▶ my ( $self, @uids ) = @_;
Subroutine get_from_storage: called CC=3 SCAR=11.0
Pod undocumented
32  
33 2769 my $s = $self->storage;
34  
35 2769 ▶ return if grep { not exists $s->{$_} } @uids;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not exists $s->{$_};} @uids 35 2734 2769
36  
37 2734 my @objs = map { $self->deserialize($_) } @{ $s }{@uids};
38  
39 2734 ▶ if ( @objs == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@objs == 1) { } 2305 429 2734
40 2305 return $objs[0];
41 } else {
42 429 return @objs;
43 }
44 }
45  
46 sub commit_entries {
47 1745 ▶ my ( $self, @entries ) = @_;
Subroutine commit_entries: called CC=5 SCAR=16.1
Pod undocumented
48  
49 1745 my $s = $self->storage;
50  
51 1745 foreach my $entry ( @entries ) {
52 4070 my $id = $entry->id;
53  
54 4070 ▶ if ( $entry->deleted ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->deleted) { } 56 4014 4070
55 56 delete $s->{$id};
56 } else {
57 4014 ▶ if ( exists $s->{$id} and not $entry->has_prev ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $s->{$id} and not $entry->has_prev) 25 3989 4014
Condition100%3/3
exists $s->{$id} and not $entry->has_prev
!ll&&!rl&&r
333365625
MC/DC100%2/2
exists $s->{$id} and not $entry->has_prev
exists $s->{$id} not $entry->has_prev
Truth table100%3/3
A and not(B)
A= exists $s->{$id}B= not $entry->has_prev
ABresult
0X0
100
111
58 25 croak "Entry $id already exists in the database";
59 }
60 3989 $s->{$id} = $self->serialize($entry);
61 }
62 }
63 }
64  
65 sub exists_in_storage {
66 431 ▶ my ( $self, @uids ) = @_;
Subroutine exists_in_storage: called CC=1 SCAR=0.0
Pod undocumented
67  
68 431 map { exists $self->storage->{$_} } @uids;
69 }
70  
71 sub all_storage_entries {
72 783 ▶ my $self = shift;
Subroutine all_storage_entries: called CC=1 SCAR=0.0
Pod undocumented
73 783 return bulk(map { $self->deserialize($_) } values %{ $self->storage });
74 }
75  
76 21 __PACKAGE__->meta->make_immutable;
77  
78 21 __PACKAGE__
79  
80 __END__
81  
82 =pod
83  
84 =head1 NAME
85  
86 KiokuDB::Backend::Hash - In memory backend for testing purposes.
87  
88 =head1 SYNOPSIS
89  
90 my $dir = KiokuDB->new(
91 backend => KiokuDB::Backend::Hash->new(),
92 );
93  
94 =head1 DESCRIPTION
95  
96 This L<KiokuDB> backend provides in memory storage and retrieval of
97 L<KiokuDB::Entry> objects using L<Storable>'s C<dclone> to make dumps of the
98 backend clear.
99  
100 =cut
« KiokuDB/TypeMap/Entry/Callback.pm ↑ Summary KiokuDB/Test/Fixture/Sets.pm »