line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::WebSocket::PubSub::Syntax; |
2
|
|
|
|
|
|
|
$Mojo::WebSocket::PubSub::Syntax::VERSION = '0.06'; |
3
|
3
|
|
|
3
|
|
1139135
|
use Mojo::Base 'Mojo::EventEmitter'; |
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
21
|
|
4
|
3
|
|
|
3
|
|
490
|
use Time::HiRes qw(gettimeofday); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has 'lookup' => \&_lookup; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub keepalive { |
9
|
6
|
|
|
6
|
0
|
4496
|
return { t => 'k' }; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub ping() { |
13
|
4
|
|
|
4
|
0
|
12878
|
return { t => 'i', cts => [gettimeofday] }; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub pong { |
17
|
2
|
|
|
2
|
0
|
12
|
my $s = shift; |
18
|
2
|
|
50
|
|
|
11
|
my $ping = shift || return; |
19
|
2
|
|
|
|
|
5
|
$ping->{t} = 'o'; |
20
|
2
|
|
|
|
|
14
|
$ping->{sts} = [gettimeofday]; |
21
|
2
|
|
|
|
|
7
|
return $ping; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub listen { |
25
|
10
|
|
|
10
|
0
|
21458
|
my $s = shift; |
26
|
10
|
|
|
|
|
36
|
my $ch = shift; |
27
|
10
|
|
|
|
|
52
|
return {t => 'l', ch => $ch}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub listened { |
31
|
19
|
|
|
19
|
0
|
40
|
my $s = shift; |
32
|
19
|
|
50
|
|
|
49
|
my $join = shift || return; |
33
|
19
|
|
|
|
|
44
|
$join->{t} = 'd'; |
34
|
19
|
|
|
|
|
46
|
return $join; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub notify { |
38
|
6
|
|
|
6
|
0
|
17856
|
my $s = shift; |
39
|
6
|
|
50
|
|
|
30
|
my $msg = shift || return; |
40
|
6
|
|
|
|
|
34
|
return {t => 'n', msg => $msg}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub notified { |
44
|
4
|
|
|
4
|
0
|
15
|
my $s = shift; |
45
|
4
|
|
50
|
|
|
59
|
my $msg = shift || return; |
46
|
4
|
|
|
|
|
16
|
$msg->{t} = 'm'; |
47
|
4
|
|
|
|
|
15
|
return $msg; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub broadcast_notify { |
51
|
4
|
|
|
4
|
0
|
13
|
my $s = shift; |
52
|
4
|
|
50
|
|
|
17
|
my $msg = shift || return; |
53
|
4
|
|
50
|
|
|
17
|
my $from = shift || return; |
54
|
4
|
|
|
|
|
13
|
$msg->{t} = 'b'; |
55
|
4
|
|
|
|
|
11
|
$msg->{from} = $from; |
56
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
13
|
return $msg; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub parse { |
61
|
42
|
|
|
42
|
0
|
144
|
my $s = shift; |
62
|
42
|
|
50
|
|
|
137
|
my $msg = shift || return; |
63
|
|
|
|
|
|
|
|
64
|
42
|
|
|
|
|
97
|
my $cmd = $msg->{t}; |
65
|
42
|
50
|
|
|
|
129
|
return unless exists $s->lookup->{$cmd}; |
66
|
42
|
|
|
|
|
208
|
my $ll = $s->lookup->{$cmd}; |
67
|
|
|
|
|
|
|
|
68
|
42
|
|
|
|
|
266
|
$s->emit( all => $ll->{cb}->( $s, $ll->{event}, $msg ) ); |
69
|
42
|
|
|
|
|
5862
|
$s->emit( $ll->{event} => $ll->{cb}->( $s, $msg ) ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _lookup { |
73
|
25
|
|
|
25
|
|
131
|
my $s = shift; |
74
|
|
|
|
|
|
|
my $ll = { |
75
|
|
|
|
|
|
|
k => { |
76
|
|
|
|
|
|
|
event => 'keepalive', |
77
|
|
|
|
|
|
|
}, |
78
|
|
|
|
|
|
|
i => { |
79
|
|
|
|
|
|
|
event => 'ping', |
80
|
1
|
|
|
1
|
|
4
|
reply => sub { $s->pong($_[0]); }, |
81
|
|
|
|
|
|
|
}, |
82
|
|
|
|
|
|
|
o => { |
83
|
|
|
|
|
|
|
event => 'pong', |
84
|
|
|
|
|
|
|
}, |
85
|
|
|
|
|
|
|
l => { |
86
|
|
|
|
|
|
|
event => 'listen', |
87
|
18
|
|
|
18
|
|
46
|
reply => sub { $s->listened($_[0]); }, |
88
|
|
|
|
|
|
|
}, |
89
|
|
|
|
|
|
|
d => { |
90
|
|
|
|
|
|
|
event => 'listened', |
91
|
|
|
|
|
|
|
}, |
92
|
|
|
|
|
|
|
n => { |
93
|
|
|
|
|
|
|
event => 'notify', |
94
|
3
|
|
|
3
|
|
15
|
reply => sub { $s->broadcast_notify($_[0], $_[1]) }, |
95
|
|
|
|
|
|
|
}, |
96
|
25
|
|
|
|
|
416
|
'm' => { |
97
|
|
|
|
|
|
|
event => 'notified', |
98
|
|
|
|
|
|
|
}, |
99
|
|
|
|
|
|
|
b => { |
100
|
|
|
|
|
|
|
event => 'broadcast_notify', |
101
|
|
|
|
|
|
|
}, |
102
|
|
|
|
|
|
|
}; |
103
|
25
|
|
|
|
|
135
|
foreach ( keys %$ll ) { |
104
|
200
|
|
|
84
|
|
678
|
$ll->{$_}->{cb} = sub {shift; return @_}; |
|
84
|
|
|
|
|
147
|
|
|
84
|
|
|
|
|
316
|
|
105
|
|
|
|
|
|
|
} |
106
|
25
|
|
|
|
|
185
|
return $ll; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=pod |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 NAME |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Mojo::WebSocket::PubSub::Syntax - Syntax parser/builder for communication in Mojo::WebSocket::PubSub |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=for html |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 VERSION |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
version 0.06 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 SYNOPSIS |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 DESCRIPTION |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Syntax parser/builder for communication in Mojo::WebSocket::PubSub |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=encoding UTF-8 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 BUGS/CONTRIBUTING |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Please report any bugs through the web interface at L |
140
|
|
|
|
|
|
|
If you want to contribute changes or otherwise involve yourself in development, feel free to fork the Git repository from |
141
|
|
|
|
|
|
|
L. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 SUPPORT |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
You can find this documentation with the perldoc command too. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
perldoc Mojo::WebSocket::PubSub::Syntax |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 AUTHOR |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Emiliano Bruni |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
This software is copyright (c) 2021 by Emiliano Bruni. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
158
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
__END__ |