blib/lib/IPC/Manager/Client/UnixSocket.pm

filter: Statementstmt 90.4% 66 / 73 Branchbran 50.0% 9 / 18 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 90.0% 18 / 20 Podpod 91.6% 11 / 12 totaltotal 80.9% 106 / 131 CC 13 SCAR 10.8
CC
13
Cov
80%
send_message
7.1
viable
6.0
fill_buffer
3.0
CRAP 2.9
↑ Summary
1 package IPC::Manager::Client::UnixSocket;
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  
5 2 our $VERSION = '0.000010';
6  
7 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use POSIX qw/mkfifo/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use IO::Socket::UNIX qw/SOCK_DGRAM/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use parent 'IPC::Manager::Base::FS::Handle';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 use Object::HashBase qw{
14 +buffer
15 +socket
16 +socket_cache
17 2 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 0 ▶sub viable { eval { require IO::Socket::UNIX; 1 } || 0 }
Subroutine viable: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require IO::Socket::UNIX; 1 } } or 0 0 0 0
20  
21 17 ▶sub check_path { -S $_[1] }
Subroutine check_path: called CC=1 SCAR=0.0
Pod documented
22 9 ▶sub path_type { 'UNIX Socket' }
Subroutine path_type: called CC=1 SCAR=0.0
Pod documented
23  
24 2 ▶sub have_handles_for_select { 1 }
Subroutine have_handles_for_select: called CC=1 SCAR=0.0
Pod documented
25 8 ▶sub handles_for_select { $_[0]->{+SOCKET} }
Subroutine handles_for_select: called CC=1 SCAR=0.0
Pod documented
26  
27 0 ▶sub suspend { croak "suspend is not supported by the UnixSocket driver" }
Subroutine suspend: not called CC=1 SCAR=6.9
Pod documented
28  
29 sub make_path {
30 9 ▶ my $self = shift;
Subroutine make_path: called CC=2 SCAR=7.0
Pod documented
31 9 my $path = $self->path;
32  
33 9 ▶ my $s = IO::Socket::UNIX->new(
Branch: 1 branch
BranchTrueFalseTotal
my $s = "IO::Socket::UNIX"->new("Type", 2, "Local", $path, "Blocking", 0) or die "Cannot create reader socket: $!" 0 9 9
34 Type => SOCK_DGRAM,
35 Local => $path,
36 Blocking => 0,
37 ) or die "Cannot create reader socket: $!";
38  
39 9 $self->{+SOCKET} = $s;
40 }
41  
42 sub pre_disconnect_hook {
43 8 ▶ my $self = shift;
Subroutine pre_disconnect_hook: called CC=2 SCAR=7.2
Pod documented
44 8 ▶ unlink($self->{+PATH}) or warn "Could not unlink socket: $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink $self->{"path"} or warn "Could not unlink socket: $!" 0 8 8
45 }
46  
47 sub init {
48 9 ▶ my $self = shift;
Subroutine init: called CC=2 SCAR=7.1
Pod undocumented
49  
50 9 ▶ $self->{+BUFFER} //= [];
Condition50%1/2
$self->{"buffer"} //= []
l!l
09
MC/DC0%0/1
$self->{"buffer"} //= []
$self->{"buffer"}
Truth table50%1/2
A
A= $self->{"buffer"}
Aresult
11
00
51  
52 9 $self->SUPER::init();
53 }
54  
55 sub fill_buffer {
56 2 ▶ my $self = shift;
Subroutine fill_buffer: called CC=3 SCAR=11.0
Pod documented
57  
58 2 my $s = $self->{+SOCKET};
59 2 ▶ while (my $msg = <$s>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $msg = readline $s)) 2 2 4
60 2 push @{$self->{+BUFFER}} => $msg;
61 }
62  
63 2 ▶ return @{$self->{+BUFFER}} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{'buffer'};} ? : 2 0 2
64 }
65  
66 sub get_messages {
67 11 ▶ my $self = shift;
Subroutine get_messages: called CC=2 SCAR=7.1
Pod documented
68  
69 11 my @out;
70  
71 11 push @out => $self->read_resume_file;
72  
73 11 my $s = $self->{+SOCKET};
74 11 push @{$self->{+BUFFER}} => <$s>;
75 11 for my $msg (@{$self->{+BUFFER}}) {
76 7 $msg = IPC::Manager::Message->new($self->{+SERIALIZER}->deserialize($msg));
77 0 push @out => $msg;
78 0 $self->{+STATS}->{read}->{$msg->{from}}++;
79 }
80  
81 4 @{$self->{+BUFFER}} = ();
82  
83 4 return sort { $a->stamp <=> $b->stamp } @out;
84 }
85  
86 sub send_message {
87 5 ▶ my $self = shift;
Subroutine send_message: called CC=6 SCAR=19.6
Pod documented
88 5 my $msg = $self->build_message(@_);
89  
90 5 ▶ my $peer_id = $msg->to or croak "No peer specified";
Branch: 1 branch
BranchTrueFalseTotal
my $peer_id = $msg->to or croak("No peer specified") 0 5 5
91  
92 5 $self->pid_check;
93 5 ▶ my $sock = $self->peer_exists($peer_id) or die "'$peer_id' is not a valid message recipient";
Branch: 1 branch
BranchTrueFalseTotal
my $sock = $self->peer_exists($peer_id) or die "'${peer_id}' is not a valid message recipient" 0 5 5
94  
95 5 ▶ my $s = $self->{+SOCKET_CACHE}->{$sock} //= IO::Socket::UNIX->new(
Branch: 1 branch
BranchTrueFalseTotal
my $s = ($self->{"socket_cache"}{$sock} //= "IO::Socket::UNIX"->new("Type", 2, "Peer", $sock)) or die "Cannot connect to socket: $!" 0 5 5
Condition33%1/3
$self->{"socket_cache"}{$sock} //= "IO::Socket::UNIX"->new("Type", 2, "Peer", $sock)
l!l&&r!l&&!r
050
MC/DC0%0/2
$self->{"socket_cache"}{$sock} //= "IO::Socket::UNIX"->new("Type", 2, "Peer", $sock)
$self->{"socket_cache"}{$sock} "IO::Socket::UNIX"->new("Type", 2, "Peer", $sock)
Truth table33%1/3
A //= B
A= $self->{"socket_cache"}{$sock}B= "IO::Socket::UNIX"->new("Type", 2, "Peer", $sock)
ABresult
1X1
011
000
96 Type => SOCK_DGRAM,
97 Peer => $sock,
98 ) or die "Cannot connect to socket: $!";
99  
100 5 ▶ $s->send($self->{+SERIALIZER}->serialize($msg) . "\n") or die "Cannot send message: $!";
Branch: 1 branch
BranchTrueFalseTotal
$s->send($self->{"serializer"}->serialize($msg) . "\n") or die "Cannot send message: $!" 0 5 5
101  
102 5 $self->{+STATS}->{sent}->{$msg->{to}}++;
103 }
104  
105 2 1;
106  
107 __END__
↑ Summary