File Coverage

blib/lib/Redis/Hash.pm
Criterion Covered Total %
statement 12 37 32.4
branch 0 6 0.0
condition n/a
subroutine 4 12 33.3
pod n/a
total 16 55 29.0


line stmt bran cond sub pod time code
1             #
2             # This file is part of Redis
3             #
4             # This software is Copyright (c) 2015 by Pedro Melo, Damien Krotkine.
5             #
6             # This is free software, licensed under:
7             #
8             # The Artistic License 2.0 (GPL Compatible)
9             #
10             package Redis::Hash;
11             $Redis::Hash::VERSION = '1.999';
12             # ABSTRACT: tie Perl hashes to Redis hashes
13             # VERSION
14             # AUTHORITY
15              
16 1     1   79886 use strict;
  1         11  
  1         29  
17 1     1   6 use warnings;
  1         2  
  1         23  
18 1     1   492 use Tie::Hash;
  1         942  
  1         34  
19 1     1   6 use base qw/Redis Tie::StdHash/;
  1         2  
  1         684  
20              
21              
22             sub TIEHASH {
23 0     0     my ($class, $prefix, @rest) = @_;
24 0           my $self = $class->new(@rest);
25              
26 0 0         $self->{prefix} = $prefix ? "$prefix:" : '';
27              
28 0           return $self;
29             }
30              
31             sub STORE {
32 0     0     my ($self, $key, $value) = @_;
33 0           $self->set($self->{prefix} . $key, $value);
34             }
35              
36             sub FETCH {
37 0     0     my ($self, $key) = @_;
38 0           $self->get($self->{prefix} . $key);
39             }
40              
41             sub FIRSTKEY {
42 0     0     my $self = shift;
43 0           $self->{prefix_keys} = [$self->keys($self->{prefix} . '*')];
44 0           $self->NEXTKEY;
45             }
46              
47             sub NEXTKEY {
48 0     0     my $self = shift;
49              
50 0           my $key = shift @{ $self->{prefix_keys} };
  0            
51 0 0         return unless defined $key;
52              
53 0           my $p = $self->{prefix};
54 0 0         $key =~ s/^$p// if $p;
55 0           return $key;
56             }
57              
58             sub EXISTS {
59 0     0     my ($self, $key) = @_;
60 0           $self->exists($self->{prefix} . $key);
61             }
62              
63             sub DELETE {
64 0     0     my ($self, $key) = @_;
65 0           $self->del($self->{prefix} . $key);
66             }
67              
68             sub CLEAR {
69 0     0     my ($self) = @_;
70 0           $self->del($_) for $self->keys($self->{prefix} . '*');
71 0           $self->{prefix_keys} = [];
72             }
73              
74              
75             1; ## End of Redis::Hash
76              
77             __END__