line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::Bitcoin::Feed::Site::LakeBtc::Socket; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
574
|
use JSON; |
|
1
|
|
|
|
|
9012
|
|
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
436
|
use Mojo::Base 'Mojo::Transaction::WebSocket'; |
|
1
|
|
|
|
|
5769
|
|
|
1
|
|
|
|
|
4
|
|
5
|
1
|
|
|
1
|
|
92208
|
use Scalar::Util qw(weaken); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
359
|
|
6
|
|
|
|
|
|
|
has 'owner'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub configure { |
9
|
1
|
|
|
1
|
0
|
1
|
my $self = shift; |
10
|
1
|
|
|
|
|
2
|
my $owner = shift; |
11
|
1
|
|
|
|
|
3
|
$self->owner($owner); |
12
|
1
|
|
|
|
|
5
|
weaken($self->{owner}); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# call parse when receive text event |
15
|
|
|
|
|
|
|
$self->on( |
16
|
|
|
|
|
|
|
json => sub { |
17
|
3
|
|
|
3
|
|
2620
|
my ($self, $message) = @_; |
18
|
3
|
|
|
|
|
5
|
$message = $message->[0]; |
19
|
3
|
|
|
|
|
3
|
my $command = shift @$message; |
20
|
3
|
|
|
|
|
10
|
$self->emit($command, $message); |
21
|
1
|
|
|
|
|
7
|
}); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
################################################ |
24
|
|
|
|
|
|
|
# setup events |
25
|
|
|
|
|
|
|
$self->on( |
26
|
|
|
|
|
|
|
subscribe => sub { |
27
|
1
|
|
|
1
|
|
8
|
my ($self, $channel) = @_; |
28
|
|
|
|
|
|
|
$self->on( |
29
|
|
|
|
|
|
|
'setup', |
30
|
|
|
|
|
|
|
sub { |
31
|
1
|
|
|
|
|
9
|
$self->send({json => ['websocket_rails.subscribe', {data => {channel => $channel}}]}); |
32
|
1
|
|
|
|
|
4
|
}); |
33
|
1
|
|
|
|
|
7
|
}); |
34
|
1
|
|
|
|
|
8
|
$self->emit('subscribe', 'ticker'); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
######################################## |
37
|
|
|
|
|
|
|
# events from server |
38
|
|
|
|
|
|
|
$self->on( |
39
|
|
|
|
|
|
|
'client_connected', |
40
|
|
|
|
|
|
|
sub { |
41
|
1
|
|
|
1
|
|
5
|
my $self = shift; |
42
|
1
|
|
|
|
|
2
|
$self->emit('setup'); |
43
|
1
|
|
|
|
|
7
|
}); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$self->on( |
46
|
|
|
|
|
|
|
'websocket_rails.ping', |
47
|
|
|
|
|
|
|
sub { |
48
|
1
|
|
|
1
|
|
11
|
shift->send({json => ['websocket_rails.pong', undef, undef]}); |
49
|
1
|
|
|
|
|
6
|
}); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$self->on( |
52
|
|
|
|
|
|
|
'update', |
53
|
|
|
|
|
|
|
sub { |
54
|
1
|
|
|
1
|
|
5
|
my ($self, $data) = @_; |
55
|
1
|
|
|
|
|
1
|
$data = $data->[0]{data}; |
56
|
1
|
|
|
|
|
5
|
for my $k (sort keys %$data) { |
57
|
2
|
|
|
|
|
6
|
$self->owner->emit( |
58
|
|
|
|
|
|
|
'data_out', |
59
|
|
|
|
|
|
|
0, # no timestamp |
60
|
|
|
|
|
|
|
uc("${k}BTC"), |
61
|
|
|
|
|
|
|
$data->{$k}{last}, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
5
|
}); |
66
|
1
|
|
|
|
|
5
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |