line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::WebSocket::PubSub::Syntax; |
2
|
|
|
|
|
|
|
$Mojo::WebSocket::PubSub::Syntax::VERSION = '0.04'; |
3
|
3
|
|
|
3
|
|
914253
|
use Mojo::Base 'Mojo::EventEmitter'; |
|
3
|
|
|
|
|
22
|
|
|
3
|
|
|
|
|
16
|
|
4
|
3
|
|
|
3
|
|
515
|
use Time::HiRes qw(gettimeofday); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
26
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has 'lookup' => \&_lookup; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub keepalive { |
9
|
6
|
|
|
6
|
0
|
4340
|
return { t => 'k' }; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub ping() { |
13
|
4
|
|
|
4
|
0
|
10659
|
return { t => 'i', cts => [gettimeofday] }; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub pong { |
17
|
2
|
|
|
2
|
0
|
63
|
my $s = shift; |
18
|
2
|
|
50
|
|
|
7
|
my $ping = shift || return; |
19
|
2
|
|
|
|
|
6
|
$ping->{t} = 'o'; |
20
|
2
|
|
|
|
|
17
|
$ping->{sts} = [gettimeofday]; |
21
|
2
|
|
|
|
|
9
|
return $ping; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub listen { |
25
|
8
|
|
|
8
|
0
|
30148
|
my $s = shift; |
26
|
8
|
|
|
|
|
20
|
my $ch = shift; |
27
|
8
|
|
|
|
|
49
|
return {t => 'l', ch => $ch}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub listened { |
31
|
17
|
|
|
17
|
0
|
38
|
my $s = shift; |
32
|
17
|
|
50
|
|
|
49
|
my $join = shift || return; |
33
|
17
|
|
|
|
|
42
|
$join->{t} = 'd'; |
34
|
17
|
|
|
|
|
44
|
return $join; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub notify { |
38
|
6
|
|
|
6
|
0
|
13935
|
my $s = shift; |
39
|
6
|
|
50
|
|
|
20
|
my $msg = shift || return; |
40
|
6
|
|
|
|
|
32
|
return {t => 'n', msg => $msg}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub notified { |
44
|
4
|
|
|
4
|
0
|
12
|
my $s = shift; |
45
|
4
|
|
50
|
|
|
16
|
my $msg = shift || return; |
46
|
4
|
|
|
|
|
10
|
$msg->{t} = 'm'; |
47
|
4
|
|
|
|
|
19
|
return $msg; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub broadcast_notify { |
51
|
4
|
|
|
4
|
0
|
13
|
my $s = shift; |
52
|
4
|
|
50
|
|
|
15
|
my $msg = shift || return; |
53
|
4
|
|
50
|
|
|
14
|
my $from = shift || return; |
54
|
4
|
|
|
|
|
12
|
$msg->{t} = 'b'; |
55
|
4
|
|
|
|
|
11
|
$msg->{from} = $from; |
56
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
10
|
return $msg; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub parse { |
61
|
38
|
|
|
38
|
0
|
120
|
my $s = shift; |
62
|
38
|
|
50
|
|
|
111
|
my $msg = shift || return; |
63
|
|
|
|
|
|
|
|
64
|
38
|
|
|
|
|
83
|
my $cmd = $msg->{t}; |
65
|
38
|
50
|
|
|
|
132
|
return unless exists $s->lookup->{$cmd}; |
66
|
38
|
|
|
|
|
175
|
my $ll = $s->lookup->{$cmd}; |
67
|
|
|
|
|
|
|
|
68
|
38
|
|
|
|
|
220
|
$s->emit( all => $ll->{cb}->( $s, $ll->{event}, $msg ) ); |
69
|
38
|
|
|
|
|
4362
|
$s->emit( $ll->{event} => $ll->{cb}->( $s, $msg ) ); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _lookup { |
73
|
23
|
|
|
23
|
|
126
|
my $s = shift; |
74
|
|
|
|
|
|
|
my $ll = { |
75
|
|
|
|
|
|
|
k => { |
76
|
|
|
|
|
|
|
event => 'keepalive', |
77
|
|
|
|
|
|
|
}, |
78
|
|
|
|
|
|
|
i => { |
79
|
|
|
|
|
|
|
event => 'ping', |
80
|
1
|
|
|
1
|
|
6
|
reply => sub { $s->pong($_[0]); }, |
81
|
|
|
|
|
|
|
}, |
82
|
|
|
|
|
|
|
o => { |
83
|
|
|
|
|
|
|
event => 'pong', |
84
|
|
|
|
|
|
|
}, |
85
|
|
|
|
|
|
|
l => { |
86
|
|
|
|
|
|
|
event => 'listen', |
87
|
16
|
|
|
16
|
|
72
|
reply => sub { $s->listened($_[0]); }, |
88
|
|
|
|
|
|
|
}, |
89
|
|
|
|
|
|
|
d => { |
90
|
|
|
|
|
|
|
event => 'listened', |
91
|
|
|
|
|
|
|
}, |
92
|
|
|
|
|
|
|
n => { |
93
|
|
|
|
|
|
|
event => 'notify', |
94
|
3
|
|
|
3
|
|
25
|
reply => sub { $s->broadcast_notify($_[0], $_[1]) }, |
95
|
|
|
|
|
|
|
}, |
96
|
23
|
|
|
|
|
614
|
'm' => { |
97
|
|
|
|
|
|
|
event => 'notified', |
98
|
|
|
|
|
|
|
}, |
99
|
|
|
|
|
|
|
b => { |
100
|
|
|
|
|
|
|
event => 'broadcast_notify', |
101
|
|
|
|
|
|
|
}, |
102
|
|
|
|
|
|
|
}; |
103
|
23
|
|
|
|
|
128
|
foreach ( keys %$ll ) { |
104
|
184
|
|
|
76
|
|
575
|
$ll->{$_}->{cb} = sub {shift; return @_}; |
|
76
|
|
|
|
|
108
|
|
|
76
|
|
|
|
|
240
|
|
105
|
|
|
|
|
|
|
} |
106
|
23
|
|
|
|
|
136
|
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.04 |
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__ |