Server/Transport/Stdio.pm

filter: Statementstmt 39.5% 17 / 43 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 5 / 10 Podpod 100% 4 / 4 totaltotal 35.1% 26 / 74 CC 8 SCAR 28.2
CC
8
Cov
29%
handle_requests
42.0
new
6.0
configure
6.0
CRAP 16.8
↑ Summary Server.pm »
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
BranchTrueFalseTotal
if defined $server 0 0 0
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
BranchTrueFalseTotal
if (exists $params{"server"}) 0 0 0
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
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
42  
43 0 ▶ while ( my $line = <STDIN> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline STDIN)) 0 0 0
44 0 chomp $line;
45 0 ▶ next unless length $line;
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 0 0 0
46  
47 0 my $request = eval { decode_json($line) };
48 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
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
BranchTrueFalseTotal
if ($response) 0 0 0
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__
↑ Summary Server.pm »