| 1 | package Neovim::RPC::API; | ||
| 2 | 4 | our $AUTHORITY = 'cpan:YANICK'; | |
| 3 | 4 | $Neovim::RPC::API::VERSION = '0.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 List::AllUtils qw/ any /; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | |||
| 15 | 4 | with 'MooseX::Role::Loggable'; | |
| 16 | |||
| 17 | 4 | has "rpc" => ( | |
| 18 | isa => 'Neovim::RPC', | ||
| 19 | is => 'ro', | ||
| 20 | required => 1, | ||
| 21 | ); | ||
| 22 | |||
| 23 | 4 | has channel_id => ( | |
| 24 | is => 'rw', | ||
| 25 | isa => 'Int', | ||
| 26 | ); | ||
| 27 | |||
| 28 | has commands => ( | ||
| 29 | traits => [ 'Array' ], | ||
| 30 | is => 'ro', | ||
| 31 | isa => 'ArrayRef', | ||
| 32 | 0 | ▶ | default => sub { [] }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 33 | 4 | handles => { | |
| 34 | _push_command => 'push', | ||
| 35 | all_commands => 'elements', | ||
| 36 | }, | ||
| 37 | ); | ||
| 38 | |||
| 39 | has types => ( | ||
| 40 | is => 'ro', | ||
| 41 | 0 | ▶ | default => sub{ {} }, |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 42 | 4 | ); | |
| 43 | |||
| 44 | sub print_commands { | ||
| 45 | 0 | ▶ | my( $self ) = @_; |
|
Subroutine
print_commands: not called CC=2 SCAR=17.9
Pod
undocumented
| |||
| 46 | |||
| 47 | 0 | for my $c ( sort { $a->name cmp $b->name } $self->all_commands ) { | |
| 48 | 0 | say $c->name, ' ( ', join( ', ', map { join ' ', @$_ } $c->all_parameters ) , ' ) -> ', | |
| 49 | $c->return_type; | ||
| 50 | } | ||
| 51 | |||
| 52 | } | ||
| 53 | |||
| 54 | sub has_command { | ||
| 55 | 0 | ▶ | my( $self, $command ) = @_; |
|
Subroutine
has_command: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 56 | 0 | ▶ | return any { $_->{name} eq $command } $self->all_commands; |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 57 | } | ||
| 58 | |||
| 59 | sub add_command { | ||
| 60 | 0 | ▶ | my( $self, $command ) = @_; |
|
Subroutine
add_command: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 61 | |||
| 62 | 0 | $command->{api} = $self; | |
| 63 | |||
| 64 | 0 | my $c = Neovim::RPC::API::Command->new($command); | |
| 65 | 0 | $self->_push_command($c); | |
| 66 | |||
| 67 | $self->meta->add_method( $c->name => sub { | ||
| 68 | 0 | ▶ | shift; |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 69 | 0 | my %args = @_; | |
| 70 | |||
| 71 | 0 | my $struct = $c->args_to_struct(%args); | |
| 72 | |||
| 73 | 0 | $self->rpc->request( $c->name => $struct); | |
| 74 | }) | ||
| 75 | |||
| 76 | 0 | } | |
| 77 | |||
| 78 | |||
| 79 | 4 | 1; | |
| 80 | |||
| 81 | __END__ | ||
| 82 | |||
| 83 | =pod | ||
| 84 | |||
| 85 | =encoding UTF-8 | ||
| 86 | |||
| 87 | =head1 NAME | ||
| 88 | |||
| 89 | Neovim::RPC::API | ||
| 90 | |||
| 91 | =head1 VERSION | ||
| 92 | |||
| 93 | version 0.0.1 | ||
| 94 | |||
| 95 | =head1 AUTHOR | ||
| 96 | |||
| 97 | Yanick Champoux <yanick@cpan.org> | ||
| 98 | |||
| 99 | =head1 COPYRIGHT AND LICENSE | ||
| 100 | |||
| 101 | This software is copyright (c) 2015 by Yanick Champoux. | ||
| 102 | |||
| 103 | This is free software; you can redistribute it and/or modify it under | ||
| 104 | the same terms as the Perl 5 programming language system itself. | ||
| 105 | |||
| 106 | =cut | ||