line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::Plugin::WebSocket::Group; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
3
|
|
|
|
|
|
|
# ABSTACT: Grouping of connections to send messages to |
4
|
|
|
|
|
|
|
$Dancer2::Plugin::WebSocket::Group::VERSION = '0.2.0'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has source => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
required => 1, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has channels => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
required => 1, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
318
|
use Set::Tiny; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
205
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub targets { |
25
|
0
|
|
|
0
|
0
|
|
my ( $self, $omit_self ) = @_; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $channels = Set::Tiny->new( @{$self->channels} ); |
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
return grep { |
30
|
0
|
0
|
0
|
|
|
|
$_->in_channel($channels) and |
31
|
|
|
|
|
|
|
( !$omit_self or $self->source->id != $_->id ) |
32
|
0
|
|
|
|
|
|
} values %{ $self->source->manager->connections }; |
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub send { |
37
|
0
|
|
|
0
|
1
|
|
my ( $self, @args ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$_->send(@args) for $self->targets; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub broadcast { |
44
|
0
|
|
|
0
|
1
|
|
my ( $self, @args ) = @_; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$_->send(@args) for $self->targets(1); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |