Candy/Hash.pm

filter: Statementstmt 100% 37 / 37 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 98.1% 52 / 53 CC 3 SCAR 2.5
CC
3
Cov
98%
TIEHASH
2.0
FETCH
2.0
BEGIN
1.0
CRAP 1.3
« Candy.pm ↑ Summary
1 # This file was part of Redis, licensed under:
2 #
3 # The Artistic License 2.0 (GPL Compatible)
4 #
5 # Copyright (c) 2015 by Pedro Melo, Damien Krotkine.
6  
7 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 package Tie::Redis::Candy::Hash;
10  
11 # ABSTRACT: tie Perl hashes to Redis hashes - the candy way
12  
13 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use CBOR::XS qw(encode_cbor decode_cbor);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use base 'Tie::Hash';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 2 our $VERSION = '1.001'; # VERSION
18  
19 2 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=2 SCAR=7.0
20 2 my ( $class, $redis, $key ) = @_;
21  
22 2 ▶ croak "not a Redis instance: $redis"
Branch: 1 branch
BranchTrueFalseTotal
unless ref($redis) =~ /^(?:Test::Mock::)?Redis$/ 0 2 2
23 unless ref($redis) =~ m{^(?:Test::Mock::)?Redis$};
24  
25 2 my $self = {
26 key => $key,
27 redis => $redis,
28 };
29  
30 2 return bless( $self, $class );
31 }
32  
33 6 ▶sub STORE {
Subroutine STORE: called CC=1 SCAR=0.0
34 6 my ( $self, $key, $value ) = @_;
35 6 $self->{redis}->hset( $self->{key}, $key, encode_cbor($value) );
36 }
37  
38 12 ▶sub FETCH {
Subroutine FETCH: called CC=2 SCAR=6.9
39 12 my ( $self, $key ) = @_;
40 12 my $data = $self->{redis}->hget( $self->{key}, $key );
41 12 ▶ return unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 1 11 12
42 11 decode_cbor($data);
43 }
44  
45 4 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
46 4 my $self = shift;
47 4 $self->{keys} = [ $self->{redis}->hkeys( $self->{key} ) ];
48 4 $self->NEXTKEY;
49 }
50  
51 12 ▶sub NEXTKEY {
Subroutine NEXTKEY: called CC=1 SCAR=0.0
52 12 my $self = shift;
53 12 shift @{ $self->{keys} };
54 }
55  
56 11 ▶sub EXISTS {
Subroutine EXISTS: called CC=1 SCAR=0.0
57 11 my ( $self, $key ) = @_;
58 11 $self->{redis}->hexists( $self->{key}, $key );
59 }
60  
61 1 ▶sub DELETE {
Subroutine DELETE: called CC=1 SCAR=0.0
62 1 my ( $self, $key ) = @_;
63 1 $self->{redis}->hdel( $self->{key}, $key );
64 }
65  
66 1 ▶sub CLEAR {
Subroutine CLEAR: called CC=1 SCAR=0.0
67 1 my ($self) = @_;
68 1 $self->{redis}->del( $self->{key} );
69 1 delete $self->{keys};
70 }
71  
72 2 1;
73  
74 __END__
« Candy.pm ↑ Summary