| 1 | package Tie::Redis::List; | ||||||||||
| 2 | { | ||||||||||
| 3 | 4 | $Tie::Redis::List::VERSION = '0.26'; | |||||||||
| 4 | } | ||||||||||
| 5 | # ABSTRACT: Connect a Redis list to a Perl array | ||||||||||
| 6 | |||||||||||
| 7 | 0 | ▶ | sub TIEARRAY { | ||||||||
|
Subroutine
TIEARRAY: not called CC=1 SCAR=6.9
| |||||||||||
| 8 | 0 | my($class, %args) = @_; | |||||||||
| 9 | 0 | bless \%args, $class; | |||||||||
| 10 | } | ||||||||||
| 11 | |||||||||||
| 12 | 0 | ▶ | sub _cmd { | ||||||||
|
Subroutine
_cmd: not called CC=1 SCAR=6.9
| |||||||||||
| 13 | 0 | my($self, $cmd, @args) = @_; | |||||||||
| 14 | 0 | return $self->{redis}->_cmd($cmd, $self->{key}, @args); | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | 0 | ▶ | sub FETCH { | ||||||||
|
Subroutine
FETCH: not called CC=1 SCAR=6.9
| |||||||||||
| 18 | 0 | my($self, $i) = @_; | |||||||||
| 19 | 0 | $self->_cmd(lindex => $i); | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 0 | ▶ | sub FETCHSIZE { | ||||||||
|
Subroutine
FETCHSIZE: not called CC=1 SCAR=6.9
| |||||||||||
| 23 | 0 | my($self) = @_; | |||||||||
| 24 | 0 | $self->_cmd("llen"); | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 0 | ▶ | sub PUSH { | ||||||||
|
Subroutine
PUSH: not called CC=2 SCAR=17.9
| |||||||||||
| 28 | 0 | my($self, @elements) = @_; | |||||||||
| 29 | 0 | $self->_cmd(rpush => $_) for @elements; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub EXTEND { | ||||||||
|
Subroutine
EXTEND: not called CC=1 SCAR=0.0
| |||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | sub STORE { | ||||||||
|
Subroutine
STORE: not called CC=3 SCAR=24.8
| |||||||||||
| 36 | 0 | my($self, $index, $value) = @_; | |||||||||
| 37 | 0 | my $len = $self->_cmd("llen"); | |||||||||
| 38 | 0 | ▶ | if($index >= $len) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | ▶ | while($index > $len) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | $self->_cmd(rpush => ""); | |||||||||
| 41 | 0 | $len++; | |||||||||
| 42 | } | ||||||||||
| 43 | 0 | $self->_cmd(rpush => $value); | |||||||||
| 44 | } else { | ||||||||||
| 45 | 0 | $self->_cmd(lset => $index, $value); | |||||||||
| 46 | } | ||||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | sub POP { | ||||||||
|
Subroutine
POP: not called CC=1 SCAR=6.9
| |||||||||||
| 50 | 0 | my($self) = @_; | |||||||||
| 51 | 0 | $self->_cmd("rpop"); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | sub SHIFT { | ||||||||
|
Subroutine
SHIFT: not called CC=1 SCAR=6.9
| |||||||||||
| 55 | 0 | my($self) = @_; | |||||||||
| 56 | 0 | $self->_cmd("lpop"); | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | sub UNSHIFT { | ||||||||
|
Subroutine
UNSHIFT: not called CC=1 SCAR=6.9
| |||||||||||
| 60 | 0 | my($self, $value) = @_; | |||||||||
| 61 | 0 | $self->_cmd(lpush => $value); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 0 | ▶ | sub SPLICE { | ||||||||
|
Subroutine
SPLICE: not called CC=3 SCAR=24.8
| |||||||||||
| 65 | 0 | my($self, $offset, $length, @list) = @_; | |||||||||
| 66 | |||||||||||
| 67 | 0 | ▶ | my @items = $length == 0 ? () : $self->_cmd(lrange => $offset, $length - 1); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | ▶ | $self->_cmd(ltrim => $offset, $offset + $length - 1) if $length > 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | # XXX | ||||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 0 | ▶ | sub CLEAR { | ||||||||
|
Subroutine
CLEAR: not called CC=1 SCAR=6.9
| |||||||||||
| 73 | 0 | my($self) = @_; | |||||||||
| 74 | 0 | $self->_cmd("del"); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 4 | 1; | |||||||||
| 78 | |||||||||||
| 79 | |||||||||||
| 80 | __END__ | ||||||||||