line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Weixin::Client::Base; |
2
|
1
|
|
|
1
|
|
10331
|
use Time::HiRes; |
|
1
|
|
|
|
|
2040
|
|
|
1
|
|
|
|
|
5
|
|
3
|
1
|
|
|
1
|
|
319
|
use AE; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1345
|
|
4
|
1
|
|
|
1
|
|
9
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
104
|
|
5
|
1
|
|
|
1
|
|
800
|
use JSON (); |
|
1
|
|
|
|
|
44214
|
|
|
1
|
|
|
|
|
514
|
|
6
|
|
|
|
|
|
|
sub now{ |
7
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
8
|
0
|
|
|
|
|
|
return int Time::HiRes::time() * 1000; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
sub json_decode { |
11
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
12
|
0
|
|
|
|
|
|
my $json = shift; |
13
|
0
|
|
|
|
|
|
my $d; |
14
|
0
|
|
|
|
|
|
eval{ |
15
|
0
|
|
|
|
|
|
$d = JSON->new->utf8->decode($json); |
16
|
|
|
|
|
|
|
}; |
17
|
0
|
|
|
|
|
|
return $d; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
sub json_encode { |
20
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
21
|
0
|
|
|
|
|
|
my $d = shift; |
22
|
0
|
|
|
|
|
|
my $json; |
23
|
0
|
|
|
|
|
|
eval{ |
24
|
0
|
|
|
|
|
|
$json = JSON->new->utf8->encode($d); |
25
|
|
|
|
|
|
|
}; |
26
|
0
|
|
|
|
|
|
return $json; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub timer { |
30
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
31
|
0
|
|
|
|
|
|
my $delay = shift; |
32
|
0
|
|
|
|
|
|
my $callback = shift; |
33
|
0
|
|
|
|
|
|
my $rand_watcher_id = rand(); |
34
|
|
|
|
|
|
|
$self->{_watchers}{$rand_watcher_id} = AE::timer $delay,0,sub{ |
35
|
0
|
|
|
0
|
|
|
delete $self->{_watchers}{$rand_watcher_id}; |
36
|
0
|
|
|
|
|
|
$callback->(); |
37
|
0
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub timer2 { |
42
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
43
|
0
|
|
|
|
|
|
my ($id,$interval,$callback) = @_; |
44
|
0
|
|
|
|
|
|
my $delay = 0; |
45
|
0
|
|
|
|
|
|
my $now = time; |
46
|
0
|
0
|
0
|
|
|
|
if(exists $self->{_intervals}{$id} and defined $self->{_intervals}{$id}{_last_dispatch_time}){ |
47
|
0
|
0
|
|
|
|
|
$delay = $now<$self->{_intervals}{$id}{_last_dispatch_time} + $interval? |
48
|
|
|
|
|
|
|
$self->{_intervals}{$id}{_last_dispatch_time}+$interval - $now |
49
|
|
|
|
|
|
|
: 0; |
50
|
|
|
|
|
|
|
$self->timer($delay,sub{ |
51
|
0
|
|
|
0
|
|
|
$self->{_intervals}{$id}{_last_dispatch_time} = time; |
52
|
0
|
|
|
|
|
|
$callback->(); |
53
|
0
|
|
|
|
|
|
}); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else{ |
56
|
0
|
|
|
|
|
|
$self->{_intervals}{$id}{_last_dispatch_time} = time; |
57
|
0
|
|
|
|
|
|
$callback->(); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |