| 1 | package Net::Async::MCP::Server::Transport::Stdio; | ||||||||||||||||||||
| 2 | # ABSTRACT: Stdio transport for Net::Async::MCP::Server | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use parent 'IO::Async::Notifier'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use Future::AsyncAwait; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use JSON::MaybeXS qw( encode_json decode_json ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | our $VERSION = '0.001'; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 16 | 0 | my ( $class, %params ) = @_; | |||||||||||||||||||
| 17 | 0 | my $server = delete $params{server}; | |||||||||||||||||||
| 18 | 0 | my $self = $class->SUPER::new(%params); | |||||||||||||||||||
| 19 | 0 | ▶ | $self->{server} = $server if defined $server; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | 0 | return $self; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | ▶ | sub configure { | ||||||||||||||||||
|
Subroutine
configure: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 24 | 0 | my ( $self, %params ) = @_; | |||||||||||||||||||
| 25 | 0 | ▶ | if ( exists $params{server} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 0 | $self->{server} = delete $params{server}; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | 0 | $self->SUPER::configure(%params); | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | ▶ | sub server { | ||||||||||||||||||
|
Subroutine
server: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 33 | 0 | my ( $self ) = @_; | |||||||||||||||||||
| 34 | 0 | return $self->{server}; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | ▶ | sub handle_requests { | ||||||||||||||||||
|
Subroutine
handle_requests: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||
| 39 | 0 | my ( $self ) = @_; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | ▶ | my $loop = $self->loop // IO::Async::Loop->new; | ||||||||||||||||||
|
Condition0%0/3
$self->loop // "IO::Async::Loop"->new
MC/DC0%0/2
$self->loop // "IO::Async::Loop"->new
$self->loop
"IO::Async::Loop"->new
Truth table0%0/3
A // B
A= $self->loopB= "IO::Async::Loop"->new
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | ▶ | while ( my $line = <STDIN> ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 0 | chomp $line; | |||||||||||||||||||
| 45 | 0 | ▶ | next unless length $line; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 0 | my $request = eval { decode_json($line) }; | |||||||||||||||||||
| 48 | 0 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 0 | $self->_send_response({ | |||||||||||||||||||
| 50 | jsonrpc => '2.0', | ||||||||||||||||||||
| 51 | id => undef, | ||||||||||||||||||||
| 52 | error => { code => -32700, message => 'Parse error' }, | ||||||||||||||||||||
| 53 | }); | ||||||||||||||||||||
| 54 | 0 | next; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | my $response = $self->server->handle($request); | |||||||||||||||||||
| 58 | 0 | ▶ | if ($response) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | 0 | $self->_send_response($response); | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | ▶ | sub _send_response { | ||||||||||||||||||
|
Subroutine
_send_response: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 65 | 0 | my ( $self, $response ) = @_; | |||||||||||||||||||
| 66 | 0 | print STDOUT encode_json($response) . "\n"; | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 1 | 1; | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||