| 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 | 2 | $Redis::Hash::VERSION = '2.000'; | |||||||||
| 12 | # ABSTRACT: tie Perl hashes to Redis hashes | ||||||||||
| 13 | # VERSION | ||||||||||
| 14 | # AUTHORITY | ||||||||||
| 15 | |||||||||||
| 16 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 2 | ▶ | use Tie::Hash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 2 | ▶ | use base qw/Redis Tie::StdHash/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | 0 | ▶ | sub TIEHASH { | ||||||||
|
Subroutine
TIEHASH: not called CC=2 SCAR=17.9
| |||||||||||
| 23 | 0 | my ($class, $prefix, @rest) = @_; | |||||||||
| 24 | 0 | my $self = $class->new(@rest); | |||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | $self->{prefix} = $prefix ? "$prefix:" : ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | 0 | return $self; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | sub STORE { | ||||||||
|
Subroutine
STORE: not called CC=1 SCAR=6.9
| |||||||||||
| 32 | 0 | my ($self, $key, $value) = @_; | |||||||||
| 33 | 0 | $self->set($self->{prefix} . $key, $value); | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | sub FETCH { | ||||||||
|
Subroutine
FETCH: not called CC=1 SCAR=6.9
| |||||||||||
| 37 | 0 | my ($self, $key) = @_; | |||||||||
| 38 | 0 | $self->get($self->{prefix} . $key); | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | sub FIRSTKEY { | ||||||||
|
Subroutine
FIRSTKEY: not called CC=1 SCAR=6.9
| |||||||||||
| 42 | 0 | my $self = shift; | |||||||||
| 43 | 0 | $self->{prefix_keys} = [$self->keys($self->{prefix} . '*')]; | |||||||||
| 44 | 0 | $self->NEXTKEY; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | sub NEXTKEY { | ||||||||
|
Subroutine
NEXTKEY: not called CC=3 SCAR=24.8
| |||||||||||
| 48 | 0 | my $self = shift; | |||||||||
| 49 | |||||||||||
| 50 | 0 | my $key = shift @{ $self->{prefix_keys} }; | |||||||||
| 51 | 0 | ▶ | return unless defined $key; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | |||||||||||
| 53 | 0 | my $p = $self->{prefix}; | |||||||||
| 54 | 0 | ▶ | $key =~ s/^$p// if $p; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 0 | return $key; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 0 | ▶ | sub EXISTS { | ||||||||
|
Subroutine
EXISTS: not called CC=1 SCAR=6.9
| |||||||||||
| 59 | 0 | my ($self, $key) = @_; | |||||||||
| 60 | 0 | $self->exists($self->{prefix} . $key); | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | sub DELETE { | ||||||||
|
Subroutine
DELETE: not called CC=1 SCAR=6.9
| |||||||||||
| 64 | 0 | my ($self, $key) = @_; | |||||||||
| 65 | 0 | $self->del($self->{prefix} . $key); | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 0 | ▶ | sub CLEAR { | ||||||||
|
Subroutine
CLEAR: not called CC=2 SCAR=17.9
| |||||||||||
| 69 | 0 | my ($self) = @_; | |||||||||
| 70 | 0 | $self->del($_) for $self->keys($self->{prefix} . '*'); | |||||||||
| 71 | 0 | $self->{prefix_keys} = []; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | |||||||||||
| 75 | 2 | 1; ## End of Redis::Hash | |||||||||
| 76 | |||||||||||
| 77 | __END__ | ||||||||||