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
|
2
|
|
|
2
|
|
10
|
use strictures 2; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
84
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Tie::Redis::Candy::Array; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: tie Perl arrays to Redis lists - the candy way |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
467
|
use Carp qw(croak confess); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
104
|
|
14
|
2
|
|
|
2
|
|
9
|
use CBOR::XS qw(encode_cbor decode_cbor); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
92
|
|
15
|
2
|
|
|
2
|
|
9
|
use base 'Tie::Array'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1606
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $undef = encode_cbor(undef); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '1.001'; # VERSION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub TIEARRAY { |
22
|
2
|
|
|
2
|
|
5
|
my ( $class, $redis, $listname ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
2
|
50
|
|
|
|
16
|
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
|
|
|
|
|
9
|
return bless( $self, $class ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub FETCH { |
36
|
51
|
|
|
51
|
|
9592
|
my ( $self, $index ) = @_; |
37
|
51
|
|
|
|
|
1224
|
my $data = $self->{redis}->lindex( $self->{list}, $index ); |
38
|
51
|
100
|
|
|
|
3774
|
return unless defined $data; |
39
|
50
|
|
|
|
|
181
|
decode_cbor($data); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub FETCHSIZE { |
43
|
67
|
|
|
67
|
|
13944
|
my ($self) = @_; |
44
|
67
|
|
|
|
|
1659
|
$self->{redis}->llen( $self->{list} ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub STORE { |
48
|
2
|
|
|
2
|
|
558
|
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
|
|
405
|
my ($self) = @_; |
59
|
1
|
|
|
|
|
34
|
$self->{redis}->del( $self->{list} ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub PUSH { |
63
|
5
|
|
|
5
|
|
387
|
my ( $self, @values ) = @_; |
64
|
5
|
|
|
|
|
163
|
$self->{redis}->rpush( $self->{list}, encode_cbor($_) ) for @values; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub POP { |
68
|
1
|
|
|
1
|
|
398
|
my ($self) = @_; |
69
|
1
|
50
|
|
|
|
181
|
map { defined($_) ? decode_cbor($_) : undef } |
70
|
1
|
|
|
|
|
30
|
$self->{redis}->rpop( $self->{list} ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub SHIFT { |
74
|
1
|
|
|
1
|
|
403
|
my ($self) = @_; |
75
|
1
|
50
|
|
|
|
177
|
map { defined($_) ? decode_cbor($_) : undef } |
76
|
1
|
|
|
|
|
33
|
$self->{redis}->lpop( $self->{list} ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub UNSHIFT { |
80
|
1
|
|
|
1
|
|
3
|
my ( $self, @values ) = @_; |
81
|
1
|
|
|
|
|
35
|
$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__ |