line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MyApp; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
455
|
use Dancer2; |
|
1
|
|
|
|
|
466809
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
74630
|
use Dancer2::Plugin::WebSocket; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
websocket_on_open sub { |
8
|
|
|
|
|
|
|
my( $conn, $env ) = @_; |
9
|
|
|
|
|
|
|
warn "# opening $conn\n"; |
10
|
|
|
|
|
|
|
}; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
websocket_on_close sub { |
14
|
|
|
|
|
|
|
my( $conn ) = @_; |
15
|
|
|
|
|
|
|
warn "# closing $conn\n"; |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
websocket_on_error sub { |
19
|
|
|
|
|
|
|
my ( $env ) = @_; |
20
|
|
|
|
|
|
|
warn "Something went bonker"; |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
websocket_on_message sub { |
24
|
|
|
|
|
|
|
my( $conn, $message ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
if ( $message->{hello} ) { |
27
|
|
|
|
|
|
|
$message->{hello} = 'browser!'; |
28
|
|
|
|
|
|
|
$conn->send( $message ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if( my $browser = $message->{browser} ) { |
32
|
|
|
|
|
|
|
$conn->add_channels( $browser ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
if ( my $channel = $message->{emit} ) { |
36
|
|
|
|
|
|
|
$conn->to($channel)->send({ emitting => $channel }); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
if ( my $channel = $message->{broadcast} ) { |
40
|
|
|
|
|
|
|
$conn->to($channel)->broadcast({ broadcasting => $channel }); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
get '/' => sub { |
45
|
|
|
|
|
|
|
my $ws_url = websocket_url; |
46
|
|
|
|
|
|
|
return <<"END"; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
WebSocket client |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
END |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
get '/say_hi' => sub { |
79
|
|
|
|
|
|
|
$_->send([ "Hello!" ]) for websocket_connections; |
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |