| 1 | package Redis::Fast::List; | ||
| 2 | |||
| 3 | # ABSTRACT: tie Perl arrays to Redis lists | ||
| 4 | # VERSION | ||
| 5 | # AUTHORITY | ||
| 6 | |||
| 7 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use base qw/Redis::Fast Tie::Array/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | |||
| 12 | 0 | ▶ | sub TIEARRAY { |
|
Subroutine
TIEARRAY: not called CC=1 SCAR=6.9
| |||
| 13 | 0 | my ($class, $list, @rest) = @_; | |
| 14 | 0 | my $self = $class->new(@rest); | |
| 15 | |||
| 16 | 0 | $self->__set_data($list); | |
| 17 | |||
| 18 | 0 | return $self; | |
| 19 | } | ||
| 20 | |||
| 21 | 0 | ▶ | sub FETCH { |
|
Subroutine
FETCH: not called CC=1 SCAR=6.9
| |||
| 22 | 0 | my ($self, $index) = @_; | |
| 23 | 0 | $self->lindex($self->__get_data, $index); | |
| 24 | } | ||
| 25 | |||
| 26 | 0 | ▶ | sub FETCHSIZE { |
|
Subroutine
FETCHSIZE: not called CC=1 SCAR=6.9
| |||
| 27 | 0 | my ($self) = @_; | |
| 28 | 0 | $self->llen($self->__get_data); | |
| 29 | } | ||
| 30 | |||
| 31 | 0 | ▶ | sub STORE { |
|
Subroutine
STORE: not called CC=1 SCAR=6.9
| |||
| 32 | 0 | my ($self, $index, $value) = @_; | |
| 33 | 0 | $self->lset($self->__get_data, $index, $value); | |
| 34 | } | ||
| 35 | |||
| 36 | 0 | ▶ | sub STORESIZE { |
|
Subroutine
STORESIZE: not called CC=1 SCAR=6.9
| |||
| 37 | 0 | my ($self, $count) = @_; | |
| 38 | 0 | $self->ltrim($self->__get_data, 0, $count); | |
| 39 | |||
| 40 | # if $count > $self->FETCHSIZE; | ||
| 41 | } | ||
| 42 | |||
| 43 | 0 | ▶ | sub CLEAR { |
|
Subroutine
CLEAR: not called CC=1 SCAR=6.9
| |||
| 44 | 0 | my ($self) = @_; | |
| 45 | 0 | $self->del($self->__get_data); | |
| 46 | } | ||
| 47 | |||
| 48 | 0 | ▶ | sub PUSH { |
|
Subroutine
PUSH: not called CC=2 SCAR=17.9
| |||
| 49 | 0 | my $self = shift; | |
| 50 | 0 | my $list = $self->__get_data; | |
| 51 | |||
| 52 | 0 | $self->rpush($list, $_) for @_; | |
| 53 | } | ||
| 54 | |||
| 55 | 0 | ▶ | sub POP { |
|
Subroutine
POP: not called CC=1 SCAR=6.9
| |||
| 56 | 0 | my $self = shift; | |
| 57 | 0 | $self->rpop($self->__get_data); | |
| 58 | } | ||
| 59 | |||
| 60 | 0 | ▶ | sub SHIFT { |
|
Subroutine
SHIFT: not called CC=1 SCAR=6.9
| |||
| 61 | 0 | my ($self) = @_; | |
| 62 | 0 | $self->lpop($self->__get_data); | |
| 63 | } | ||
| 64 | |||
| 65 | 0 | ▶ | sub UNSHIFT { |
|
Subroutine
UNSHIFT: not called CC=2 SCAR=17.9
| |||
| 66 | 0 | my $self = shift; | |
| 67 | 0 | my $list = $self->__get_data; | |
| 68 | |||
| 69 | 0 | $self->lpush($list, $_) for @_; | |
| 70 | } | ||
| 71 | |||
| 72 | 0 | ▶ | sub SPLICE { |
|
Subroutine
SPLICE: not called CC=1 SCAR=6.9
| |||
| 73 | 0 | my ($self, $offset, $length) = @_; | |
| 74 | 0 | $self->lrange($self->__get_data, $offset, $length); | |
| 75 | |||
| 76 | # FIXME rest of @_ ? | ||
| 77 | } | ||
| 78 | |||
| 79 | 0 | ▶ | sub EXTEND { |
|
Subroutine
EXTEND: not called CC=2 SCAR=17.9
| |||
| 80 | 0 | my ($self, $count) = @_; | |
| 81 | 0 | $self->rpush($self->__get_data, '') for ($self->FETCHSIZE .. ($count - 1)); | |
| 82 | } | ||
| 83 | |||
| 84 | 0 | ▶ | sub DESTROY { $_[0]->quit } |
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||
| 85 | |||
| 86 | 1 | 1; ## End of Redis::Fast::List | |
| 87 | |||
| 88 | =head1 NAME | ||
| 89 | |||
| 90 | Redis::Fast::List - tie Perl arrays to Redis lists | ||
| 91 | |||
| 92 | =head1 SYNOPSYS | ||
| 93 | |||
| 94 | tie @my_list, 'Redis::Fast::List', 'list_name', @Redis_new_parameters; | ||
| 95 | |||
| 96 | $value = $my_list[$index]; | ||
| 97 | $my_list[$index] = $value; | ||
| 98 | |||
| 99 | $count = @my_list; | ||
| 100 | |||
| 101 | push @my_list, 'values'; | ||
| 102 | $value = pop @my_list; | ||
| 103 | unshift @my_list, 'values'; | ||
| 104 | $value = shift @my_list; | ||
| 105 | |||
| 106 | ## NOTE: fourth parameter of splice is *NOT* supported for now | ||
| 107 | @other_list = splice(@my_list, 2, 3); | ||
| 108 | |||
| 109 | @my_list = (); | ||
| 110 | |||
| 111 | |||
| 112 | =cut | ||