blib/lib/IPC/Manager/Role/Client/Connection.pm

filter: Statementstmt 100% 42 / 42 Branchbran 100% 8 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 97.0% 65 / 67 CC 7 SCAR 7.9
CC
7
Cov
98%
close_idle_connections
4.0
has_connection
2.0
disconnect_connection
2.0
CRAP 2.2
« blib/lib/IPC/Manager/Client/LocalMemory.pm ↑ Summary blib/lib/IPC/Manager/Service/Peer.pm »
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.000036';
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
BranchTrueFalseTotal
exists $self->_connections->{$peer} ? : 9 8 17
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
BranchTrueFalseTotal
unless exists $cons->{$peer} 1 2 3
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
BranchTrueFalseTotal
my $entry = $self->_connections->{$peer} or return undef 1 3 4
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)
l!l
40
MC/DC0%0/1
$cons->{$peer}{"last_active"} // (next)
$cons->{$peer}{"last_active"}
Truth table50%1/2
A
A= $cons->{$peer}{"last_active"}
Aresult
11
00
53 4 ▶ next if $la >= $cutoff;
Branch: 1 branch
BranchTrueFalseTotal
if $la >= $cutoff 2 2 4
54 2 $self->_close_connection($peer);
55 2 $closed++;
56 }
57  
58 3 return $closed;
59 }
60  
61 88 1;
62  
63 __END__
« blib/lib/IPC/Manager/Client/LocalMemory.pm ↑ Summary blib/lib/IPC/Manager/Service/Peer.pm »