line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Memcached::Tool::DataSource; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
777
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
49
|
|
4
|
2
|
|
|
2
|
|
5
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
31
|
|
5
|
2
|
|
|
2
|
|
26
|
use 5.008_001; |
|
2
|
|
|
|
|
3
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
7
|
use Carp; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
123
|
|
8
|
2
|
|
|
2
|
|
1094
|
use IO::Socket; |
|
2
|
|
|
|
|
33038
|
|
|
2
|
|
|
|
|
6
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
1702
|
use App::Memcached::Tool::Util qw(is_unixsocket debug); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1297
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
14
|
0
|
|
|
|
|
|
my %args = @_; |
15
|
0
|
|
|
|
|
|
bless \%args, $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub connect { |
19
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
20
|
0
|
|
|
|
|
|
my $addr = shift; |
21
|
0
|
|
|
|
|
|
my %opts = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $socket = sub { |
24
|
0
|
0
|
|
0
|
|
|
return IO::Socket::UNIX->new(Peer => $addr) if is_unixsocket($addr); |
25
|
|
|
|
|
|
|
return IO::Socket::INET->new( |
26
|
|
|
|
|
|
|
PeerAddr => $addr, |
27
|
|
|
|
|
|
|
Proto => 'tcp', |
28
|
0
|
|
0
|
|
|
|
Timeout => $opts{timeout} || 5, |
29
|
|
|
|
|
|
|
); |
30
|
0
|
|
|
|
|
|
}->(); |
31
|
0
|
0
|
|
|
|
|
confess "Can't connect to $addr" unless $socket; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
return $class->new(socket => $socket); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub disconnect { |
37
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
38
|
0
|
0
|
|
|
|
|
$self->{socket}->close or confess "Failed to close connection!"; |
39
|
0
|
|
|
|
|
|
undef $self->{socket}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get { |
43
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
44
|
0
|
|
|
|
|
|
my @keys = @_; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $key_str = join(q{ }, @keys); |
47
|
0
|
|
|
|
|
|
$self->{socket}->write("get $key_str\r\n"); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my @results; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
while (1) { |
52
|
0
|
|
|
|
|
|
my $response = $self->{socket}->getline; |
53
|
0
|
0
|
|
|
|
|
next if ($response =~ m/^[\r\n]+$/); |
54
|
0
|
0
|
|
|
|
|
if ($response =~ m/^VALUE (\S+) (\d+) (\d+)(?: (\d+))?/) { |
|
|
0
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my %data = ( |
56
|
|
|
|
|
|
|
key => $1, |
57
|
|
|
|
|
|
|
flags => $2, |
58
|
|
|
|
|
|
|
length => $3, |
59
|
|
|
|
|
|
|
cas => $4, |
60
|
|
|
|
|
|
|
); |
61
|
0
|
|
|
|
|
|
$self->{socket}->read($response, $data{length}); |
62
|
0
|
|
|
|
|
|
$data{value} = $response; |
63
|
0
|
|
|
|
|
|
push @results, \%data; |
64
|
|
|
|
|
|
|
} elsif ($response =~ m/^END/) { |
65
|
0
|
|
|
|
|
|
last; |
66
|
|
|
|
|
|
|
} else { |
67
|
0
|
|
|
|
|
|
warn "Unknown response '$response'"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return \@results; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub query { |
75
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
76
|
0
|
|
|
|
|
|
my $query = shift; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$self->{socket}->write("$query\r\n"); |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my @response; |
81
|
0
|
|
|
|
|
|
while ($_ = $self->{socket}->getline) { |
82
|
0
|
0
|
|
|
|
|
last if m/^END/; |
83
|
0
|
0
|
|
|
|
|
confess $_ if m/^(CLIENT|SERVER_)?ERROR/; |
84
|
0
|
|
|
|
|
|
$_ =~ s/[\r\n]+$//; |
85
|
0
|
|
|
|
|
|
push @response, $_; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return \@response; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub DESTROY { |
92
|
0
|
|
|
0
|
|
|
my $self = shift; |
93
|
0
|
0
|
|
|
|
|
if ($self->{socket}) { $self->{socket}->close; } |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
__END__ |