Ext.pm

filter: Statementstmt 50.2% 97 / 193 Branchbran 10.0% 2 / 20 Conditioncond 12.5% 3 / 24 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 49.0% 27 / 55 Podpod 100% 25 / 25 totaltotal 46.5% 154 / 331 CC 22 SCAR 17.1
CC
22
Cov
43%
start_host
20.0
foreach_rtp
20.0
replace_termcodes
20.0
CRAP 5.5
« Ext/Current.pm ↑ Summary Ext/Buffer.pm »
1 package Neovim::Ext;
2 54 $Neovim::Ext::VERSION = '0.01';
3 54 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 54 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 54 ▶use base qw/Class::Accessor/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 54 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 54 ▶use Exporter qw/import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 54 ▶use Neovim::Ext::MsgPack::RPC;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 54 ▶use Neovim::Ext::Common qw/walk/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 54 ▶use Neovim::Ext::Buffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 54 ▶use Neovim::Ext::Buffers;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 54 ▶use Neovim::Ext::Current;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 54 ▶use Neovim::Ext::Funcs;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 54 ▶use Neovim::Ext::LuaFuncs;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 54 ▶use Neovim::Ext::RemoteApi;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 54 ▶use Neovim::Ext::RemoteMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 54 ▶use Neovim::Ext::RemoteSequence;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 54 ▶use Neovim::Ext::Tabpage;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 54 ▶use Neovim::Ext::Window;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 54 ▶use Neovim::Ext::Plugin::Host;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 54 __PACKAGE__->mk_accessors (qw/session channel_id metadata types api
23 vars vvars options buffers windows tabpages current funcs lua err_cb/);
24  
25 54 our @EXPORT = (qw(start_host));
26  
27 sub from_session
28 {
29 43 ▶ my ($session) = @_;
Subroutine from_session: called CC=1 SCAR=0.0
Pod documented
30  
31 43 my $result = $session->request ('nvim_get_api_info');
32 11 my ($channel_id, $metadata) = ($result->[0], $result->[1]);
33  
34 my $types =
35 {
36 $metadata->{types}{Buffer}{id} => 'Neovim::Ext::Buffer',
37 $metadata->{types}{Window}{id} => 'Neovim::Ext::Window',
38 11 $metadata->{types}{Tabpage}{id} => 'Neovim::Ext::Tabpage',
39 };
40  
41 11 return __PACKAGE__->new ($session, $channel_id, $metadata, $types);
42 }
43  
44  
45  
46 sub _setup_logging
47 {
48 0 ▶ my ($name) = @_;
Subroutine _setup_logging: not called CC=2 SCAR=17.9
49  
50 0 ▶ if ($ENV{NVIM_PERL_LOG_FILE})
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"NVIM_PERL_LOG_FILE"}) 0 0 0
51 {
52 0 *SAVESTDERR = *STDERR;
53 0 open *STDERR, '>', $ENV{NVIM_PERL_LOG_FILE};
54 }
55 }
56  
57  
58  
59 sub start_host
60 {
61 0 ▶ my ($session) = @_;
Subroutine start_host: not called CC=4 SCAR=30.0
Pod documented
62  
63 0 my @plugins;
64 0 ▶ while (my $plugin = shift @ARGV)
Branch: 1 branch
BranchTrueFalseTotal
if (my $plugin = shift @ARGV) 0 0 0
65 {
66 0 ▶ next if ($plugin !~ /\.pm$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $plugin =~ /\.pm$/ 0 0 0
67 0 push @plugins, $plugin;
68 }
69  
70 0 _setup_logging ('rplugin');
71  
72 0 ▶ $session //= Neovim::Ext::MsgPack::RPC::stdio_session();
Condition0%0/3
$session //= Neovim::Ext::MsgPack::RPC::stdio_session()
l!l&&r!l&&!r
000
MC/DC0%0/2
$session //= Neovim::Ext::MsgPack::RPC::stdio_session()
$session Neovim::Ext::MsgPack::RPC::stdio_session()
Truth table0%0/3
A //= B
A= $sessionB= Neovim::Ext::MsgPack::RPC::stdio_session()
ABresult
1X1
011
000
73 0 my $nvim = from_session ($session);
74  
75 0 my $host = Neovim::Ext::Plugin::Host->new ($nvim);
76 0 $host->start (keys (%{{ map { $_ => 1 } @plugins }}))
77 }
78  
79  
80  
81 sub new
82 {
83 11 ▶ my ($this, $session, $channel_id, $metadata, $types, %options) = @_;
Subroutine new: called CC=2 SCAR=7.0
Pod documented
84  
85 11 ▶ my $class = ref ($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0110
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
86 my $self =
87 {
88 session => $session,
89 channel_id => $channel_id,
90 metadata => $metadata,
91 types => $types,
92 err_cb => $options{err_cb},
93 11 };
94  
95 11 my $obj = bless $self, $class;
96 11 $obj->api (Neovim::Ext::RemoteApi->new ($obj, 'nvim_'));
97 11 $obj->vars (Neovim::Ext::RemoteMap->new ($obj, 'nvim_get_var', 'nvim_set_var', 'nvim_del_var'));
98 11 $obj->vvars (Neovim::Ext::RemoteMap->new ($obj, 'nvim_get_vvar'));
99 11 $obj->options (Neovim::Ext::RemoteMap->new ($obj, 'nvim_get_option', 'nvim_set_option'));
100 11 $obj->buffers (Neovim::Ext::Buffers->new ($obj));
101 11 $obj->windows (Neovim::Ext::RemoteSequence->new ($obj, 'nvim_list_wins'));
102 11 $obj->tabpages (Neovim::Ext::RemoteSequence->new ($obj, 'nvim_list_tabpages'));
103 11 $obj->current (Neovim::Ext::Current->new ($obj));
104 11 $obj->funcs (Neovim::Ext::Funcs->new ($obj));
105 11 $obj->lua (Neovim::Ext::LuaFuncs->new ($obj));
106 11 return $obj;
107 }
108  
109  
110  
111 sub next_message
112 {
113 0 ▶ my ($this) = @_;
Subroutine next_message: not called CC=2 SCAR=17.9
Pod documented
114  
115 0 my $msg = $this->session->next_message();
116 0 ▶ if ($msg)
Branch: 1 branch
BranchTrueFalseTotal
if ($msg) 0 0 0
117 {
118 0 ▶ return walk (sub { $this->_from_nvim (@_) }, $msg);
Subroutine __ANON__: not called CC=1 SCAR=6.9
119 }
120  
121 0 return undef;
122 }
123  
124  
125  
126 sub run_loop
127 {
128 0 ▶ my ($this, $request_cb, $notification_cb, $setup_cb, $err_cb) = @_;
Subroutine run_loop: not called CC=2 SCAR=17.9
Pod documented
129  
130 $err_cb //= sub
131 {
132 0 ▶ print STDERR @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
133 0 ▶ };
Condition0%0/3
$err_cb //= sub { print STDERR @_; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$err_cb //= sub { print STDERR @_; }
$err_cb sub { print STDERR @_; }
Truth table0%0/3
A //= B
A= $err_cbB= sub { print STDERR @_; }
ABresult
1X1
011
000
134  
135 0 $this->err_cb ($err_cb);
136  
137 my $filter_request_cb = sub
138 {
139 0 ▶ my ($name, $args) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
140  
141 0 ▶ $args = walk (sub { $this->_from_nvim (@_) }, $args);
Subroutine __ANON__: not called CC=1 SCAR=6.9
142  
143 0 my $result;
144 eval
145 0 {
146 0 $result = $request_cb->($name, $args);
147 };
148  
149 0 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
150 {
151 0 $this->err_cb->($@);
152 0 die;
153 }
154  
155 0 ▶ return walk (sub { $this->_to_nvim (@_) }, $result);
Subroutine __ANON__: not called CC=1 SCAR=6.9
156 0 };
157  
158 my $filter_notification_cb = sub
159 {
160 0 ▶ my ($name, $args) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
161  
162 0 ▶ $args = walk (sub { $this->_from_nvim (@_) }, $args);
Subroutine __ANON__: not called CC=1 SCAR=6.9
163  
164 eval
165 0 {
166 0 $notification_cb->($name, $args);
167 };
168  
169 0 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
170 {
171 0 $this->err_cb->($@);
172 0 die;
173 }
174 0 };
175  
176 0 $this->session->run ($filter_request_cb, $filter_notification_cb, $setup_cb);
177 }
178  
179  
180  
181 sub stop_loop
182 {
183 0 ▶ my ($this) = @_;
Subroutine stop_loop: not called CC=1 SCAR=6.9
Pod documented
184 0 $this->session->stop();
185 }
186  
187  
188  
189 sub close
190 {
191 0 ▶ my ($this) = @_;
Subroutine close: not called CC=1 SCAR=6.9
Pod documented
192 0 $this->session->close();
193 }
194  
195  
196  
197 sub request
198 {
199 18 ▶ my ($this, $name, @args) = @_;
Subroutine request: called CC=1 SCAR=0.0
Pod documented
200  
201 18 ▶ @args = @{walk (sub { $this->_to_nvim (@_) }, \@args)};
Subroutine __ANON__: called CC=1 SCAR=0.0
202 18 my $result = $this->session->request ($name, @args);
203 7 ▶ return walk (sub { $this->_from_nvim (@_) }, $result);
Subroutine __ANON__: called CC=1 SCAR=0.0
204 }
205  
206  
207  
208 sub subscribe
209 {
210 0 ▶ my ($this, $event) = @_;
Subroutine subscribe: not called CC=1 SCAR=6.9
Pod documented
211 0 return $this->request ('nvim_subscribe', $event);
212 }
213  
214  
215  
216 sub unsubscribe
217 {
218 0 ▶ my ($this, $event) = @_;
Subroutine unsubscribe: not called CC=1 SCAR=6.9
Pod documented
219 0 return $this->request ('nvim_unsubscribe', $event);
220 }
221  
222  
223  
224 sub command
225 {
226 2 ▶ my ($this, $string, @args) = @_;
Subroutine command: called CC=1 SCAR=0.0
Pod documented
227 2 return $this->request ('nvim_command', $string, @args);
228 }
229  
230  
231  
232 sub command_output
233 {
234 0 ▶ my ($this, $string) = @_;
Subroutine command_output: not called CC=1 SCAR=6.9
Pod documented
235 0 return $this->request ('nvim_command_output', $string)
236 }
237  
238  
239  
240 sub eval
241 {
242 0 ▶ my ($this, $string, @args) = @_;
Subroutine eval: not called CC=1 SCAR=6.9
Pod documented
243 0 return $this->request ('nvim_eval', $string, @args);
244 }
245  
246  
247  
248 sub call
249 {
250 0 ▶ my ($this, $name, @args) = @_;
Subroutine call: not called CC=1 SCAR=6.9
Pod documented
251 0 return $this->request ('nvim_call_function', $name, [@args]);
252 }
253  
254  
255  
256 sub exec_lua
257 {
258 0 ▶ my ($this, $code, @args) = @_;
Subroutine exec_lua: not called CC=1 SCAR=6.9
Pod documented
259 0 return $this->request ('nvim_execute_lua', $code, [@args]);
260 }
261  
262  
263  
264 sub strwidth
265 {
266 0 ▶ my ($this, $string) = @_;
Subroutine strwidth: not called CC=1 SCAR=6.9
Pod documented
267 0 return $this->request ('nvim_strwidth', $string);
268 }
269  
270  
271  
272 sub list_runtime_paths
273 {
274 0 ▶ my ($this) = @_;
Subroutine list_runtime_paths: not called CC=1 SCAR=6.9
Pod documented
275 0 return $this->request ('nvim_list_runtime_paths');
276 }
277  
278  
279  
280 sub foreach_rtp
281 {
282 0 ▶ my ($this, $cb) = @_;
Subroutine foreach_rtp: not called CC=4 SCAR=30.0
Pod documented
283  
284 0 foreach my $path (@{$this->list_runtime_paths})
285 {
286 eval
287 0 {
288 0 ▶ last if (!$cb->($path));
Branch: 1 branch
BranchTrueFalseTotal
unless &$cb($path) 0 0 0
289 };
290  
291 0 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
292 {
293 0 last;
294 }
295 }
296 }
297  
298  
299  
300 sub chdir
301 {
302 0 ▶ my ($this, $dir_path) = @_;
Subroutine chdir: not called CC=1 SCAR=6.9
Pod documented
303 0 chdir ($dir_path);
304 0 return $this->request ('nvim_set_current_dir', $dir_path);
305 }
306  
307  
308  
309 sub feedkeys
310 {
311 0 ▶ my ($this, $keys, $options, $escape_csi) = @_;
Subroutine feedkeys: not called CC=3 SCAR=24.8
Pod documented
312  
313 0 ▶ $options //= '';
Condition0%0/2
$options //= ""
l!l
00
MC/DC0%0/1
$options //= ""
$options
Truth table0%0/2
A
A= $options
Aresult
11
00
314 0 ▶ $escape_csi //= 1;
Condition0%0/2
$escape_csi //= 1
l!l
00
MC/DC0%0/1
$escape_csi //= 1
$escape_csi
Truth table0%0/2
A
A= $escape_csi
Aresult
11
00
315 0 return $this->request ('nvim_feedkeys', $keys, $options, $escape_csi);
316 }
317  
318  
319  
320 sub input
321 {
322 0 ▶ my ($this, $bytes) = @_;
Subroutine input: not called CC=1 SCAR=6.9
Pod documented
323 0 return $this->request ('nvim_input', $bytes);
324 }
325  
326  
327  
328 sub replace_termcodes
329 {
330 0 ▶ my ($this, $string, $from_part, $do_lt, $special) = @_;
Subroutine replace_termcodes: not called CC=4 SCAR=30.0
Pod documented
331  
332 0 ▶ $from_part //= 0;
Condition0%0/2
$from_part //= 0
l!l
00
MC/DC0%0/1
$from_part //= 0
$from_part
Truth table0%0/2
A
A= $from_part
Aresult
11
00
333 0 ▶ $do_lt //= 1;
Condition0%0/2
$do_lt //= 1
l!l
00
MC/DC0%0/1
$do_lt //= 1
$do_lt
Truth table0%0/2
A
A= $do_lt
Aresult
11
00
334 0 ▶ $special //= 1;
Condition0%0/2
$special //= 1
l!l
00
MC/DC0%0/1
$special //= 1
$special
Truth table0%0/2
A
A= $special
Aresult
11
00
335 0 return $this->request ('nvim_replace_termcodes', $string,
336 $from_part, $do_lt, $special);
337 }
338  
339  
340  
341 sub out_write
342 {
343 0 ▶ my ($self, $msg, @args) = @_;
Subroutine out_write: not called CC=1 SCAR=6.9
Pod documented
344 0 return $self->request ('nvim_out_write', $msg, @args);
345 }
346  
347  
348  
349 sub err_write
350 {
351 0 ▶ my ($self, $msg, @args) = @_;
Subroutine err_write: not called CC=1 SCAR=6.9
Pod documented
352 0 return $self->request ('nvim_err_write', $msg, @args);
353 }
354  
355  
356  
357 sub quit
358 {
359 1 ▶ my ($self, $quit_command) = @_;
Subroutine quit: called CC=2 SCAR=7.0
Pod documented
360  
361 1 ▶ $quit_command //= 'qa!';
Condition50%1/2
$quit_command //= "qa!"
l!l
01
MC/DC0%0/1
$quit_command //= "qa!"
$quit_command
Truth table50%1/2
A
A= $quit_command
Aresult
11
00
362 1 eval { $self->command ($quit_command) };
363 }
364  
365  
366  
367 sub _to_nvim
368 {
369 22 ▶ my ($this, $obj) = @_;
Subroutine _to_nvim: called CC=3 SCAR=13.3
370  
371 22 ▶ if (ref ($obj) && $obj->isa ('Neovim::Ext::Remote'))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj and $obj->isa("Neovim::Ext::Remote")) 0 22 22
Condition33%1/3
ref $obj and $obj->isa("Neovim::Ext::Remote")
!ll&&!rl&&r
2200
MC/DC0%0/2
ref $obj and $obj->isa("Neovim::Ext::Remote")
ref $obj $obj->isa("Neovim::Ext::Remote")
Truth table33%1/3
A and B
A= ref $objB= $obj->isa("Neovim::Ext::Remote")
ABresult
0X0
100
111
372 {
373 0 return $obj->code_data;
374 }
375  
376 22 return $obj;
377 }
378  
379  
380  
381 sub _from_nvim
382 {
383 7 ▶ my ($this, $obj) = @_;
Subroutine _from_nvim: called CC=2 SCAR=8.4
384  
385 7 ▶ if (ref ($obj) eq 'MsgPack::Raw::Ext')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj eq "MsgPack::Raw::Ext") 0 7 7
386 {
387 0 my $class = $this->types->{$obj->{type}};
388 0 return $class->new ($this, $obj);
389 }
390  
391 7 return $obj;
392 }
393  
394 54 1;
395  
396 __END__
« Ext/Current.pm ↑ Summary Ext/Buffer.pm »