t/Communicate.pm

filter: Statementstmt 23.8% 16 / 67 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 41.6% 5 / 12 Podpod 0.0% 0 / 7 totaltotal 22.8% 21 / 92 CC 4 SCAR 11.8
CC
4
Cov
22%
new
6.0
send_message
6.0
recv_message
6.0
CRAP 3.3
« blib/lib/PLS/Server.pm ↑ Summary blib/lib/PLS/Server/Method/CompletionItem.pm »
1 package t::Communicate;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use JSON::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use PLS::Server;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub new
12 0 ▶{
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
13 0 my ($class) = @_;
14  
15 0 pipe my $client_read_fh, my $server_write_fh;
16 0 pipe my $server_read_fh, my $client_write_fh;
17 0 pipe my $client_err_fh, my $server_err_fh;
18  
19 0 $client_read_fh->autoflush();
20 0 $client_write_fh->autoflush();
21 0 $server_read_fh->autoflush();
22 0 $server_write_fh->autoflush();
23  
24 0 my $pid = fork;
25  
26 0 ▶ if ($pid)
Branch: 1 branch
BranchTrueFalseTotal
if ($pid) { } 0 0 0
27 {
28 0 close $server_read_fh;
29 0 close $server_write_fh;
30  
31 0 my $self = {
32 pid => $pid,
33 read_fh => $client_read_fh,
34 write_fh => $client_write_fh,
35 err_fh => $client_err_fh
36 };
37  
38 0 return bless $self, $class;
39 } ## end if ($pid)
40 else
41 {
42 0 close $client_read_fh;
43 0 close $client_write_fh;
44 0 close $client_err_fh;
45  
46 0 open STDOUT, '>&', $server_write_fh;
47 0 open STDIN, '>&', $server_read_fh;
48  
49 0 open STDERR, '>&', $server_err_fh;
50 0 my $server = PLS::Server->new();
51 0 exit $server->run();
52 } ## end else [ if ($pid) ]
53  
54 0 return;
55 } ## end sub new
56  
57 sub send_message
58 0 ▶{
Subroutine send_message: not called CC=2 SCAR=17.9
Pod undocumented
59 0 my ($self, $message) = @_;
60  
61 0 ▶ $message = JSON::PP->new->utf8->encode($message) if (ref $message);
Branch: 1 branch
BranchTrueFalseTotal
if ref $message 0 0 0
62 0 my $length = length $message;
63 0 $self->send_raw_message("Content-Length: $length\r\n\r\n$message");
64  
65 0 return;
66 } ## end sub send_message
67  
68 sub recv_message
69 0 ▶{
Subroutine recv_message: not called CC=2 SCAR=17.9
Pod undocumented
70 0 my ($self) = @_;
71  
72 0 local $/ = "\r\n";
73 0 my $response = readline $self->{read_fh};
74 0 ▶ return unless (length $response);
Branch: 1 branch
BranchTrueFalseTotal
unless length $response 0 0 0
75 0 readline $self->{read_fh}; # blank line
76 0 my ($content_length) = $response =~ /Content-Length: (\d+)/;
77 0 my $json;
78 0 read $self->{read_fh}, $json, $content_length;
79  
80 0 return eval { JSON::PP->new->utf8->decode($json) };
81 } ## end sub recv_message
82  
83 sub send_message_and_recv_response
84 0 ▶{
Subroutine send_message_and_recv_response: not called CC=1 SCAR=6.9
Pod undocumented
85 0 my ($self, $message) = @_;
86  
87 0 $self->send_message($message);
88 0 return $self->recv_message();
89 } ## end sub send_message_and_recv_response
90  
91 sub send_raw_message
92 0 ▶{
Subroutine send_raw_message: not called CC=1 SCAR=6.9
Pod undocumented
93 0 my ($self, $message) = @_;
94  
95 0 print {$self->{write_fh}} $message;
96  
97 0 return;
98 } ## end sub send_raw_message
99  
100 sub recv_err
101 0 ▶{
Subroutine recv_err: not called CC=1 SCAR=6.9
Pod undocumented
102 0 my ($self) = @_;
103  
104 0 return readline $self->{err_fh};
105 }
106  
107 sub stop_server
108 0 ▶{
Subroutine stop_server: not called CC=1 SCAR=6.9
Pod undocumented
109 0 my ($self) = @_;
110  
111 0 kill 'TERM', $self->{pid};
112 0 waitpid $self->{pid}, 0;
113  
114 0 return;
115 } ## end sub stop_server
116  
117 2 1;
« blib/lib/PLS/Server.pm ↑ Summary blib/lib/PLS/Server/Method/CompletionItem.pm »