lib/Neovim/RPC/API.pm

filter: Statementstmt 54.2% 32 / 59 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 44.4% 8 / 18 Podpod 25.0% 1 / 4 totaltotal 50.6% 41 / 81 CC 3 SCAR 8.8
CC
3
Cov
54%
print_commands
6.0
export_dsl
6.0
__ANON__
2.0
CRAP 2.4
« lib/Neovim/RPC.pm ↑ Summary lib/Neovim/RPC/Plugin/LoadPlugin.pm »
1 package Neovim::RPC::API;
2 4 our $AUTHORITY = 'cpan:YANICK';
3 4 $Neovim::RPC::API::VERSION = '1.0.1';
4 4 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 ▶use Neovim::RPC::API::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶use List::AllUtils qw/ any /;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Promises qw/ deferred /;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 has log => (
19 is => 'ro',
20 lazy => 1,
21 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 Log::Any->get_logger->clone( prefix => '[Neovim::RPC::API] ' );
23 },
24 4 );
25  
26 has ready => (
27 is => 'ro',
28 lazy => 1,
29 0 ▶ default => sub { deferred },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 4 );
31  
32 4 has "rpc" => (
33 isa => 'Neovim::RPC',
34 is => 'ro',
35 required => 1,
36 );
37  
38 4 has channel_id => (
39 is => 'rw',
40 isa => 'Int',
41 );
42  
43 has commands => (
44 traits => [ 'Array' ],
45 is => 'ro',
46 isa => 'ArrayRef',
47 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 4 handles => {
49 _push_command => 'push',
50 all_commands => 'elements',
51 },
52 );
53  
54 has types => (
55 is => 'ro',
56 0 ▶ default => sub{ {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 4 );
58  
59 0 ▶sub print_commands {
Subroutine print_commands: not called CC=2 SCAR=17.9
Pod undocumented
60 0 my( $self ) = @_;
61  
62 0 for my $c ( sort { $a->name cmp $b->name } $self->all_commands ) {
63 0 say $c->name, ' ( ', join( ', ', map { join ' ', @$_ } $c->all_parameters ) , ' ) -> ',
64 $c->return_type;
65 }
66  
67 }
68  
69 0 ▶sub has_command {
Subroutine has_command: not called CC=1 SCAR=6.9
Pod undocumented
70 0 my( $self, $command ) = @_;
71 0 ▶ return any { $_->{name} eq $command } $self->all_commands;
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 }
73  
74 0 ▶sub add_command {
Subroutine add_command: not called CC=1 SCAR=6.9
Pod undocumented
75 0 my( $self, $command ) = @_;
76  
77 0 $command->{api} = $self;
78  
79 0 my $c = Neovim::RPC::API::Command->new($command);
80 0 $self->_push_command($c);
81  
82 0 ▶ $self->meta->add_method( $c->name => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
83 0 shift;
84 0 my @args = @_;
85  
86 0 my $struct = $c->args_to_struct(@args);
87  
88 0 return $self->rpc->send_request( $c->name => $struct);
89 })
90  
91 0 }
92  
93  
94 0 ▶sub export_dsl {
Subroutine export_dsl: not called CC=2 SCAR=17.9
Pod documented
95 0 my $self = shift;
96 0 my $interactive = shift;
97  
98 0 my $class = caller;
99  
100 0 for my $command ( $self->all_commands ) {
101 0 my $name = $command->name;
102  
103 0 eval qq!
104 sub ${class}::$name {
105 my \$p =\$self->$name(\@_);
106 return unless \$interactive;
107 \$self->rpc->loop(\$p);
108 \$p->is_done ? \$p->get : warn \$p->failure;
109 }
110 !;
111 }
112
113 }
114  
115  
116 4 1;
117  
118 __END__
« lib/Neovim/RPC.pm ↑ Summary lib/Neovim/RPC/Plugin/LoadPlugin.pm »