| 1 | package PEF::Front::WebSocket::QueueServer::Queue; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use AnyEvent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Scalar::Util qw'weaken refaddr'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 6 | bless { | |||||||||||||||||||||||||||
| 10 | queue => [], | ||||||||||||||||||||||||||||
| 11 | clients => {}, | ||||||||||||||||||||||||||||
| 12 | id => $_[1], | ||||||||||||||||||||||||||||
| 13 | server => $_[2], | ||||||||||||||||||||||||||||
| 14 | }; | ||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 24 | ▶ | sub add_client { | ||||||||||||||||||||||||||
|
Subroutine
add_client: called CC=8 SCAR=21.4
| |||||||||||||||||||||||||||||
| 18 | 24 | my ($self, $client, $last_id) = @_; | |||||||||||||||||||||||||||
| 19 | 24 | my $id_client = $client->id; | |||||||||||||||||||||||||||
| 20 | 24 | my $lcid = refaddr $client; | |||||||||||||||||||||||||||
| 21 | 24 | ▶ | return if $self->{clients}{$lcid}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 24 | weaken $client; | |||||||||||||||||||||||||||
| 23 | 24 | $self->{clients}{$lcid} = $client; | |||||||||||||||||||||||||||
| 24 | 24 | ▶ | if (defined $last_id and $last_id != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $last_id and $last_id != 0
MC/DC50%1/2
defined $last_id and $last_id != 0
defined $last_id
$last_id != 0
Truth table66%2/3
A and B
A= defined $last_idB= $last_id != 0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | if (@{$self->{queue}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | if ($self->{queue}[0][0] <= $last_id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # если первое сообщение в очереди имеет айди не выше последнего, | ||||||||||||||||||||||||||||
| 30 | # то у клиента есть как минимум часть актуальной очереди и никаких сообщений не было потеряно | ||||||||||||||||||||||||||||
| 31 | # дошлём клиенту новые сообщения, если они появились | ||||||||||||||||||||||||||||
| 32 | 2 | for my $mt (@{$self->{queue}}) { | |||||||||||||||||||||||||||
| 33 | 4 | my $id_message = $mt->[0]; | |||||||||||||||||||||||||||
| 34 | 4 | ▶ | if ($id_message > $last_id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 2 | $self->{server}->_transfer($self->{id}, $id_message, $mt->[1], $client->group, [$id_client]); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | } else { | ||||||||||||||||||||||||||||
| 39 | # если айди последнего сообщения клиента "безнадёжно устарел", то ему надо сообщить о необходимости | ||||||||||||||||||||||||||||
| 40 | # перегрузить модель данных | ||||||||||||||||||||||||||||
| 41 | 0 | $self->{server}->_transfer($self->{id}, 0, $self->{server}->reload_message, $client->group, [$id_client]); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } else { | ||||||||||||||||||||||||||||
| 44 | # если в очереди нет сообщений, значит всё давно заэкспайрилось, клиенту надо перегрузить модель данных | ||||||||||||||||||||||||||||
| 45 | 0 | $self->{server}->_transfer($self->{id}, 0, $self->{server}->reload_message, $client->group, [$id_client]); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # если клиент не показал "последенго айди", то у него только что загруженная модель данных | ||||||||||||||||||||||||||||
| 50 | # return true if client was added | ||||||||||||||||||||||||||||
| 51 | 24 | return 1; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 8 | ▶ | sub publish { | ||||||||||||||||||||||||||
|
Subroutine
publish: called CC=9 SCAR=28.2
| |||||||||||||||||||||||||||||
| 55 | 8 | my ($self, $id_message, $message) = @_; | |||||||||||||||||||||||||||
| 56 | 8 | ▶ | if ($id_message != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # упрядочиваем сообщения по $id_message | ||||||||||||||||||||||||||||
| 59 | 8 | my $last_index = @{$self->{queue}} - 1; | |||||||||||||||||||||||||||
| 60 | 8 | ▶ | if (!@{$self->{queue}} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not @{$self->{"queue"};} or $self->{"queue"}[$last_index][0] < $id_message
MC/DC0%0/2
not @{$self->{"queue"};} or $self->{"queue"}[$last_index][0] < $id_message
not @{$self->{"queue"};}
$self->{"queue"}[$last_index][0] < $id_message
Truth table66%2/3
not(A) or B
A= not @{$self->{"queue"};}B= $self->{"queue"}[$last_index][0] < $id_message
| |||||||||||||||||||||||||||||
| 61 | || $self->{queue}[$last_index][0] < $id_message) | ||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||
| 63 | 8 | push @{$self->{queue}}, [$id_message, $message, time]; | |||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ($self->{queue}[0][0] > $id_message) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | unshift @{$self->{queue}}, [$id_message, $message, time]; | |||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | for (my $i = $last_index; $i >= 0; --$i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ($self->{queue}[$i][0] < $id_message) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | splice @{$self->{queue}}, $i + 1, 0, [$id_message, $message, time]; | |||||||||||||||||||||||||||
| 71 | 0 | last; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 8 | my %g; | |||||||||||||||||||||||||||
| 78 | 8 | for (keys %{$self->{clients}}) { | |||||||||||||||||||||||||||
| 79 | 28 | my $c = $self->{clients}{$_}; | |||||||||||||||||||||||||||
| 80 | 28 | push @{$g{$c->group}}, $c->id; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 8 | for my $group (keys %g) { | |||||||||||||||||||||||||||
| 83 | 22 | $self->{server}->_transfer($self->{id}, $id_message, $message, $group, $g{$group}); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 4 | ▶ | sub remove_client { | ||||||||||||||||||||||||||
|
Subroutine
remove_client: called CC=2 SCAR=11.6
| |||||||||||||||||||||||||||||
| 88 | 4 | my ($self, $client) = @_; | |||||||||||||||||||||||||||
| 89 | 4 | my $lcid = refaddr $client; | |||||||||||||||||||||||||||
| 90 | 4 | delete $self->{clients}{$lcid}; | |||||||||||||||||||||||||||
| 91 | 4 | ▶ | if (!%{$self->{clients}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | weaken $self; | |||||||||||||||||||||||||||
| 93 | $self->{destroy_timer} = AnyEvent->timer( | ||||||||||||||||||||||||||||
| 94 | after => $self->{server}->no_client_expiration, | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | cb => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if ($self && !%{$self->{clients}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self and not %{$self->{"clients"};}
MC/DC0%0/2
$self and not %{$self->{"clients"};}
$self
not %{$self->{"clients"};}
Truth table0%0/3
A and not(B)
A= $selfB= not %{$self->{"clients"};}
| |||||||||||||||||||||||||||||
| 97 | 0 | $self->{server}->_remove_queue($self->{id}); | |||||||||||||||||||||||||||
| 98 | 0 | undef $self; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 0 | ); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | package PEF::Front::WebSocket::QueueServer::Client; | ||||||||||||||||||||||||||||
| 106 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 107 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 24 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 110 | 24 | bless { | |||||||||||||||||||||||||||
| 111 | group => $_[1], | ||||||||||||||||||||||||||||
| 112 | id => $_[2], | ||||||||||||||||||||||||||||
| 113 | queues => [] | ||||||||||||||||||||||||||||
| 114 | }; | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 30 | ▶ | sub group { | ||||||||||||||||||||||||||
|
Subroutine
group: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 118 | 30 | $_[0]{group}; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 52 | ▶ | sub id { | ||||||||||||||||||||||||||
|
Subroutine
id: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 122 | 52 | $_[0]{id}; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 24 | ▶ | sub subscribe { | ||||||||||||||||||||||||||
|
Subroutine
subscribe: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 126 | 24 | my ($self, $queue, $last_id) = @_; | |||||||||||||||||||||||||||
| 127 | 24 | ▶ | push @{$self->{queues}}, $queue | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | if $queue->add_client($self, $last_id); | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 4 | ▶ | sub unsubscribe { | ||||||||||||||||||||||||||
|
Subroutine
unsubscribe: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 132 | 4 | my ($self, $queue) = @_; | |||||||||||||||||||||||||||
| 133 | 4 | ▶ | $queue->remove_client($self) if $queue; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 137 | 0 | $_[0]->unsubscribe($_) for @{$_[0]{queues}}; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | package PEF::Front::WebSocket::QueueServer; | ||||||||||||||||||||||||||||
| 141 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 142 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 2 | ▶ | use EV; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 145 | 2 | ▶ | use AnyEvent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 146 | 2 | ▶ | use AnyEvent::Handle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 147 | 2 | ▶ | use AnyEvent::Socket; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 148 | 2 | ▶ | use CBOR::XS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 149 | 2 | ▶ | use Scalar::Util 'weaken'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 24 | ▶ | sub subscribe_client_to_queue { | ||||||||||||||||||||||||||
|
Subroutine
subscribe_client_to_queue: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 152 | 24 | my ($self, $handle, $cmd) = @_; | |||||||||||||||||||||||||||
| 153 | 24 | my $queue = $cmd->{queue}; | |||||||||||||||||||||||||||
| 154 | 24 | my $group = $handle->fh->fileno; | |||||||||||||||||||||||||||
| 155 | 24 | my $cid = $cmd->{id_client}; | |||||||||||||||||||||||||||
| 156 | 24 | my $last_id = $cmd->{last_id}; | |||||||||||||||||||||||||||
| 157 | 24 | ▶ | my $client = ($self->{groups}{$group}{clients}{$cid} ||= PEF::Front::WebSocket::QueueServer::Client->new($group, $cid)); | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"groups"}{$group}{"clients"}{$cid} ||= "PEF::Front::WebSocket::QueueServer::Client"->new($group, $cid)
MC/DC0%0/2
$self->{"groups"}{$group}{"clients"}{$cid} ||= "PEF::Front::WebSocket::QueueServer::Client"->new($group, $cid)
$self->{"groups"}{$group}{"clients"}{$cid}
"PEF::Front::WebSocket::QueueServer::Client"->new($group, $cid)
Truth table33%1/3
A ||= B
A= $self->{"groups"}{$group}{"clients"}{$cid}B= "PEF::Front::WebSocket::QueueServer::Client"->new($group, $cid)
| |||||||||||||||||||||||||||||
| 158 | 24 | ▶ | my $qo = $self->{queues}{$queue} || $self->register_queue($queue); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{'queues'}{$queue} || $self->register_queue($queue)
MC/DC0%0/2
$self->{'queues'}{$queue} || $self->register_queue($queue)
$self->{'queues'}{$queue}
$self->register_queue($queue)
Truth table66%2/3
A || B
A= $self->{'queues'}{$queue}B= $self->register_queue($queue)
| |||||||||||||||||||||||||||||
| 159 | 24 | $client->subscribe($qo, $last_id); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 4 | ▶ | sub unsubscribe_client_from_queue { | ||||||||||||||||||||||||||
|
Subroutine
unsubscribe_client_from_queue: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 4 | my ($self, $handle, $cmd) = @_; | |||||||||||||||||||||||||||
| 164 | 4 | my $queue = $cmd->{queue}; | |||||||||||||||||||||||||||
| 165 | 4 | my $group = $handle->fh->fileno; | |||||||||||||||||||||||||||
| 166 | 4 | my $cid = $cmd->{id_client}; | |||||||||||||||||||||||||||
| 167 | 4 | my $client = $self->{groups}{$group}{clients}{$cid}; | |||||||||||||||||||||||||||
| 168 | 4 | my $qo = $self->{queues}{$queue}; | |||||||||||||||||||||||||||
| 169 | 4 | ▶ | $client->unsubscribe($qo) if $client && $qo; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$client and $qo
MC/DC0%0/2
$client and $qo
$client
$qo
Truth table33%1/3
A and B
A= $clientB= $qo
| |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 8 | ▶ | sub publish_to_queue { | ||||||||||||||||||||||||||
|
Subroutine
publish_to_queue: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 173 | 8 | my ($self, $handle, $cmd) = @_; | |||||||||||||||||||||||||||
| 174 | 8 | my $queue = $cmd->{queue}; | |||||||||||||||||||||||||||
| 175 | 8 | my $id_message = $cmd->{id_message}; | |||||||||||||||||||||||||||
| 176 | 8 | my $message = $cmd->{message}; | |||||||||||||||||||||||||||
| 177 | 8 | ▶ | my $qo = $self->{queues}{$queue} || $self->register_queue($queue); | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'queues'}{$queue} || $self->register_queue($queue)
MC/DC0%0/2
$self->{'queues'}{$queue} || $self->register_queue($queue)
$self->{'queues'}{$queue}
$self->register_queue($queue)
Truth table33%1/3
A || B
A= $self->{'queues'}{$queue}B= $self->register_queue($queue)
| |||||||||||||||||||||||||||||
| 178 | 8 | $qo->publish($id_message, $message); | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 2 | ▶ | sub unregister_client { | ||||||||||||||||||||||||||
|
Subroutine
unregister_client: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 182 | 2 | my ($self, $handle, $cmd) = @_; | |||||||||||||||||||||||||||
| 183 | 2 | my $group = $handle->fh->fileno; | |||||||||||||||||||||||||||
| 184 | 2 | my $cid = $cmd->{id_client}; | |||||||||||||||||||||||||||
| 185 | 2 | delete $self->{groups}{$group}{clients}{$cid}; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 2 | my %cmd_switch = ( | |||||||||||||||||||||||||||
| 189 | subscribe => \&subscribe_client_to_queue, | ||||||||||||||||||||||||||||
| 190 | unsubscribe => \&unsubscribe_client_from_queue, | ||||||||||||||||||||||||||||
| 191 | publish => \&publish_to_queue, | ||||||||||||||||||||||||||||
| 192 | unregister => \&unregister_client, | ||||||||||||||||||||||||||||
| 193 | ); | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 38 | ▶ | sub on_cmd { | ||||||||||||||||||||||||||
|
Subroutine
on_cmd: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 196 | 38 | my ($self, $handle, $cmd) = @_; | |||||||||||||||||||||||||||
| 197 | 38 | my $group = $handle->fh->fileno; | |||||||||||||||||||||||||||
| 198 | $handle->push_read( | ||||||||||||||||||||||||||||
| 199 | 32 | ▶ | cbor => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 200 | 32 | $self->on_cmd(@_); | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 38 | ); | |||||||||||||||||||||||||||
| 203 | 38 | ▶ | if (my $cmd_sub = $cmd_switch{$cmd->{command}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | 38 | $cmd_sub->($self, $handle, $cmd); | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 6 | ▶ | sub register_queue { | ||||||||||||||||||||||||||
|
Subroutine
register_queue: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 209 | 6 | my ($self, $queue) = @_; | |||||||||||||||||||||||||||
| 210 | 6 | $self->{queues}{$queue} = PEF::Front::WebSocket::QueueServer::Queue->new($queue, $self); | |||||||||||||||||||||||||||
| 211 | 6 | $self->{queues}{$queue}; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 6 | ▶ | sub create_group { | ||||||||||||||||||||||||||
|
Subroutine
create_group: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 215 | 6 | my ($self, $group, $handle) = @_; | |||||||||||||||||||||||||||
| 216 | 6 | $self->{groups}{$group} = { | |||||||||||||||||||||||||||
| 217 | handle => $handle, | ||||||||||||||||||||||||||||
| 218 | clients => {} | ||||||||||||||||||||||||||||
| 219 | }; | ||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | ▶ | sub destroy_group { | ||||||||||||||||||||||||||
|
Subroutine
destroy_group: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 223 | 0 | my ($self, $group) = @_; | |||||||||||||||||||||||||||
| 224 | 0 | delete $self->{groups}{$group}; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 0 | ▶ | sub _remove_queue { | ||||||||||||||||||||||||||
|
Subroutine
_remove_queue: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 228 | 0 | my ($self, $queue) = @_; | |||||||||||||||||||||||||||
| 229 | 0 | delete $self->{queues}{$queue}; | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 24 | ▶ | sub _transfer { | ||||||||||||||||||||||||||
|
Subroutine
_transfer: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 233 | 24 | my ($self, $queue, $id_message, $message, $group, $cidref) = @_; | |||||||||||||||||||||||||||
| 234 | 24 | my $handle = $self->{groups}{$group}{handle}; | |||||||||||||||||||||||||||
| 235 | 24 | $handle->push_write(cbor => [$queue, $id_message, $message, $cidref]); | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | sub on_disconnect { | ||||||||||||||||||||||||||
|
Subroutine
on_disconnect: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 239 | 0 | my ($self, $handle, $fatal, $msg) = @_; | |||||||||||||||||||||||||||
| 240 | 0 | $self->destroy_group($handle->fh->fileno); | |||||||||||||||||||||||||||
| 241 | 0 | $handle->destroy; | |||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 6 | ▶ | sub on_accept { | ||||||||||||||||||||||||||
|
Subroutine
on_accept: called CC=1 SCAR=0.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 246 | 6 | my ($self, $fh, $host, $port) = @_; | |||||||||||||||||||||||||||
| 247 | my $handle = AnyEvent::Handle->new( | ||||||||||||||||||||||||||||
| 248 | 0 | ▶ | on_error => sub {$self->on_disconnect(@_)}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 249 | 0 | ▶ | on_eof => sub {$self->on_disconnect(@_)}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 250 | 6 | fh => $fh, | |||||||||||||||||||||||||||
| 251 | ); | ||||||||||||||||||||||||||||
| 252 | 6 | $self->create_group($fh->fileno, $handle); | |||||||||||||||||||||||||||
| 253 | $handle->push_read( | ||||||||||||||||||||||||||||
| 254 | 6 | ▶ | cbor => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 255 | 6 | ▶ | $self->on_cmd(@_) if $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | 6 | ); | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 261 | 2 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 262 | 2 | my $self; | |||||||||||||||||||||||||||
| 263 | 2 | ▶ | my $tcp_address = delete $args{address} || '127.0.0.1'; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{'address'} || '127.0.0.1'
MC/DC0%0/1
delete $args{'address'} || '127.0.0.1'
delete $args{'address'}
Truth table50%1/2
A
A= delete $args{'address'}
| |||||||||||||||||||||||||||||
| 264 | 2 | ▶ | my $tcp_port = delete $args{port} || 54321; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{'port'} || 54321
MC/DC0%0/1
delete $args{'port'} || 54321
delete $args{'port'}
Truth table50%1/2
A
A= delete $args{'port'}
| |||||||||||||||||||||||||||||
| 265 | 2 | ▶ | my $no_client_expiration = delete $args{no_client_expiration} || 900; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{'no_client_expiration'} || 900
MC/DC0%0/1
delete $args{'no_client_expiration'} || 900
delete $args{'no_client_expiration'}
Truth table50%1/2
A
A= delete $args{'no_client_expiration'}
| |||||||||||||||||||||||||||||
| 266 | 2 | ▶ | my $message_expiration = delete $args{message_expiration} || 3600; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{'message_expiration'} || 3600
MC/DC0%0/1
delete $args{'message_expiration'} || 3600
delete $args{'message_expiration'}
Truth table50%1/2
A
A= delete $args{'message_expiration'}
| |||||||||||||||||||||||||||||
| 267 | 2 | ▶ | my $reload_message = delete $args{reload_message} || {result => 'RELOAD'}; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{'reload_message'} || {'result', 'RELOAD'}
MC/DC0%0/1
delete $args{'reload_message'} || {'result', 'RELOAD'}
delete $args{'reload_message'}
Truth table50%1/2
A
A= delete $args{'reload_message'}
| |||||||||||||||||||||||||||||
| 268 | $self = { | ||||||||||||||||||||||||||||
| 269 | 2 | ▶ | server => tcp_server($tcp_address, $tcp_port, sub {$self->on_accept(@_)}), | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 270 | no_client_expiration => $no_client_expiration, | ||||||||||||||||||||||||||||
| 271 | message_expiration => $message_expiration, | ||||||||||||||||||||||||||||
| 272 | reload_message => $reload_message, | ||||||||||||||||||||||||||||
| 273 | groups => {}, | ||||||||||||||||||||||||||||
| 274 | queues => {} | ||||||||||||||||||||||||||||
| 275 | }; | ||||||||||||||||||||||||||||
| 276 | 2 | bless $self, $class; | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 0 | ▶ | sub no_client_expiration { | ||||||||||||||||||||||||||
|
Subroutine
no_client_expiration: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 280 | 0 | $_[0]{no_client_expiration}; | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 0 | ▶ | sub message_expiration { | ||||||||||||||||||||||||||
|
Subroutine
message_expiration: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 284 | 0 | $_[0]{message_expiration}; | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 0 | ▶ | sub reload_message { | ||||||||||||||||||||||||||
|
Subroutine
reload_message: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 288 | 0 | $_[0]{reload_message}; | |||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 1 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=3 SCAR=13.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 294 | 1 | my ($slave, $tcp_address, $tcp_port, $no_client_expiration, $message_expiration, $reload_message) = @_; | |||||||||||||||||||||||||||
| 295 | 1 | ▶ | if ($reload_message) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | 0 | $reload_message = decode_cbor $reload_message; | |||||||||||||||||||||||||||
| 297 | 0 | ▶ | if (!%$reload_message) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 298 | 0 | $reload_message = undef; | |||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | 1 | my $queue_server = new PEF::Front::WebSocket::QueueServer( | |||||||||||||||||||||||||||
| 302 | address => $tcp_address, | ||||||||||||||||||||||||||||
| 303 | port => $tcp_port, | ||||||||||||||||||||||||||||
| 304 | no_client_expiration => $no_client_expiration, | ||||||||||||||||||||||||||||
| 305 | message_expiration => $message_expiration, | ||||||||||||||||||||||||||||
| 306 | reload_message => $reload_message | ||||||||||||||||||||||||||||
| 307 | ); | ||||||||||||||||||||||||||||
| 308 | my $handle = AnyEvent::Handle->new( | ||||||||||||||||||||||||||||
| 309 | 0 | ▶ | on_error => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 310 | 0 | exit; | |||||||||||||||||||||||||||
| 311 | }, | ||||||||||||||||||||||||||||
| 312 | 1 | ▶ | on_eof => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 313 | 1 | exit; | |||||||||||||||||||||||||||
| 314 | }, | ||||||||||||||||||||||||||||
| 315 | 0 | ▶ | on_read => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 316 | }, | ||||||||||||||||||||||||||||
| 317 | 1 | fh => $slave, | |||||||||||||||||||||||||||
| 318 | ); | ||||||||||||||||||||||||||||
| 319 | 1 | $handle->push_write("1"); | |||||||||||||||||||||||||||
| 320 | 1 | EV::run(); | |||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 2 | 1; | |||||||||||||||||||||||||||