line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mcache; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
850
|
use 5.010001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
47
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
1597
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw(new get add del update count id); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.031'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
################### |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
1
|
|
|
1
|
0
|
14
|
my $classname = shift; |
19
|
1
|
|
|
|
|
3
|
my $self = {}; |
20
|
1
|
|
|
|
|
4
|
bless($self,$classname); |
21
|
1
|
|
|
|
|
7
|
$self->_init(@_); |
22
|
1
|
|
|
|
|
4
|
return $self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _init { |
26
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
27
|
1
|
50
|
|
|
|
5
|
if (@_) { |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
|
0
|
sub DESTROY { |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
################### |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub add { |
37
|
4
|
|
|
4
|
0
|
18
|
my $self = shift; |
38
|
4
|
|
|
|
|
11
|
my @in = @_; |
39
|
4
|
|
|
|
|
5
|
my $key; |
40
|
4
|
50
|
|
|
|
10
|
if ($in[1]) { |
41
|
4
|
50
|
|
|
|
8
|
if ($in[2]) { |
42
|
0
|
|
|
|
|
0
|
$key = "$in[2]"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
|
|
|
|
|
|
# generate unique KEY |
46
|
4
|
|
|
|
|
131
|
$key = "$in[1]"."-".rand(1000000)."-".time."-".rand(3141592652); |
47
|
|
|
|
|
|
|
} |
48
|
4
|
|
|
|
|
25
|
$self->{$in[1]}->{"$key"} = "\"key\": \"$key\", ".$in[0]; |
49
|
|
|
|
|
|
|
|
50
|
4
|
|
|
|
|
7
|
my $str = "\"list\": ["; |
51
|
4
|
|
|
|
|
7
|
my $count = 0; |
52
|
4
|
|
|
|
|
7
|
my $rndid = rand(314159265); |
53
|
4
|
|
|
|
|
23
|
foreach my $d (sort keys %{$self->{$in[1]}}) { |
|
4
|
|
|
|
|
26
|
|
54
|
19
|
100
|
|
|
|
37
|
if ($d eq 'CACHE') {next;} |
|
3
|
|
|
|
|
5
|
|
55
|
16
|
100
|
|
|
|
23
|
if ($d eq 'STAT') {next;} |
|
3
|
|
|
|
|
7
|
|
56
|
13
|
100
|
|
|
|
26
|
if ($d eq 'ID') {next;} |
|
3
|
|
|
|
|
4
|
|
57
|
10
|
|
|
|
|
26
|
$str = $str." {".$self->{$in[1]}->{$d}."},"; |
58
|
10
|
|
|
|
|
10
|
++$count; |
59
|
10
|
|
|
|
|
19
|
$rndid = $rndid + rand(314159265); |
60
|
|
|
|
|
|
|
} |
61
|
4
|
|
|
|
|
23
|
chop($str); |
62
|
4
|
|
|
|
|
8
|
$str = $str."], \"count\": \"$count\""; |
63
|
4
|
|
|
|
|
9
|
$self->{$in[1]}->{'CACHE'} = $str; |
64
|
4
|
|
|
|
|
8
|
$self->{$in[1]}->{'STAT'} = $count; |
65
|
4
|
|
|
|
|
7
|
$self->{$in[1]}->{'ID'} = $rndid; |
66
|
4
|
|
|
|
|
5
|
undef $str; |
67
|
4
|
|
|
|
|
6
|
undef $rndid; |
68
|
4
|
|
|
|
|
34
|
undef @in; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
4
|
|
|
|
|
13
|
return $key; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else { |
74
|
0
|
|
|
|
|
0
|
return 0; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub update { |
79
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
80
|
0
|
|
|
|
|
0
|
my @in = @_; |
81
|
0
|
|
|
|
|
0
|
my $key; |
82
|
0
|
0
|
|
|
|
0
|
if ($in[2]) { |
83
|
0
|
|
|
|
|
0
|
$key = "$in[2]"; |
84
|
0
|
0
|
|
|
|
0
|
if (exists $self->{$in[1]}->{$in[2]}) { |
85
|
0
|
|
|
|
|
0
|
$self->{$in[1]}->{$in[2]} = "\"key\": \"$key\", ".$in[0]; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
0
|
my $str = "\"list\": ["; |
88
|
0
|
|
|
|
|
0
|
my $count = 0; |
89
|
0
|
|
|
|
|
0
|
my $rndid = rand(314159265); |
90
|
0
|
|
|
|
|
0
|
foreach my $d (sort keys %{$self->{$in[1]}}) { |
|
0
|
|
|
|
|
0
|
|
91
|
0
|
0
|
|
|
|
0
|
if ($d eq 'CACHE') {next;} |
|
0
|
|
|
|
|
0
|
|
92
|
0
|
0
|
|
|
|
0
|
if ($d eq 'STAT') {next;} |
|
0
|
|
|
|
|
0
|
|
93
|
0
|
0
|
|
|
|
0
|
if ($d eq 'ID') {next;} |
|
0
|
|
|
|
|
0
|
|
94
|
0
|
|
|
|
|
0
|
$str = $str." {".$self->{$in[1]}->{$d}."},"; |
95
|
0
|
|
|
|
|
0
|
++$count; |
96
|
0
|
|
|
|
|
0
|
$rndid = $rndid + rand(314159265); |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
0
|
chop($str); |
99
|
0
|
|
|
|
|
0
|
$str = $str."], \"count\": \"$count\""; |
100
|
0
|
|
|
|
|
0
|
$self->{$in[1]}->{'CACHE'} = $str; |
101
|
0
|
|
|
|
|
0
|
$self->{$in[1]}->{'STAT'} = $count; |
102
|
0
|
|
|
|
|
0
|
$self->{$in[1]}->{'ID'} = $rndid; |
103
|
0
|
|
|
|
|
0
|
undef $str; |
104
|
0
|
|
|
|
|
0
|
undef $rndid; |
105
|
0
|
|
|
|
|
0
|
undef @in; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
else { |
108
|
|
|
|
|
|
|
# add(@in); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub del { |
114
|
2
|
|
|
2
|
0
|
12
|
my $self = shift; |
115
|
2
|
|
|
|
|
6
|
my @in = @_; |
116
|
2
|
50
|
|
|
|
7
|
if ($in[1]) { |
117
|
2
|
50
|
|
|
|
8
|
if (exists $self->{$in[0]}->{$in[1]}) { |
118
|
2
|
|
|
|
|
7
|
delete($self->{$in[0]}->{$in[1]}); |
119
|
|
|
|
|
|
|
# print "del: $in[1]\n"; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
else { |
122
|
|
|
|
|
|
|
# print "no del\n"; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
2
|
|
|
|
|
2
|
my $str = "\"list\": ["; |
127
|
2
|
|
|
|
|
4
|
my $count = 0; |
128
|
2
|
|
|
|
|
3
|
my $rndid = rand(314159265); |
129
|
2
|
|
|
|
|
4
|
foreach my $d (sort keys %{$self->{$in[0]}}) { |
|
2
|
|
|
|
|
10
|
|
130
|
11
|
100
|
|
|
|
24
|
if ($d eq 'CACHE') {next;} |
|
2
|
|
|
|
|
3
|
|
131
|
9
|
100
|
|
|
|
17
|
if ($d eq 'STAT') {next;} |
|
2
|
|
|
|
|
6
|
|
132
|
7
|
100
|
|
|
|
12
|
if ($d eq 'ID') {next;} |
|
2
|
|
|
|
|
3
|
|
133
|
5
|
|
|
|
|
22
|
$str = $str." {(-".$d."-)".$self->{$in[0]}->{$d}."},"; |
134
|
5
|
|
|
|
|
6
|
++$count; |
135
|
5
|
|
|
|
|
30
|
$rndid = $rndid + rand(314159265); |
136
|
|
|
|
|
|
|
} |
137
|
2
|
|
|
|
|
4
|
chop($str); |
138
|
2
|
|
|
|
|
5
|
$str = $str."], \"count\": \"$count\""; |
139
|
2
|
|
|
|
|
6
|
$self->{$in[0]}->{'CACHE'} = $str; |
140
|
2
|
|
|
|
|
4
|
$self->{$in[0]}->{'STAT'} = $count; |
141
|
2
|
|
|
|
|
3
|
$self->{$in[0]}->{'ID'} = $rndid; |
142
|
2
|
|
|
|
|
4
|
undef $str; |
143
|
2
|
|
|
|
|
2
|
undef $rndid; |
144
|
2
|
|
|
|
|
5
|
undef @in; |
145
|
|
|
|
|
|
|
|
146
|
2
|
|
|
|
|
5
|
return 1; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
else { |
149
|
0
|
|
|
|
|
0
|
return 0; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub get { |
154
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
155
|
0
|
|
|
|
|
0
|
my @in = @_; |
156
|
0
|
|
|
|
|
0
|
my $key; |
157
|
0
|
0
|
|
|
|
0
|
if ($in[1]) { |
|
|
0
|
|
|
|
|
|
158
|
0
|
|
|
|
|
0
|
my $r = $self->{$in[0]}->{$in[1]}; |
159
|
0
|
0
|
|
|
|
0
|
if (!$r) { |
160
|
0
|
|
|
|
|
0
|
$r = "\"key\": \"undef\""; |
161
|
|
|
|
|
|
|
} |
162
|
0
|
|
|
|
|
0
|
return $r; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
elsif($in[0]) { |
165
|
0
|
|
|
|
|
0
|
my $r = $self->{$in[0]}->{'CACHE'}; |
166
|
0
|
0
|
|
|
|
0
|
if (!$r) { |
167
|
0
|
|
|
|
|
0
|
return "\"id\": \"null\""; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
else { |
170
|
0
|
|
|
|
|
0
|
return $r; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
else { |
174
|
0
|
|
|
|
|
0
|
return "\"id\": \"undef\""; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub count { |
180
|
2
|
|
|
2
|
0
|
23
|
my $self = shift; |
181
|
2
|
|
|
|
|
5
|
my @in = @_; |
182
|
2
|
50
|
|
|
|
9
|
if ($in[0]) { |
183
|
2
|
|
|
|
|
11
|
return $self->{$in[0]}->{'STAT'}; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub id { |
188
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
189
|
0
|
|
|
|
|
|
my @in = @_; |
190
|
0
|
0
|
|
|
|
|
if ($in[0]) { |
191
|
0
|
|
|
|
|
|
return $self->{$in[0]}->{'ID'}; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
1; |
197
|
|
|
|
|
|
|
__END__ |