| 1 | package Neovim::Ext::MsgPack::RPC::Stream; | ||||||||||||||||||||
| 2 | 56 | $Neovim::Ext::MsgPack::RPC::Stream::VERSION = '0.01'; | |||||||||||||||||||
| 3 | 56 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 56 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 56 | ▶ | use base qw/Class::Accessor/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 56 | ▶ | use MsgPack::Raw; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 56 | __PACKAGE__->mk_accessors (qw/loop packer unpacker message_cb/); | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | sub new | ||||||||||||||||||||
| 11 | { | ||||||||||||||||||||
| 12 | 43 | ▶ | my ($this, $loop) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 43 | ▶ | my $class = ref ($this) || $this; | ||||||||||||||||||
|
Condition33%1/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table33%1/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||
| 15 | 43 | my $self = | |||||||||||||||||||
| 16 | { | ||||||||||||||||||||
| 17 | loop => $loop, | ||||||||||||||||||||
| 18 | packer => MsgPack::Raw::Packer->new(), | ||||||||||||||||||||
| 19 | unpacker => MsgPack::Raw::Unpacker->new(), | ||||||||||||||||||||
| 20 | }; | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 43 | return bless $self, $class; | |||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | sub run | ||||||||||||||||||||
| 28 | { | ||||||||||||||||||||
| 29 | 61 | ▶ | my ($this, $message_cb, $setup_cb) = @_; | ||||||||||||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 30 | 61 | $this->message_cb ($message_cb); | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | $this->loop->run (sub | ||||||||||||||||||||
| 33 | { | ||||||||||||||||||||
| 34 | 84 | ▶ | $this->_on_data (@_); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | 61 | }, $setup_cb | |||||||||||||||||||
| 36 | ); | ||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | sub stop | ||||||||||||||||||||
| 42 | { | ||||||||||||||||||||
| 43 | 18 | ▶ | my ($this) = @_; | ||||||||||||||||||
|
Subroutine
stop: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 44 | 18 | $this->loop->stop(); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | sub close | ||||||||||||||||||||
| 50 | { | ||||||||||||||||||||
| 51 | 0 | ▶ | my ($this) = @_; | ||||||||||||||||||
|
Subroutine
close: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 52 | 0 | $this->loop->close(); | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | sub send | ||||||||||||||||||||
| 58 | { | ||||||||||||||||||||
| 59 | 104 | ▶ | my ($this, $msg) = @_; | ||||||||||||||||||
|
Subroutine
send: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 60 | 104 | $this->loop->send ($this->packer->pack ($msg)); | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | sub create_future | ||||||||||||||||||||
| 66 | { | ||||||||||||||||||||
| 67 | 61 | ▶ | my ($this) = @_; | ||||||||||||||||||
|
Subroutine
create_future: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 68 | 61 | return $this->loop->create_future(); | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | sub await | ||||||||||||||||||||
| 74 | { | ||||||||||||||||||||
| 75 | 0 | ▶ | my ($this, $future) = @_; | ||||||||||||||||||
|
Subroutine
await: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 76 | 0 | $this->loop->await ($future); | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | sub _on_data | ||||||||||||||||||||
| 82 | { | ||||||||||||||||||||
| 83 | 84 | ▶ | my ($this, $data) = @_; | ||||||||||||||||||
|
Subroutine
_on_data: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 84 | $this->unpacker->feed ($data); | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 102 | AGAIN: | |||||||||||||||||||
| 88 | my $result = $this->unpacker->next; | ||||||||||||||||||||
| 89 | 102 | ▶ | if ($result) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | { | ||||||||||||||||||||
| 91 | 18 | $this->message_cb->($result); | |||||||||||||||||||
| 92 | 18 | goto AGAIN; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =head1 NAME | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | Neovim::Ext::MsgPack::RPC::Stream - Neovim::Ext::MsgPack::RPC::Stream class | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =head1 VERSION | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | version 0.01 | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | =head1 SYNOPSIS | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | use Neovim::Ext; | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =head1 METHODS | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | =head2 run( \&message_cb ) | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | Run the event loop to receive messages from Nvim. While the event | ||||||||||||||||||||
| 113 | loop is running, C<\&message_cb> will be called whenever a message | ||||||||||||||||||||
| 114 | is received. | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =head2 stop( ) | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | Stop the event loop. | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | =head2 send( $msg ) | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | Queue C<$msg> for sending to Nvim. | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =head2 close( ) | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | Close the event loop. | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | =head2 create_future( ) | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | Create a future. | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | =head2 await( $future ) | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | Wait for C<$future> to complete. | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | 56 | 1; | |||||||||||||||||||