line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Memcached::Tool::Util; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
764
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
90
|
|
4
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
88
|
|
5
|
3
|
|
|
3
|
|
76
|
use 5.008_001; |
|
3
|
|
|
|
|
9
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
15
|
use Exporter 'import'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
125
|
|
8
|
3
|
|
|
3
|
|
16
|
use List::Util qw(first); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
300
|
|
9
|
3
|
|
|
3
|
|
1704
|
use POSIX 'strftime'; |
|
3
|
|
|
|
|
18734
|
|
|
3
|
|
|
|
|
37
|
|
10
|
3
|
|
|
3
|
|
5565
|
use Time::HiRes 'gettimeofday'; |
|
3
|
|
|
|
|
3948
|
|
|
3
|
|
|
|
|
14
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
13
|
|
|
|
|
|
|
looks_like_addr |
14
|
|
|
|
|
|
|
create_addr |
15
|
|
|
|
|
|
|
is_unixsocket |
16
|
|
|
|
|
|
|
debug |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => \@EXPORT_OK); |
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
3
|
|
1140
|
use App::Memcached::Tool; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
87
|
|
21
|
3
|
|
|
3
|
|
14
|
use App::Memcached::Tool::Constants ':all'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
389
|
|
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
3
|
|
14
|
use version; our $VERSION = 'v0.9.4'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
14
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub looks_like_addr { |
26
|
14
|
|
|
14
|
0
|
21
|
my $string = shift; |
27
|
14
|
50
|
|
|
|
34
|
return $string if is_unixsocket($string); |
28
|
|
|
|
|
|
|
|
29
|
14
|
|
|
|
|
20
|
my $hostname = $string; |
30
|
14
|
100
|
|
82
|
|
85
|
if (first { $_ eq $string } MODES()) { |
|
82
|
|
|
|
|
83
|
|
31
|
5
|
|
|
|
|
22
|
return; |
32
|
|
|
|
|
|
|
} |
33
|
9
|
100
|
|
|
|
56
|
if ($hostname =~ m/([^\s:]+):\d+/) { |
34
|
2
|
|
|
|
|
6
|
$hostname = $1; |
35
|
|
|
|
|
|
|
} |
36
|
9
|
100
|
|
|
|
77077
|
return $string if gethostbyname($hostname); |
37
|
|
|
|
|
|
|
|
38
|
5
|
|
|
|
|
136
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub create_addr { |
42
|
20
|
|
|
20
|
0
|
3678
|
my $base_addr = shift; |
43
|
20
|
100
|
|
|
|
66
|
return DEFAULT_ADDR() unless $base_addr; |
44
|
10
|
50
|
|
|
|
23
|
return $base_addr if is_unixsocket($base_addr); |
45
|
10
|
100
|
|
|
|
68
|
return $base_addr if ($base_addr =~ m/([^\s:]+):\d+/); |
46
|
5
|
|
|
|
|
18
|
return join(qw{:}, $base_addr, DEFAULT_PORT()); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub debug { |
50
|
0
|
|
|
0
|
0
|
0
|
my $message = shift; |
51
|
0
|
0
|
|
|
|
0
|
return unless $App::Memcached::Tool::DEBUG; |
52
|
0
|
|
|
|
|
0
|
my ($sec, $usec) = gettimeofday; |
53
|
0
|
|
|
|
|
0
|
printf STDERR "%s.%03d [DEBUG] $message at %s line %d.\n", |
54
|
|
|
|
|
|
|
strftime('%F %T', localtime($sec)), $usec/1000, (caller)[1,2]; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub is_unixsocket { |
58
|
24
|
|
|
24
|
0
|
31
|
my $file = shift; |
59
|
24
|
50
|
33
|
|
|
485
|
return 1 if (-e $file && -S $file); |
60
|
24
|
|
|
|
|
64
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
__END__ |