| 1 | package Neovim::RPC; | ||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||||||||
| 3 | # ABSTRACT: RPC client for Neovim | ||||||||||||||||||||
| 4 | 2 | $Neovim::RPC::VERSION = '1.0.1'; | |||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use IO::Socket::INET; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use MsgPack::RPC; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | ▶ | use Neovim::RPC::API::AutoDiscover; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 2 | ▶ | use MsgPack::Decoder; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 2 | ▶ | use Class::Load qw/ load_class /; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | ▶ | use experimental 'signatures'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 2 | extends 'MsgPack::RPC'; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 2 | has '+io' => ( | |||||||||||||||||||
| 20 | builder => '_build_io' | ||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | ▶ | sub _build_io { | ||||||||||||||||||
|
Subroutine
_build_io: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 24 | 0 | my $self = shift; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 0 | ▶ | my $io =$ENV{NVIM_LISTEN_ADDRESS} || do { | ||||||||||||||||||
|
Condition0%0/3
$ENV{'NVIM_LISTEN_ADDRESS'} || do {
open my $in, '<', '-';
open my $out, '>', '-';
[$in, $out]
}
MC/DC0%0/2
$ENV{'NVIM_LISTEN_ADDRESS'} || do {
open my $in, '<', '-';
open my $out, '>', '-';
[$in, $out]
}
$ENV{'NVIM_LISTEN_ADDRESS'}
do {
open my $in, '<', '-';
open my $out, '>', '-';
[$in, $out]
}
Truth table0%0/3
A || B
A= $ENV{'NVIM_LISTEN_ADDRESS'}B= do {
open my $in, '<', '-';
open my $out, '>', '-';
[$in, $out]
}
| |||||||||||||||||||||
| 27 | 0 | open my $in, '<', '-'; | |||||||||||||||||||
| 28 | 0 | open my $out, '>', '-'; | |||||||||||||||||||
| 29 | 0 | [ $in, $out ]; | |||||||||||||||||||
| 30 | }; | ||||||||||||||||||||
| 31 | 0 | $self->_set_io_accessors($self->io); | |||||||||||||||||||
| 32 | 0 | $io; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | # sub BUILD { my $self = shift; $self->_set_io_accessors($self->io) if $self->io } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | ▶ | sub BUILD { | ||||||||||||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||
| 39 | 0 | ▶ | $self->api->ready->done(sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 40 | 0 | ▶ | $self->subscribe( 'nvimx_stop', sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 41 | 0 | $self->loop->stop; | |||||||||||||||||||
| 42 | 0 | }); | |||||||||||||||||||
| 43 | }) | ||||||||||||||||||||
| 44 | 0 | } | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | has "api" => ( | ||||||||||||||||||||
| 47 | is => 'ro', | ||||||||||||||||||||
| 48 | lazy => 1, | ||||||||||||||||||||
| 49 | 0 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 50 | 0 | my $self = shift; | |||||||||||||||||||
| 51 | 0 | Neovim::RPC::API::AutoDiscover->new( rpc => $self ); | |||||||||||||||||||
| 52 | }, | ||||||||||||||||||||
| 53 | 2 | ); | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | ▶ | before subscribe => sub($self,$event,@){ | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 56 | 0 | ▶ | $self->api->ready->done( sub{ $self->api->vim_subscribe( event => $event ) }); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 57 | 2 | }; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | ▶ | 0 and around emit_request => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 60 | 0 | my( $orig, $self, @args ) = @_; | |||||||||||||||||||
| 61 | 0 | my $event = $orig->($self,@args); | |||||||||||||||||||
| 62 | 0 | ▶ | $event->response->fail("no subscriber") unless $event->response->is_ready; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | 0 | $event; | |||||||||||||||||||
| 64 | 2 | }; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | has plugins => ( | ||||||||||||||||||||
| 67 | is => 'ro', | ||||||||||||||||||||
| 68 | traits => [ 'Hash' ], | ||||||||||||||||||||
| 69 | isa => 'HashRef', | ||||||||||||||||||||
| 70 | 0 | ▶ | default => sub { +{} }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 71 | 2 | ); | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | # TODO make that a coerced type | ||||||||||||||||||||
| 74 | # TODO can load an object directly | ||||||||||||||||||||
| 75 | # TODO switch load_class for use_module | ||||||||||||||||||||
| 76 | 0 | ▶ | sub load_plugin ( $self, $plugin ) { | ||||||||||||||||||
|
Subroutine
load_plugin: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 77 | 0 | my $class = 'Neovim::RPC::Plugin::' . $plugin; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | ▶ | return $self->plugins->{$plugin} ||= | ||||||||||||||||||
|
Condition0%0/3
$self->plugins->{$plugin} ||= load_class($class)->new("rpc", $self)
MC/DC0%0/2
$self->plugins->{$plugin} ||= load_class($class)->new("rpc", $self)
$self->plugins->{$plugin}
load_class($class)->new("rpc", $self)
Truth table0%0/3
A ||= B
A= $self->plugins->{$plugin}B= load_class($class)->new("rpc", $self)
| |||||||||||||||||||||
| 80 | load_class($class)->new( rpc => $self ); | ||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 2 | 1; | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||