line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
|
|
|
|
package Tie::Redis::Candy::Array; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: tie Perl arrays to Redis lists - the candy way |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
22
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
57
|
|
12
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
13
|
2
|
|
|
2
|
|
11
|
use Carp qw(croak confess); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
121
|
|
14
|
2
|
|
|
2
|
|
10
|
use CBOR::XS qw(encode_cbor decode_cbor); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
95
|
|
15
|
2
|
|
|
2
|
|
20
|
use base 'Tie::Array'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1839
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $undef = encode_cbor(undef); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '1.000'; # VERSION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub TIEARRAY { |
22
|
2
|
|
|
2
|
|
5
|
my ( $class, $redis, $listname ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
2
|
50
|
|
|
|
14
|
croak "not a Redis instance: $redis" |
25
|
|
|
|
|
|
|
unless ref($redis) =~ m{^(?:Test::Mock::)?Redis$}; |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
|
|
8
|
my $self = { |
28
|
|
|
|
|
|
|
list => $listname, |
29
|
|
|
|
|
|
|
redis => $redis, |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
11
|
return bless( $self, $class ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub FETCH { |
36
|
51
|
|
|
51
|
|
9287
|
my ( $self, $index ) = @_; |
37
|
51
|
|
|
|
|
1267
|
my $data = $self->{redis}->lindex( $self->{list}, $index ); |
38
|
51
|
100
|
|
|
|
3796
|
return unless defined $data; |
39
|
50
|
|
|
|
|
190
|
decode_cbor($data); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub FETCHSIZE { |
43
|
67
|
|
|
67
|
|
12867
|
my ($self) = @_; |
44
|
67
|
|
|
|
|
1621
|
$self->{redis}->llen( $self->{list} ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub STORE { |
48
|
2
|
|
|
2
|
|
433
|
my ( $self, $index, $value ) = @_; |
49
|
2
|
|
|
|
|
59
|
$self->{redis}->lset( $self->{list}, $index, encode_cbor($value) ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub STORESIZE { |
53
|
0
|
|
|
0
|
|
0
|
my ( $self, $count ) = @_; |
54
|
0
|
|
|
|
|
0
|
$self->{redis}->ltrim( $self->{list}, 0, $count ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub CLEAR { |
58
|
1
|
|
|
1
|
|
288
|
my ($self) = @_; |
59
|
1
|
|
|
|
|
30
|
$self->{redis}->del( $self->{list} ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub PUSH { |
63
|
5
|
|
|
5
|
|
282
|
my ( $self, @values ) = @_; |
64
|
5
|
|
|
|
|
171
|
$self->{redis}->rpush( $self->{list}, encode_cbor($_) ) for @values; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub POP { |
68
|
1
|
|
|
1
|
|
282
|
my ($self) = @_; |
69
|
1
|
50
|
|
|
|
258
|
map { defined($_) ? decode_cbor($_) : undef } |
70
|
1
|
|
|
|
|
29
|
$self->{redis}->rpop( $self->{list} ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub SHIFT { |
74
|
1
|
|
|
1
|
|
318
|
my ($self) = @_; |
75
|
1
|
50
|
|
|
|
188
|
map { defined($_) ? decode_cbor($_) : undef } |
76
|
1
|
|
|
|
|
38
|
$self->{redis}->lpop( $self->{list} ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub UNSHIFT { |
80
|
1
|
|
|
1
|
|
3
|
my ( $self, @values ) = @_; |
81
|
1
|
|
|
|
|
33
|
$self->{redis}->lpush( $self->{list}, encode_cbor($_) ) for reverse @values; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub SPLICE { |
85
|
0
|
|
|
0
|
|
|
confess 'UNIMPLEMENTED'; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
1
|
|
|
sub EXTEND { |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
0
|
|
|
sub DESTROY { |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |