| 1 | package PLS::Server; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Future::Queue; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use Future::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use IO::Async::Loop; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use IO::Async::Signal; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use IO::Async::Stream; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 9 | ▶ | use IO::Async::Timer::Periodic; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use PLS::JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 9 | ▶ | use PLS::Server::Request::Factory; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 9 | ▶ | use PLS::Server::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 9 | ▶ | use PLS::Server::Response::Cancelled; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 NAME | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | PLS::Server | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | Perl Language Server | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | This server communicates to a language client through STDIN/STDOUT. | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | my $server = PLS::Server->new(); | ||||||||||||||||||||||||||||
| 34 | my $exit_code = $server->run(); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | exit $exit_code; | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =cut | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub new | ||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||
| 42 | 7 | ▶ | my ($class) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | return | ||||||||||||||||||||||||||||
| 45 | 7 | bless { | |||||||||||||||||||||||||||
| 46 | loop => IO::Async::Loop->new(), | ||||||||||||||||||||||||||||
| 47 | stream => undef, | ||||||||||||||||||||||||||||
| 48 | running_futures => {}, | ||||||||||||||||||||||||||||
| 49 | pending_requests => {} | ||||||||||||||||||||||||||||
| 50 | }, $class; | ||||||||||||||||||||||||||||
| 51 | } ## end sub new | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub run | ||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||
| 55 | 7 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 7 | $self->{client_requests} = Future::Queue->new(); | |||||||||||||||||||||||||||
| 58 | 7 | $self->{client_responses} = Future::Queue->new(); | |||||||||||||||||||||||||||
| 59 | 7 | $self->{server_requests} = Future::Queue->new(); | |||||||||||||||||||||||||||
| 60 | 7 | $self->{server_responses} = Future::Queue->new(); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Future::Utils::repeat | ||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||
| 64 | $self->{client_requests}->shift->on_done( | ||||||||||||||||||||||||||||
| 65 | sub { | ||||||||||||||||||||||||||||
| 66 | 10 | ▶ | my ($request) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 10 | $self->handle_client_request($request); | |||||||||||||||||||||||||||
| 69 | 10 | return; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 17 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 72 | } ## end Future::Utils::repeat | ||||||||||||||||||||||||||||
| 73 | 7 | ▶ | while => sub { 1 }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Future::Utils::repeat | ||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | $self->{client_responses}->shift->on_done( | ||||||||||||||||||||||||||||
| 78 | sub { | ||||||||||||||||||||||||||||
| 79 | 3 | ▶ | my ($response) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 3 | $self->handle_client_response($response); | |||||||||||||||||||||||||||
| 82 | 3 | return; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 10 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 85 | } ## end Future::Utils::repeat | ||||||||||||||||||||||||||||
| 86 | 7 | ▶ | while => sub { 1 }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Future::Utils::repeat | ||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||
| 90 | $self->{server_requests}->shift->on_done( | ||||||||||||||||||||||||||||
| 91 | sub { | ||||||||||||||||||||||||||||
| 92 | 25 | ▶ | my ($request) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 93 | 25 | $self->handle_server_request($request); | |||||||||||||||||||||||||||
| 94 | 25 | return; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 32 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 97 | } ## end Future::Utils::repeat | ||||||||||||||||||||||||||||
| 98 | 7 | ▶ | while => sub { 1 }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | Future::Utils::repeat | ||||||||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||||||||
| 102 | $self->{server_responses}->shift->on_done( | ||||||||||||||||||||||||||||
| 103 | sub { | ||||||||||||||||||||||||||||
| 104 | 6 | ▶ | my ($response) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 105 | 6 | $self->handle_server_response($response); | |||||||||||||||||||||||||||
| 106 | 6 | return; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 13 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 109 | } ## end Future::Utils::repeat | ||||||||||||||||||||||||||||
| 110 | 7 | ▶ | while => sub { 1 }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | $self->{stream} = IO::Async::Stream->new_for_stdio( | ||||||||||||||||||||||||||||
| 113 | autoflush => 0, | ||||||||||||||||||||||||||||
| 114 | on_read => sub { | ||||||||||||||||||||||||||||
| 115 | 7 | ▶ | my $size = 0; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | return sub { | ||||||||||||||||||||||||||||
| 118 | 15 | ▶ | my ($stream, $buffref, $eof) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 15 | ▶ | exit if $eof; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 15 | ▶ | unless ($size) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||
| 124 | 15 | ▶ | return 0 unless ($$buffref =~ s/^(.*?)\r\n\r\n//s); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 15 | my $headers = $1; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 15 | my %headers = map { split /: / } grep { length } split /\r\n/, $headers; | |||||||||||||||||||||||||||
| 128 | 15 | $size = $headers{'Content-Length'}; | |||||||||||||||||||||||||||
| 129 | 15 | ▶ | die 'no Content-Length header provided' unless $size; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | } ## end unless ($size) | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 14 | ▶ | return 0 if (length($$buffref) < $size); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 14 | my $json = substr $$buffref, 0, $size, ''; | |||||||||||||||||||||||||||
| 135 | 14 | $size = 0; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 14 | my $content = decode_json $json; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 14 | $self->handle_client_message($content); | |||||||||||||||||||||||||||
| 140 | 14 | return 1; | |||||||||||||||||||||||||||
| 141 | 7 | }; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | 7 | ); | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 7 | $self->{loop}->add($self->{stream}); | |||||||||||||||||||||||||||
| 146 | $self->{loop}->add( | ||||||||||||||||||||||||||||
| 147 | IO::Async::Signal->new(name => 'TERM', | ||||||||||||||||||||||||||||
| 148 | 2 | ▶ | on_receipt => sub { $self->stop(0) }) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 149 | 7 | ▶ | ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | if ($^O ne 'MSWin32'); | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 7 | my $exit_code = $self->{loop}->run(); | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 6 | ▶ | return (length $exit_code) ? $exit_code : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | } ## end sub run | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | sub handle_client_message | ||||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||
| 159 | 14 | ▶ | my ($self, $message) = @_; | ||||||||||||||||||||||||||
|
Subroutine
handle_client_message: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 14 | ▶ | if (length $message->{method}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||
| 163 | 11 | $message = PLS::Server::Request::Factory->new($message); | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 11 | ▶ | if (blessed($message) and $message->isa('PLS::Server::Response')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($message) and $message->isa("PLS::Server::Response")
MC/DC50%1/2
builtin::blessed($message) and $message->isa("PLS::Server::Response")
builtin::blessed($message)
$message->isa("PLS::Server::Response")
Truth table66%2/3
A and B
A= builtin::blessed($message)B= $message->isa("PLS::Server::Response")
| |||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||
| 167 | 1 | $self->{server_responses}->push($message); | |||||||||||||||||||||||||||
| 168 | 1 | return; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | } ## end if (length $message->{...}) | ||||||||||||||||||||||||||||
| 171 | else | ||||||||||||||||||||||||||||
| 172 | { | ||||||||||||||||||||||||||||
| 173 | 3 | $message = PLS::Server::Response->new($message); | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 13 | ▶ | return unless blessed($message); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 13 | ▶ | if ($message->isa('PLS::Server::Request')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | { | ||||||||||||||||||||||||||||
| 180 | 10 | $self->{client_requests}->push($message); | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | 13 | ▶ | if ($message->isa('PLS::Server::Response')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | { | ||||||||||||||||||||||||||||
| 184 | 3 | $self->{client_responses}->push($message); | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 13 | return; | |||||||||||||||||||||||||||
| 188 | } ## end sub handle_client_message | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | sub send_server_request | ||||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||
| 192 | 25 | ▶ | my ($self, $request) = @_; | ||||||||||||||||||||||||||
|
Subroutine
send_server_request: called CC=4 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 25 | ▶ | return unless blessed($request); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 25 | ▶ | if ($request->isa('PLS::Server::Request')) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||
| 198 | 25 | $self->{server_requests}->push($request); | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | elsif ($request->isa('Future')) | ||||||||||||||||||||||||||||
| 201 | { | ||||||||||||||||||||||||||||
| 202 | $request->on_done( | ||||||||||||||||||||||||||||
| 203 | sub { | ||||||||||||||||||||||||||||
| 204 | 0 | ▶ | my ($request) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | $self->{server_requests}->push($request); | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | 0 | )->retain(); | |||||||||||||||||||||||||||
| 209 | } ## end elsif ($request->isa('Future'...)) | ||||||||||||||||||||||||||||
| 210 | 25 | return; | |||||||||||||||||||||||||||
| 211 | } ## end sub send_server_request | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | sub send_message | ||||||||||||||||||||||||||||
| 214 | { | ||||||||||||||||||||||||||||
| 215 | 31 | ▶ | my ($self, $message) = @_; | ||||||||||||||||||||||||||
|
Subroutine
send_message: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 31 | ▶ | return if (not blessed($message) or not $message->isa('PLS::Server::Message')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($message) and $message->isa("PLS::Server::Message")
MC/DC0%0/2
builtin::blessed($message) and $message->isa("PLS::Server::Message")
builtin::blessed($message)
$message->isa("PLS::Server::Message")
Truth table33%1/3
A and B
A= builtin::blessed($message)B= $message->isa("PLS::Server::Message")
| |||||||||||||||||||||||||||||
| 218 | 31 | my $json = $message->serialize(); | |||||||||||||||||||||||||||
| 219 | 31 | my $length = length $$json; | |||||||||||||||||||||||||||
| 220 | 31 | $self->{stream}->write("Content-Length: $length\r\n\r\n$$json")->retain(); | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 31 | return; | |||||||||||||||||||||||||||
| 223 | } ## end sub send_message | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | sub handle_client_request | ||||||||||||||||||||||||||||
| 226 | { | ||||||||||||||||||||||||||||
| 227 | 10 | ▶ | my ($self, $request) = @_; | ||||||||||||||||||||||||||
|
Subroutine
handle_client_request: called CC=5 SCAR=21.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 10 | my $response = $request->service($self); | |||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 10 | ▶ | if (blessed($response)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | { | ||||||||||||||||||||||||||||
| 233 | 5 | ▶ | if ($response->isa('PLS::Server::Response')) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 234 | { | ||||||||||||||||||||||||||||
| 235 | 5 | $self->{server_responses}->push($response); | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | elsif ($response->isa('Future')) | ||||||||||||||||||||||||||||
| 238 | { | ||||||||||||||||||||||||||||
| 239 | 0 | ▶ | $self->{running_futures}{$request->{id}} = $response if (length $request->{id}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | $response->on_done( | ||||||||||||||||||||||||||||
| 242 | sub { | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | my ($response) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 244 | 0 | $self->{server_responses}->push($response); | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | )->on_cancel( | ||||||||||||||||||||||||||||
| 247 | sub { | ||||||||||||||||||||||||||||
| 248 | 0 | ▶ | $self->{server_responses}->push(PLS::Server::Response::Cancelled->new(id => $request->{id})); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | 0 | ); | |||||||||||||||||||||||||||
| 251 | } ## end elsif ($response->isa('Future'...)) | ||||||||||||||||||||||||||||
| 252 | } ## end if (blessed($response)...) | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 10 | return; | |||||||||||||||||||||||||||
| 255 | } ## end sub handle_client_request | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | sub handle_client_response | ||||||||||||||||||||||||||||
| 258 | { | ||||||||||||||||||||||||||||
| 259 | 3 | ▶ | my ($self, $response) = @_; | ||||||||||||||||||||||||||
|
Subroutine
handle_client_response: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 3 | my $request = $self->{pending_requests}{$response->{id}}; | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 3 | ▶ | if (blessed($request) and $request->isa('PLS::Server::Request')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($request) and $request->isa("PLS::Server::Request")
MC/DC0%0/2
builtin::blessed($request) and $request->isa("PLS::Server::Request")
builtin::blessed($request)
$request->isa("PLS::Server::Request")
Truth table33%1/3
A and B
A= builtin::blessed($request)B= $request->isa("PLS::Server::Request")
| |||||||||||||||||||||||||||||
| 264 | { | ||||||||||||||||||||||||||||
| 265 | 3 | $request->handle_response($response, $self); | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 3 | return; | |||||||||||||||||||||||||||
| 269 | } ## end sub handle_client_response | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | sub handle_server_request | ||||||||||||||||||||||||||||
| 272 | { | ||||||||||||||||||||||||||||
| 273 | 25 | ▶ | my ($self, $request) = @_; | ||||||||||||||||||||||||||
|
Subroutine
handle_server_request: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | 25 | ▶ | if ($request->{notification}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | { | ||||||||||||||||||||||||||||
| 277 | 10 | delete $request->{notification}; | |||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | else | ||||||||||||||||||||||||||||
| 280 | { | ||||||||||||||||||||||||||||
| 281 | 15 | $request->{id} = ++$self->{last_request_id}; | |||||||||||||||||||||||||||
| 282 | 15 | $self->{pending_requests}{$request->{id}} = $request; | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 25 | ▶ | delete $self->{running_futures}{$request->{id}} if (length $request->{id}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | 25 | $self->send_message($request); | |||||||||||||||||||||||||||
| 287 | 25 | return; | |||||||||||||||||||||||||||
| 288 | } ## end sub handle_server_request | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | sub handle_server_response | ||||||||||||||||||||||||||||
| 291 | { | ||||||||||||||||||||||||||||
| 292 | 6 | ▶ | my ($self, $response) = @_; | ||||||||||||||||||||||||||
|
Subroutine
handle_server_response: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 6 | $self->send_message($response); | |||||||||||||||||||||||||||
| 295 | 6 | return; | |||||||||||||||||||||||||||
| 296 | } ## end sub handle_server_response | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | sub monitor_client_process | ||||||||||||||||||||||||||||
| 299 | { | ||||||||||||||||||||||||||||
| 300 | 5 | ▶ | my ($self, $pid) = @_; | ||||||||||||||||||||||||||
|
Subroutine
monitor_client_process: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | my $timer = IO::Async::Timer::Periodic->new( | ||||||||||||||||||||||||||||
| 303 | interval => 30, | ||||||||||||||||||||||||||||
| 304 | on_tick => sub { | ||||||||||||||||||||||||||||
| 305 | 4 | ▶ | return if (kill 'ZERO', $pid); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | 4 | $self->stop(1); | |||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | 5 | ); | |||||||||||||||||||||||||||
| 309 | 5 | $self->{loop}->add($timer); | |||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 5 | $timer->start(); | |||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 5 | return; | |||||||||||||||||||||||||||
| 314 | } ## end sub monitor_client_process | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | sub stop | ||||||||||||||||||||||||||||
| 317 | { | ||||||||||||||||||||||||||||
| 318 | 6 | ▶ | my ($self, $exit_code) = @_; | ||||||||||||||||||||||||||
|
Subroutine
stop: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 6 | $self->{loop}->stop($exit_code); | |||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 6 | return; | |||||||||||||||||||||||||||
| 323 | } ## end sub stop | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 9 | 1; | |||||||||||||||||||||||||||