Storage/Driver/Memory.pm

filter: Statementstmt 100% 17 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 100% 23 / 23 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Storage/Driver/Files.pm ↑ Summary Storage/Driver/OneFile.pm »
1 package Hash::Storage::Driver::Memory;
2  
3 our $VERSION = '0.02';
4  
5 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Storable qw/dclone/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use base "Hash::Storage::Driver::Base";
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub init {
15 my ($self) = @_;
16 $self->{data} = {};
17 }
18  
19 sub get {
20 my ( $self, $id ) = @_;
21 my $hashes = $self->{data};
22 my $hash = $hashes->{$id};
23  
24 return unless $hash;
25 return dclone($hash);
26 }
27  
28 sub set {
29 my ( $self, $id, $fields ) = @_;
30 my $hashes = $self->{data};
31  
32 @{ $hashes->{$id} }{ keys %$fields } = values %$fields;
33 }
34  
35 sub del {
36 my ( $self, $id ) = @_;
37 my $hashes = $self->{data};
38  
39 delete $hashes->{$id};
40 }
41  
42 sub list {
43 my ( $self, @query ) = @_;
44 my $hashes = $self->{data};
45  
46 my @hashes = values %$hashes;
47 my $filtered = $self->do_filtering(\@hashes, \@query);
48 return dclone $filtered;
49 }
50  
51 sub count {
52 my ( $self, $filter ) = @_;
53 my $hashes = $self->list(where => $filter);
54 return scalar(@$hashes);
55 }
56  
57 1; # End of Hash::Storage
« Storage/Driver/Files.pm ↑ Summary Storage/Driver/OneFile.pm »