| 1 | package IPC::Manager::Role::Client::Connection; | ||||||||||||
| 2 | 88 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 88 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 88 | our $VERSION = '0.000035'; | |||||||||||
| 6 | |||||||||||||
| 7 | 88 | ▶ | use Time::HiRes qw/time/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 88 | ▶ | use Role::Tiny; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 88 | requires qw{ | |||||||||||
| 12 | _connections | ||||||||||||
| 13 | _close_connection | ||||||||||||
| 14 | }; | ||||||||||||
| 15 | |||||||||||||
| 16 | sub has_connection { | ||||||||||||
| 17 | 17 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
has_connection: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 18 | 17 | my ($peer) = @_; | |||||||||||
| 19 | 17 | ▶ | return exists $self->_connections->{$peer} ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 20 | } | ||||||||||||
| 21 | |||||||||||||
| 22 | sub connections { | ||||||||||||
| 23 | 4 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
connections: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 24 | 4 | return sort keys %{$self->_connections}; | |||||||||||
| 25 | } | ||||||||||||
| 26 | |||||||||||||
| 27 | sub disconnect_connection { | ||||||||||||
| 28 | 3 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
disconnect_connection: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 29 | 3 | my ($peer) = @_; | |||||||||||
| 30 | 3 | my $cons = $self->_connections; | |||||||||||
| 31 | 3 | ▶ | return 0 unless exists $cons->{$peer}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | 2 | $self->_close_connection($peer); | |||||||||||
| 33 | 2 | return 1; | |||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | sub last_activity { | ||||||||||||
| 37 | 4 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
last_activity: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 38 | 4 | my ($peer) = @_; | |||||||||||
| 39 | 4 | ▶ | my $entry = $self->_connections->{$peer} or return undef; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | 3 | return $entry->{last_active}; | |||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | sub close_idle_connections { | ||||||||||||
| 44 | 3 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
close_idle_connections: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 45 | 3 | my ($max_idle) = @_; | |||||||||||
| 46 | |||||||||||||
| 47 | 3 | my $cutoff = time - $max_idle; | |||||||||||
| 48 | 3 | my $cons = $self->_connections; | |||||||||||
| 49 | |||||||||||||
| 50 | 3 | my $closed = 0; | |||||||||||
| 51 | 3 | for my $peer (keys %$cons) { | |||||||||||
| 52 | 4 | ▶ | my $la = $cons->{$peer}->{last_active} // next; | ||||||||||
|
Condition50%1/2
$cons->{$peer}{"last_active"} // (next)
MC/DC0%0/1
$cons->{$peer}{"last_active"} // (next)
$cons->{$peer}{"last_active"}
Truth table50%1/2
A
A= $cons->{$peer}{"last_active"}
| |||||||||||||
| 53 | 4 | ▶ | next if $la >= $cutoff; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 54 | 2 | $self->_close_connection($peer); | |||||||||||
| 55 | 2 | $closed++; | |||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | 3 | return $closed; | |||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | 88 | 1; | |||||||||||
| 62 | |||||||||||||
| 63 | __END__ | ||||||||||||