| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||
| 2 | package YATT::Lite::LanguageServer::Generic; | ||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use File::AddInc; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use MOP4Import::Base::CLI_JSON -as_base | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | , [fields => | ||||||||||||||||||||||||||||
| 8 | , qw/_buffer _out_semaphore _log_fh/ | ||||||||||||||||||||||||||||
| 9 | , [read_fd => default => 0] | ||||||||||||||||||||||||||||
| 10 | , [write_fd => default => 1] | ||||||||||||||||||||||||||||
| 11 | , [read_length => default => 8192] | ||||||||||||||||||||||||||||
| 12 | , [jsonrpc_version => default => '2.0'] | ||||||||||||||||||||||||||||
| 13 | , [dump_request => default => 0] | ||||||||||||||||||||||||||||
| 14 | , [logfile => doc => "append protocol trace to this file (default: \$YATT_LANGSERVER_LOG). Works even with --quiet"] | ||||||||||||||||||||||||||||
| 15 | , qw/_is_shutting_down/ | ||||||||||||||||||||||||||||
| 16 | 2 | ]; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | use MOP4Import::Types | ||||||||||||||||||||||||||||
| 21 | 2 | ▶ | (Header => [[fields => qw/Content-Length/]]); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | use YATT::Lite::LanguageServer::Protocol | ||||||||||||||||||||||||||||
| 24 | 2 | ▶ | qw/Message Request Response Notification Error/, qr/^ErrorCodes__/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # Most logics are shamelessly stolen from Perl::LanguageServer | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use Coro ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use Coro::AIO ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use AnyEvent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 2 | ▶ | use Scope::Guard qw/guard/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 2 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 2 | ▶ | use Errno qw(EINTR); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | #======================================== | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub cli_encode_json { | ||||||||||||||||||||||||||
|
Subroutine
cli_encode_json: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 0 | (my MY $self, my $obj) = @_; | |||||||||||||||||||||||||||
| 45 | 0 | my ($encoded, $err); | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 47 | 0 | $encoded = $self->SUPER::cli_encode_json($obj); | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 49 | 0 | $err = $_; | |||||||||||||||||||||||||||
| 50 | 0 | }; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | unless (defined $encoded) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | Carp::croak (($err // 'json encode error') | ||||||||||||||||||||||||||
|
Condition0%0/2
$err // "json encode error"
MC/DC0%0/1
$err // "json encode error"
$err
Truth table0%0/2
A
A= $err
| |||||||||||||||||||||||||||||
| 54 | .": ".MOP4Import::Util::terse_dump($obj)); | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | $encoded; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub after_configure_default { | ||||||||||||||||||||||||||
|
Subroutine
after_configure_default: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 0 | (my MY $self) = @_; | |||||||||||||||||||||||||||
| 62 | 0 | $self->{_out_semaphore} = Coro::Semaphore->new; | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | $self->{logfile} //= $ENV{YATT_LANGSERVER_LOG}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"logfile"} //= $ENV{"YATT_LANGSERVER_LOG"}
MC/DC0%0/2
$self->{"logfile"} //= $ENV{"YATT_LANGSERVER_LOG"}
$self->{"logfile"}
$ENV{"YATT_LANGSERVER_LOG"}
Truth table0%0/3
A //= B
A= $self->{"logfile"}B= $ENV{"YATT_LANGSERVER_LOG"}
| |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if (defined $self->{logfile} and $self->{logfile} ne '') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"logfile"} and $self->{"logfile"} ne ""
MC/DC0%0/2
defined $self->{"logfile"} and $self->{"logfile"} ne ""
defined $self->{"logfile"}
$self->{"logfile"} ne ""
Truth table0%0/3
A and B
A= defined $self->{"logfile"}B= $self->{"logfile"} ne ""
| |||||||||||||||||||||||||||||
| 65 | open $self->{_log_fh}, '>>', $self->{logfile} | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | or die "Can't open logfile $self->{logfile}: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | $self->{_log_fh}->autoflush(1); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | #======================================== | ||||||||||||||||||||||||||||
| 72 | # Logging. | ||||||||||||||||||||||||||||
| 73 | # | ||||||||||||||||||||||||||||
| 74 | # Goes to STDERR unless --quiet, and to --logfile (or $YATT_LANGSERVER_LOG) | ||||||||||||||||||||||||||||
| 75 | # regardless of --quiet. Arguments may be CODE refs, which are only | ||||||||||||||||||||||||||||
| 76 | # evaluated when something is actually logged (JSON encoding of a whole | ||||||||||||||||||||||||||||
| 77 | # didOpen/didChange is not free). | ||||||||||||||||||||||||||||
| 78 | # | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub is_logging { | ||||||||||||||||||||||||||
|
Subroutine
is_logging: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 0 | (my MY $self) = @_; | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | $self->{_log_fh} || !$self->{quiet}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub logmsg { | ||||||||||||||||||||||||||
|
Subroutine
logmsg: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 0 | (my MY $self, my @msg) = @_; | |||||||||||||||||||||||||||
| 86 | 0 | ▶ | return unless $self->is_logging; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | my $line = sprintf("# %.3f ", Time::HiRes::time()) | ||||||||||||||||||||||||||||
| 88 | 0 | ▶ | . join("", map {ref $_ eq 'CODE' ? $_->() : $_} @msg) . "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | print {$self->{_log_fh}} $line if $self->{_log_fh}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | print STDERR $line unless $self->{quiet}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub json_for_log { | ||||||||||||||||||||||||||
|
Subroutine
json_for_log: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 94 | 0 | (my MY $self, my ($obj, $limit)) = @_; | |||||||||||||||||||||||||||
| 95 | 0 | my $str = eval { $self->cli_encode_json($obj) }; | |||||||||||||||||||||||||||
| 96 | 0 | ▶ | $str = "(unencodable: $@)" unless defined $str; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | $self->truncate_for_log($str, $limit); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub truncate_for_log { | ||||||||||||||||||||||||||
|
Subroutine
truncate_for_log: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 101 | 0 | (my MY $self, my ($str, $limit)) = @_; | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ($limit and length($str) > $limit) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$limit and length $str > $limit
MC/DC0%0/2
$limit and length $str > $limit
$limit
length $str > $limit
Truth table0%0/3
A and B
A= $limitB= length $str > $limit
| |||||||||||||||||||||||||||||
| 103 | 0 | substr($str, 0, $limit) . "...(" . length($str) . " bytes)"; | |||||||||||||||||||||||||||
| 104 | } else { | ||||||||||||||||||||||||||||
| 105 | 0 | $str; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | #======================================== | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub call_method { | ||||||||||||||||||||||||||
|
Subroutine
call_method: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 112 | 0 | (my MY $self, my Request $request) = @_; | |||||||||||||||||||||||||||
| 113 | 0 | my $method = $self->translate_method_name($request->{method}); | |||||||||||||||||||||||||||
| 114 | 0 | ▶ | if (my $sub = $self->can($method)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | my $params = $request->{params}; | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | $self->logmsg("call_method: $method '", sub {$self->json_for_log($params, 200)}, "'"); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 117 | 0 | $sub->($self, $params); | |||||||||||||||||||||||||||
| 118 | } else { | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $self->logmsg("Not implemented: ", sub {$self->json_for_log($request, 200)}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 120 | 0 | undef; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub translate_method_name { | ||||||||||||||||||||||||||
|
Subroutine
translate_method_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 125 | 0 | (my MY $self, my $method) = @_; | |||||||||||||||||||||||||||
| 126 | 0 | $method =~ s,/,__,g; | |||||||||||||||||||||||||||
| 127 | 0 | $method =~ s,^\$,__ext,; | |||||||||||||||||||||||||||
| 128 | 0 | 'lspcall__'.$method; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub cmd_server { | ||||||||||||||||||||||||||
|
Subroutine
cmd_server: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 132 | 0 | (my MY $self, my @args) = @_; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | autoflush STDERR 1; | |||||||||||||||||||||||||||
| 135 | # A client which went away turns into a write error (handled) instead of | ||||||||||||||||||||||||||||
| 136 | # SIGPIPE killing the server in the middle of a response. | ||||||||||||||||||||||||||||
| 137 | 0 | local $SIG{PIPE} = 'IGNORE'; | |||||||||||||||||||||||||||
| 138 | 0 | $self->logmsg("server started"); | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | my $cv = AnyEvent::CondVar->new; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | async { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 143 | 0 | $self->mainloop(@args); | |||||||||||||||||||||||||||
| 144 | 0 | $cv->send; | |||||||||||||||||||||||||||
| 145 | 0 | }; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | $cv->recv; | |||||||||||||||||||||||||||
| 148 | 0 | $self->logmsg("server finished"); | |||||||||||||||||||||||||||
| 149 | 0 | ""; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub mainloop { | ||||||||||||||||||||||||||
|
Subroutine
mainloop: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 153 | 0 | (my MY $self) = @_; | |||||||||||||||||||||||||||
| 154 | 0 | my (%request, %notification); # XXX: should this be an instance member? | |||||||||||||||||||||||||||
| 155 | 0 | my $notificationNo; | |||||||||||||||||||||||||||
| 156 | 0 | while (1) { | |||||||||||||||||||||||||||
| 157 | 0 | my $reqRaw = $self->read_raw_request; | |||||||||||||||||||||||||||
| 158 | 0 | ▶ | unless (defined $reqRaw) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | $self->logmsg("input closed, leaving mainloop"); | |||||||||||||||||||||||||||
| 160 | 0 | return; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | 0 | my Request $request = eval { decode_json($reqRaw) }; | |||||||||||||||||||||||||||
| 163 | 0 | ▶ | unless (ref $request eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | # A broken frame must not kill the reader (which would leave the | ||||||||||||||||||||||||||||
| 165 | # server deaf forever). Report and continue with the next frame. | ||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my $err = $@ || "not a JSON object"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'not a JSON object'
MC/DC0%0/1
$@ || 'not a JSON object'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||
| 167 | 0 | $self->logmsg("json parse error, frame dropped: $err"); | |||||||||||||||||||||||||||
| 168 | 0 | $self->emit_error_response(undef, ErrorCodes__ParseError, "Parse error: $err"); | |||||||||||||||||||||||||||
| 169 | 0 | next; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if (defined (my $id = $request->{id})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | $self->logmsg("processing request: ", sub {$self->json_for_log($request, 500)}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 173 | 0 | ▶ | $request{$id} = async { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | my $guard = guard { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 175 | 0 | delete $request{$id}; | |||||||||||||||||||||||||||
| 176 | 0 | }; | |||||||||||||||||||||||||||
| 177 | 0 | $self->process_request($request); | |||||||||||||||||||||||||||
| 178 | 0 | }; | |||||||||||||||||||||||||||
| 179 | } else { | ||||||||||||||||||||||||||||
| 180 | 0 | ▶ | $self->logmsg("got notification: ", sub {$self->json_for_log($request, 500)}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 181 | 0 | my $no = ++$notificationNo; | |||||||||||||||||||||||||||
| 182 | 0 | ▶ | $notification{$no} = async { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | my $guard = guard { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 184 | 0 | delete $notification{$no}; | |||||||||||||||||||||||||||
| 185 | 0 | }; | |||||||||||||||||||||||||||
| 186 | 0 | $self->process_request($request); | |||||||||||||||||||||||||||
| 187 | 0 | }; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | cede; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | #======================================== | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | sub lspcall__shutdown { | ||||||||||||||||||||||||||
|
Subroutine
lspcall__shutdown: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 197 | 0 | (my MY $self, my $nullParam) = @_; | |||||||||||||||||||||||||||
| 198 | 0 | $self->{_is_shutting_down} = 1; | |||||||||||||||||||||||||||
| 199 | 0 | undef; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 0 | ▶ | sub lspcall__exit { | ||||||||||||||||||||||||||
|
Subroutine
lspcall__exit: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 203 | 0 | (my MY $self, my $nullParam) = @_; | |||||||||||||||||||||||||||
| 204 | 0 | ▶ | my $code = $self->{_is_shutting_down} ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | 0 | $self->logmsg("exit with code $code"); | |||||||||||||||||||||||||||
| 206 | 0 | ▶ | close $self->{_log_fh} if $self->{_log_fh}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 0 | exit $code; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | #======================================== | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 0 | ▶ | sub send_notification { | ||||||||||||||||||||||||||
|
Subroutine
send_notification: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 213 | 0 | (my MY $self, my ($methodName, $params)) = @_; | |||||||||||||||||||||||||||
| 214 | 0 | my Notification $notif = {}; | |||||||||||||||||||||||||||
| 215 | 0 | $notif->{method} = $methodName; | |||||||||||||||||||||||||||
| 216 | 0 | $notif->{params} = $params; | |||||||||||||||||||||||||||
| 217 | 0 | $notif->{jsonrpc} = $self->{jsonrpc_version}; | |||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 0 | my $wdata = eval { $self->format_message($notif) }; | |||||||||||||||||||||||||||
| 220 | 0 | ▶ | unless (defined $wdata) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | ▶ | $self->logmsg("notification encode failed ($methodName): ", $@ // 'unknown error'); | ||||||||||||||||||||||||||
|
Condition0%0/2
$@ // "unknown error"
MC/DC0%0/1
$@ // "unknown error"
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||
| 222 | 0 | return; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 0 | ▶ | $self->logmsg("sending notification: ", sub {$self->truncate_for_log($wdata, 300)}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 0 | $self->emit_outdata($wdata); | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 0 | ▶ | sub process_request { | ||||||||||||||||||||||||||
|
Subroutine
process_request: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 231 | 0 | (my MY $self, my Request $request) = @_; | |||||||||||||||||||||||||||
| 232 | 0 | my $isRequest = defined $request->{id}; | |||||||||||||||||||||||||||
| 233 | 0 | my Response $outdata; | |||||||||||||||||||||||||||
| 234 | 0 | my $result = eval { $self->call_method($request) }; | |||||||||||||||||||||||||||
| 235 | 0 | ▶ | if (my $msg = $@) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 236 | # Expect $msg is an object which supports stringification, or a string. | ||||||||||||||||||||||||||||
| 237 | 0 | ▶ | my $text = ref $msg ? "$msg" : $msg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if ($isRequest) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | 0 | $outdata->{error} = my Error $error = {}; | |||||||||||||||||||||||||||
| 240 | 0 | $error->{code} = ErrorCodes__UnknownErrorCode; | |||||||||||||||||||||||||||
| 241 | 0 | $error->{message} = $text; | |||||||||||||||||||||||||||
| 242 | } else { | ||||||||||||||||||||||||||||
| 243 | # JSON-RPC forbids responses to notifications. | ||||||||||||||||||||||||||||
| 244 | 0 | $self->logmsg("error in notification handler ($request->{method}): $text"); | |||||||||||||||||||||||||||
| 245 | 0 | return; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | } elsif ($isRequest) { | ||||||||||||||||||||||||||||
| 248 | 0 | $outdata->{result} = $result; | |||||||||||||||||||||||||||
| 249 | } else { | ||||||||||||||||||||||||||||
| 250 | 0 | return; | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 0 | eval { $self->emit_response($outdata, $request->{id}) }; | |||||||||||||||||||||||||||
| 254 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | 0 | $self->logmsg("failed to emit response for id=$request->{id}: $@"); | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | ▶ | sub emit_error_response { | ||||||||||||||||||||||||||
|
Subroutine
emit_error_response: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 260 | 0 | (my MY $self, my ($id, $code, $message)) = @_; | |||||||||||||||||||||||||||
| 261 | 0 | my Response $res = {}; | |||||||||||||||||||||||||||
| 262 | 0 | $res->{error} = my Error $error = {}; | |||||||||||||||||||||||||||
| 263 | 0 | $error->{code} = $code; | |||||||||||||||||||||||||||
| 264 | 0 | $error->{message} = $message; | |||||||||||||||||||||||||||
| 265 | 0 | eval { $self->emit_response($res, $id) }; | |||||||||||||||||||||||||||
| 266 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | 0 | $self->logmsg("failed to emit error response: $@"); | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 0 | ▶ | sub emit_response { | ||||||||||||||||||||||||||
|
Subroutine
emit_response: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 272 | 0 | (my MY $self, my Response $response, my $id) = @_; | |||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 0 | my $wdata = eval { $self->format_message($self->make_response($response, $id)) }; | |||||||||||||||||||||||||||
| 275 | 0 | ▶ | unless (defined $wdata) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | # Never let an unencodable result kill the coro (and the server). | ||||||||||||||||||||||||||||
| 277 | 0 | ▶ | my $err = $@ // 'unknown error'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$@ // "unknown error"
MC/DC0%0/1
$@ // "unknown error"
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||
| 278 | 0 | ▶ | $self->logmsg("response encode failed for id=", $id // 'null', ": $err"); | ||||||||||||||||||||||||||
|
Condition0%0/2
$id // "null"
MC/DC0%0/1
$id // "null"
$id
Truth table0%0/2
A
A= $id
| |||||||||||||||||||||||||||||
| 279 | 0 | my Response $fallback = {}; | |||||||||||||||||||||||||||
| 280 | 0 | $fallback->{error} = my Error $error = {}; | |||||||||||||||||||||||||||
| 281 | 0 | $error->{code} = ErrorCodes__InternalError; | |||||||||||||||||||||||||||
| 282 | 0 | $error->{message} = "response encode failed: $err"; | |||||||||||||||||||||||||||
| 283 | 0 | $wdata = $self->format_message($self->make_response($fallback, $id)); | |||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 0 | ▶ | $self->logmsg("sending response: ", sub {$self->truncate_for_log($wdata, 300)}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 0 | $self->emit_outdata($wdata); | |||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 0 | ▶ | sub emit_outdata { | ||||||||||||||||||||||||||
|
Subroutine
emit_outdata: not called CC=3 SCAR=20.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 292 | 0 | (my MY $self, my $wdata) = @_; | |||||||||||||||||||||||||||
| 293 | 0 | my $guard = $self->{_out_semaphore}->guard; | |||||||||||||||||||||||||||
| 294 | 0 | my $sum = 0; | |||||||||||||||||||||||||||
| 295 | 2 | ▶ | use bytes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 296 | 0 | ▶ | while ((my $diff = length($wdata) - $sum) > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 297 | 0 | my $cnt = aio_write $self->{write_fd}, undef, $diff, $wdata, $sum; | |||||||||||||||||||||||||||
| 298 | 0 | ▶ | die "write_error ($!)" if $cnt <= 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | 0 | $sum += $cnt; | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 0 | $self->logmsg("sent $sum bytes"); | |||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 0 | ▶ | sub make_response { | ||||||||||||||||||||||||||
|
Subroutine
make_response: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 306 | 0 | (my MY $self, my Response $response, my $id) = @_; | |||||||||||||||||||||||||||
| 307 | 0 | $response->{id} = $id; # null for errors without id (ParseError). | |||||||||||||||||||||||||||
| 308 | 0 | $response->{jsonrpc} = $self->{jsonrpc_version}; | |||||||||||||||||||||||||||
| 309 | 0 | $response; | |||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 0 | ▶ | sub format_message { | ||||||||||||||||||||||||||
|
Subroutine
format_message: not called CC=3 SCAR=20.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 313 | 0 | (my MY $self, my Message $message) = @_; | |||||||||||||||||||||||||||
| 314 | 0 | my $outdata = $self->cli_encode_json($message); | |||||||||||||||||||||||||||
| 315 | 0 | ▶ | if (Encode::is_utf8($outdata)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 316 | 0 | Encode::_utf8_off($outdata); | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | 2 | ▶ | use bytes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 319 | 0 | my $len = length $outdata; | |||||||||||||||||||||||||||
| 320 | 0 | my @out = ("Content-Length: $len" | |||||||||||||||||||||||||||
| 321 | , "Content-Type: application/vscode-jsonrpc; charset=utf-8" | ||||||||||||||||||||||||||||
| 322 | , "" | ||||||||||||||||||||||||||||
| 323 | , $outdata); | ||||||||||||||||||||||||||||
| 324 | 0 | ▶ | wantarray ? @out : join("\r\n", @out); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | #======================================== | ||||||||||||||||||||||||||||
| 328 | # Reading frames. | ||||||||||||||||||||||||||||
| 329 | # | ||||||||||||||||||||||||||||
| 330 | # Both loops below check what is already in _buffer BEFORE blocking in | ||||||||||||||||||||||||||||
| 331 | # aio_read, so that several frames arriving in one read (eglot writes | ||||||||||||||||||||||||||||
| 332 | # didChange and definition back to back) are all served without waiting | ||||||||||||||||||||||||||||
| 333 | # for further input. GH-275 | ||||||||||||||||||||||||||||
| 334 | # | ||||||||||||||||||||||||||||
| 335 | # Returns the body of the next frame, or undef at EOF / read error. | ||||||||||||||||||||||||||||
| 336 | 0 | ▶ | sub read_raw_request { | ||||||||||||||||||||||||||
|
Subroutine
read_raw_request: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 337 | 0 | (my MY $self) = @_; | |||||||||||||||||||||||||||
| 338 | 0 | while (1) { | |||||||||||||||||||||||||||
| 339 | 0 | ▶ | my Header $header = $self->read_header | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | or return undef; | ||||||||||||||||||||||||||||
| 341 | 0 | my $len = $header->{'Content-Length'}; | |||||||||||||||||||||||||||
| 342 | 0 | ▶ | if (defined $len and $len =~ /^\d+\z/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $len and $len =~ /^\d+\z/
MC/DC0%0/2
defined $len and $len =~ /^\d+\z/
defined $len
$len =~ /^\d+\z/
Truth table0%0/3
A and B
A= defined $lenB= $len =~ /^\d+\z/
| |||||||||||||||||||||||||||||
| 343 | 0 | ▶ | while ((my $diff = $len - length $self->{_buffer}) > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | my $cnt = aio_read $self->{read_fd}, undef, $diff | ||||||||||||||||||||||||||||
| 345 | 0 | , $self->{_buffer}, length $self->{_buffer}; | |||||||||||||||||||||||||||
| 346 | 0 | ▶ | if (not defined $cnt or $cnt < 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $cnt or $cnt < 0
MC/DC0%0/2
not defined $cnt or $cnt < 0
not defined $cnt
$cnt < 0
Truth table0%0/3
not(A) or B
A= not defined $cntB= $cnt < 0
| |||||||||||||||||||||||||||||
| 347 | 0 | ▶ | next if $! == EINTR; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | 0 | $self->logmsg("read error (body): $!"); | |||||||||||||||||||||||||||
| 349 | 0 | return undef; | |||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | 0 | ▶ | if ($cnt == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 352 | 0 | $self->logmsg("EOF while reading body (wanted $diff more bytes)"); | |||||||||||||||||||||||||||
| 353 | 0 | return undef; | |||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | 0 | my $data = substr($self->{_buffer}, 0, $len, ''); | |||||||||||||||||||||||||||
| 357 | 0 | ▶ | return wantarray ? ($data, $header) : $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | # A header block without (valid) Content-Length: skip it and resync | ||||||||||||||||||||||||||||
| 360 | # at the next header instead of terminating the server. | ||||||||||||||||||||||||||||
| 361 | $self->logmsg("no valid Content-Length, header skipped: " | ||||||||||||||||||||||||||||
| 362 | 0 | ▶ | , sub {$self->json_for_log($header)}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | # Returns the parsed header of the next frame (consumed from _buffer), | ||||||||||||||||||||||||||||
| 367 | # or undef at EOF / read error. | ||||||||||||||||||||||||||||
| 368 | 0 | ▶ | sub read_header { | ||||||||||||||||||||||||||
|
Subroutine
read_header: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 369 | 0 | (my MY $self) = @_; | |||||||||||||||||||||||||||
| 370 | 0 | ▶ | $self->{_buffer} //= ""; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"_buffer"} //= ""
MC/DC0%0/1
$self->{"_buffer"} //= ""
$self->{"_buffer"}
Truth table0%0/2
A
A= $self->{"_buffer"}
| |||||||||||||||||||||||||||||
| 371 | 0 | my $sepPos; | |||||||||||||||||||||||||||
| 372 | 0 | ▶ | while (($sepPos = index($self->{_buffer}, "\r\n\r\n")) < 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 373 | my $cnt = aio_read $self->{read_fd}, undef, $self->{read_length} | ||||||||||||||||||||||||||||
| 374 | 0 | , $self->{_buffer}, length $self->{_buffer}; | |||||||||||||||||||||||||||
| 375 | $self->logmsg("aio read header: cnt=", $cnt // 'undef' | ||||||||||||||||||||||||||||
| 376 | 0 | ▶ | , ($self->{dump_request} ? ("\n", sub {$self->dump_buffer}) : ())); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
Condition0%0/2
$cnt // "undef"
MC/DC0%0/1
$cnt // "undef"
$cnt
Truth table0%0/2
A
A= $cnt
| |||||||||||||||||||||||||||||
| 377 | 0 | ▶ | if (not defined $cnt or $cnt < 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $cnt or $cnt < 0
MC/DC0%0/2
not defined $cnt or $cnt < 0
not defined $cnt
$cnt < 0
Truth table0%0/3
not(A) or B
A= not defined $cntB= $cnt < 0
| |||||||||||||||||||||||||||||
| 378 | 0 | ▶ | next if $! == EINTR; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | 0 | $self->logmsg("read error (header): $!"); | |||||||||||||||||||||||||||
| 380 | 0 | return undef; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | 0 | ▶ | if ($cnt == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 383 | 0 | ▶ | $self->logmsg("EOF with unparsed input: ", sub {$self->truncate_for_log($self->{_buffer}, 200)}) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 384 | 0 | ▶ | if length $self->{_buffer}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 385 | 0 | return undef; | |||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||
| 388 | 0 | my Header $header = {}; | |||||||||||||||||||||||||||
| 389 | 0 | foreach my $line (split /\r\n/, substr($self->{_buffer}, 0, $sepPos)) { | |||||||||||||||||||||||||||
| 390 | 0 | my ($k, $v) = split /:\s*/, $line, 2; | |||||||||||||||||||||||||||
| 391 | 0 | ▶ | next unless defined $k and defined $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $k and defined $v
MC/DC0%0/2
defined $k and defined $v
defined $k
defined $v
Truth table0%0/3
A and B
A= defined $kB= defined $v
| |||||||||||||||||||||||||||||
| 392 | 0 | ▶ | $k = 'Content-Length' if lc($k) eq 'content-length'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 393 | 0 | $header->{$k} = $v; | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | 0 | substr($self->{_buffer}, 0, $sepPos+4, ''); | |||||||||||||||||||||||||||
| 396 | 0 | ▶ | $self->logmsg("got header: ", sub {$self->json_for_log($header)}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 397 | 0 | $header; | |||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | 0 | ▶ | sub dump_buffer { | ||||||||||||||||||||||||||
|
Subroutine
dump_buffer: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 401 | 0 | (my MY $self) = @_; | |||||||||||||||||||||||||||
| 402 | 0 | require Data::HexDump::XXD; | |||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 0 | join("\n", Data::HexDump::XXD::xxd($self->{_buffer})); | |||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | #---------------------------------------- | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | # file:// uri => local path (percent-decoded octets, no symlink | ||||||||||||||||||||||||||||
| 410 | # resolution: the server keys templates by the path form the client | ||||||||||||||||||||||||||||
| 411 | # sends). Symmetric with Inspector::filename2uri (URI::file->new_abs). | ||||||||||||||||||||||||||||
| 412 | 0 | ▶ | sub uri2localpath { | ||||||||||||||||||||||||||
|
Subroutine
uri2localpath: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 413 | 0 | (my MY $self, my $uri) = @_; | |||||||||||||||||||||||||||
| 414 | 0 | ▶ | return undef unless defined $uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 415 | 0 | ▶ | return undef unless $uri =~ m{^file://}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 416 | 0 | URI->new($uri)->file; | |||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | 2 | ▶ | MY->run(\@ARGV) unless caller; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||