LanguageServer/IO.pm

filter: Statementstmt 24.0% 19 / 79 Branchbran 3.1% 1 / 32 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 50.0% 5 / 10 Podpod 0.0% 0 / 1 totaltotal 17.1% 25 / 146 CC 22 SCAR 39.2
CC
22
Cov
16%
run_async
90.0
_read
72.0
_write
30.0
CRAP 50.5
« LanguageServer/Workspace.pm ↑ Summary LanguageServer/DebuggerProcess.pm »
1 package Perl::LanguageServer::IO ;
2  
3 1 ▶use Moose::Role ;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Coro ;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Coro::AIO ;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Data::Dump qw{dump} ;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶no warnings 'uninitialized' ;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 has 'out_fh' =>
12 (
13 is => 'rw',
14 #isa => 'Int',
15 ) ;
16  
17 1 has 'in_fh' =>
18 (
19 is => 'rw',
20 #isa => 'Int',
21 ) ;
22  
23 # ---------------------------------------------------------------------------
24  
25 1 ▶our $windows= ($^O =~ /Win/)?1:0 ;
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /Win/ ? : 0 1 1
26  
27 # ---------------------------------------------------------------------------
28  
29 sub _read
30 0 ▶ {
Subroutine _read: not called CC=8 SCAR=42.8
31 0 my ($self, $data, $length, $dataoffset, $fh, $readline) = @_ ;
32  
33 0 ▶ $fh ||= $self -> in_fh ;
Condition0%0/3
$fh ||= $self->in_fh
l!l&&r!l&&!r
000
MC/DC0%0/2
$fh ||= $self->in_fh
$fh $self->in_fh
Truth table0%0/3
A ||= B
A= $fhB= $self->in_fh
ABresult
1X1
011
000
34  
35 0 ▶ if (ref ($fh) =~ /^Coro::Handle/)
Branch: 1 branch
BranchTrueFalseTotal
if (ref($fh) =~ /^Coro::Handle/) 0 0 0
36 {
37 0 ▶ if ($readline)
Branch: 1 branch
BranchTrueFalseTotal
if ($readline) 0 0 0
38 {
39 0 $$data = $fh -> readline ;
40 0 return length ($$data) ;
41 }
42 0 return $fh -> sysread ($$data, $length, $dataoffset) ;
43 }
44 0 ▶ if (!$windows || !ref $fh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($Perl::LanguageServer::IO::windows and ref $fh) 0 0 0
Condition0%0/3
$Perl::LanguageServer::IO::windows and ref $fh
!ll&&!rl&&r
000
MC/DC0%0/2
$Perl::LanguageServer::IO::windows and ref $fh
$Perl::LanguageServer::IO::windows ref $fh
Truth table0%0/3
A and B
A= $Perl::LanguageServer::IO::windowsB= ref $fh
ABresult
0X0
100
111
45 {
46 0 return aio_read ($fh, undef, $length, $$data, $dataoffset) ;
47 }
48  
49 0 my $timeout = 0.01 ;
50  
51 0 my $s = IO::Select -> new ();
52 0 $s -> add($fh) ;
53 0 my @ready ;
54 0 ▶ while (!(@ready = $s -> can_read (0)))
Branch: 1 branch
BranchTrueFalseTotal
unless (@ready = $s->can_read(0)) 0 0 0
55 {
56 0 Coro::AnyEvent::sleep ($timeout) ;
57 }
58 0 ▶ $length = length ($$data) if (!defined ($length)) ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $length 0 0 0
59 0 return sysread ($fh, $$data, $length, $dataoffset) ;
60 }
61  
62 # ---------------------------------------------------------------------------
63  
64 sub _write
65 0 ▶ {
Subroutine _write: not called CC=5 SCAR=34.0
66 0 my ($self, $data, $length, $dataoffset) = @_ ;
67  
68 0 my $fh = $self -> out_fh ;
69 0 ▶ if (ref ($fh) =~ /^Coro::Handle/)
Branch: 1 branch
BranchTrueFalseTotal
if (ref($fh) =~ /^Coro::Handle/) 0 0 0
70 {
71 0 return $fh -> syswrite ($data, $length, $dataoffset) ;
72 }
73  
74 0 ▶ if (!$windows || !ref $fh)
Branch: 1 branch
BranchTrueFalseTotal
unless ($Perl::LanguageServer::IO::windows and ref $fh) 0 0 0
Condition0%0/3
$Perl::LanguageServer::IO::windows and ref $fh
!ll&&!rl&&r
000
MC/DC0%0/2
$Perl::LanguageServer::IO::windows and ref $fh
$Perl::LanguageServer::IO::windows ref $fh
Truth table0%0/3
A and B
A= $Perl::LanguageServer::IO::windowsB= ref $fh
ABresult
0X0
100
111
75 {
76 0 return aio_write ($fh, undef, $length, $data, $dataoffset) ;
77 }
78  
79 0 ▶ $length = length ($data) if (!defined ($length)) ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $length 0 0 0
80 0 return syswrite ($fh, $data, $length, $dataoffset) ;
81 }
82  
83 # ---------------------------------------------------------------------------
84  
85 sub run_async
86 0 ▶ {
Subroutine run_async: not called CC=9 SCAR=45.0
Pod undocumented
87 0 my ($self, $cmd, $on_stdout, $on_stderr, $on_exit) = @_ ;
88  
89 0 ▶ $on_stdout ||= 'on_stdout' ;
Condition0%0/2
$on_stdout ||= "on_stdout"
l!l
00
MC/DC0%0/1
$on_stdout ||= "on_stdout"
$on_stdout
Truth table0%0/2
A
A= $on_stdout
Aresult
11
00
90 0 ▶ $on_stderr ||= 'on_stderr' ;
Condition0%0/2
$on_stderr ||= "on_stderr"
l!l
00
MC/DC0%0/1
$on_stderr ||= "on_stderr"
$on_stderr
Truth table0%0/2
A
A= $on_stderr
Aresult
11
00
91 0 ▶ $on_exit ||= 'on_exit' ;
Condition0%0/2
$on_exit ||= "on_exit"
l!l
00
MC/DC0%0/1
$on_exit ||= "on_exit"
$on_exit
Truth table0%0/2
A
A= $on_exit
Aresult
11
00
92  
93 0 my($wtr, $rdr, $err);
94  
95 0 ▶ if ( ref($cmd) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cmd) { } 0 0 0
96 {
97 0 $self -> logger ("start @$cmd\n") ;
98 } else
99 {
100 0 $self -> logger ("start $cmd\n") ;
101 }
102  
103 0 require IPC::Open3 ;
104 0 require Symbol ;
105 0 $err = Symbol::gensym () ;
106 0 my $pid;
107 0 ▶ if ( ref($cmd) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cmd) { } 0 0 0
108 {
109 0 ▶ $pid = IPC::Open3::open3($wtr, $rdr, $err, @$cmd) or die "Cannot run @$cmd" ;
Branch: 1 branch
BranchTrueFalseTotal
$pid = IPC::Open3::open3($wtr, $rdr, $err, @$cmd) or die "Cannot run @$cmd" 0 0 0
110 } else
111 {
112 0 ▶ $pid = IPC::Open3::open3($wtr, $rdr, $err, $cmd) or die "Cannot run $cmd" ;
Branch: 1 branch
BranchTrueFalseTotal
$pid = IPC::Open3::open3($wtr, $rdr, $err, $cmd) or die "Cannot run $cmd" 0 0 0
113 }
114  
115 0 $self -> out_fh ($wtr) ;
116 0 $self -> in_fh ($rdr) ;
117  
118 0 ▶ if ( ref($cmd) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cmd) { } 0 0 0
119 {
120 0 $self -> logger ("@$cmd started\n") ;
121 } else
122 {
123 0 $self -> logger ("$cmd started\n") ;
124 }
125  
126 async
127 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
128 0 my $data ;
129 0 ▶ while ($self -> _read (\$data, 8192))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_read(\$data, 8192)) 0 0 0
130 {
131 0 $self -> logger ("stdout ", $data, "\n") ;
132 0 $self -> $on_stdout ($data) ;
133 }
134 0 waitpid( $pid, 0 );
135 0 $self -> logger ("@$cmd ended\n") ;
136 0 Coro::cede_notself () ;
137 0 $self -> $on_exit ($?) ;
138 0 } ;
139  
140 async
141 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
142 0 my $data ;
143 0 ▶ while ($self -> _read (\$data, 8192, undef, $err))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_read(\$data, 8192, undef, $err)) 0 0 0
144 {
145 0 $self -> logger ("stderr ", $data, "\n") ;
146 0 $self -> $on_stderr ($data) ;
147 }
148 0 } ;
149  
150 0 return $pid ;
151 }
152  
153  
154 1 1 ;
155  
« LanguageServer/Workspace.pm ↑ Summary LanguageServer/DebuggerProcess.pm »