blib/lib/AnyEvent/MCP/Client/HTTP.pm

filter: Statementstmt 96.0% 98 / 102 Branchbran 77.1% 54 / 70 Conditioncond 65.4% 55 / 84 MC/DCmcdc 36.9% 17 / 46 Subroutinesub 93.3% 14 / 15 Podpod 100% 1 / 1 totaltotal 75.1% 239 / 318 CC 65 SCAR 27.4
CC
65
Cov
81%
_send
24.4
__ANON__
23.9
__ANON__
9.9
CRAP 15.4
« blib/lib/AnyEvent/MCP/Client.pm ↑ Summary blib/lib/AnyEvent/MCP/Workdirs.pm »
1 =head1 NAME
2  
3 AnyEvent::MCP::Client::HTTP - MCP over AnyEvent::HTTP
4  
5 =head1 SYNOPSIS
6  
7 use AnyEvent::MCP::Client::HTTP;
8  
9 my $client = AnyEvent::MCP::Client::HTTP->new (
10 name => "example", url => $url, bearer => $token,
11 timeout => 30,
12 );
13  
14 =head1 DESCRIPTION
15  
16 Use this transport to talk to an MCP server through HTTP. The caller supplies
17 the endpoint and, if needed, credentials; the common Client layer handles
18 discovery and tool calls. Unlike a browser, this client does not follow
19 redirects or silently retry requests. A redirected request could disclose
20 credentials to another host, and retrying a tool call could perform an
21 operation twice.
22  
23 =head1 FIRST CALL
24  
25 For a bundled MCP server already listening on HTTP, use the full URL
26 it prints with C<--print-url>:
27  
28 use AnyEvent;
29 use AnyEvent::MCP::Client::HTTP;
30  
31 my $client = AnyEvent::MCP::Client::HTTP->new (
32 url => "http://127.0.0.1:31740/TOKEN/",
33 );
34 my $cv = AE::cv;
35 $client->call (workdirs => {}, sub { $cv->send (@_) });
36 my ($success, $result) = $cv->recv;
37 $success or die "$result->{message}\n";
38 !$result->{isError} or die "$result->{content}[0]{text}\n";
39  
40 Replace the example URL with the actual credential-bearing URL. The
41 common L<AnyEvent::MCP::Client> layer negotiates MCP and handles
42 callbacks. A successful JSON-RPC exchange can still return a tool error
43 as C<isError>; always inspect both.
44  
45 =head1 METHODS
46  
47 =over
48  
49 =item $client = AnyEvent::MCP::Client::HTTP->new (%config)
50  
51 Accepts the common L<AnyEvent::MCP::Client> options and these transport
52 options. Options are flat, rather than nested in an HTTP configuration hash.
53  
54 =over
55  
56 =item url => $url
57  
58 Complete endpoint URL, optionally including a URL-path token. Required
59 unless supplied by the named client configuration.
60  
61 =item bearer => $token
62  
63 Supplies C<Authorization: Bearer TOKEN>. Without it, the URL alone is
64 used; a bearer token is not inferred from a URL. The server must accept
65 the selected credential. With the bundled servers, the URL-path token
66 and bearer header present the same static credential.
67  
68 =item name => $name
69  
70 Loads C<url>, C<bearer> and C<timeout> defaults from C<[client NAME]>.
71 Explicit constructor arguments override them, including explicitly undefined
72 credentials. Without a name no global configuration is accessed.
73  
74 =item timeout => $seconds
75  
76 HTTP inactivity timeout, defaulting to 300 seconds. Use the common
77 C<request_timeout> option for an overall tool-call deadline.
78  
79 =item headers => { %headers }
80  
81 Additional HTTP headers. Protocol headers and an explicitly configured
82 bearer header are supplied by this module.
83  
84 =item max_size => $bytes
85  
86 Bounds a JSON response or an individual buffered SSE event, defaulting to
87 8 MiB. SSE notifications are delivered incrementally rather than after
88 the HTTP response ends.
89  
90 =back
91  
92 C<proxy>, C<tls_ctx>, C<handle_params>, C<sessionid>, C<on_prepare>,
93 C<on_connect> and C<tcp_connect> are passed to L<AnyEvent::HTTP>.
94 No HTTP cookies or Basic authentication are supplied by this module.
95 Redirects and automatic HTTP retries are disabled.
96  
97 Legacy session IDs are retained from initialization. An expired session fails
98 outstanding requests; a later operation can initialize again. Legacy GET
99 streams and the old separate SSE endpoint transport are not implemented.
100  
101 =back
102  
103 =cut
104  
105 package AnyEvent::MCP::Client::HTTP;
106  
107 33 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 33 ▶use parent "AnyEvent::MCP::Client";
Subroutine BEGIN: called CC=1 SCAR=0.0
109 33 ▶use AnyEvent::HTTP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
110 33 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
111 33 ▶use MIME::Base64 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
112 33 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
113 33 ▶use AnyEvent::MCP::Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 64 ▶sub new {
Subroutine new: called CC=9 SCAR=22.0
Pod documented
116 64 my ($class, %kv) = @_;
117  
118 64 ▶ if (defined $kv{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $kv{"name"}) 17 47 64
119 17 ▶ my $settings = (AnyEvent::MCP::Config::global_config)->{section}{"client $kv{name}"} || {};
Condition100%2/2
AnyEvent::MCP::Config::global_config()->{'section'}{"client $kv{'name'}"} || {}
l!l
215
MC/DC100%1/1
AnyEvent::MCP::Config::global_config()->{'section'}{"client $kv{'name'}"} || {}
AnyEvent::MCP::Config::global_config()->{'section'}{"client $kv{'name'}"}
Truth table100%2/2
A
A= AnyEvent::MCP::Config::global_config()->{'section'}{"client $kv{'name'}"}
Aresult
11
00
120 %kv = (
121 17 ▶ (map { exists $settings->{$_} ? ($_ => $settings->{$_}) : () }
Branch: 1 branch
BranchTrueFalseTotal
exists $settings->{$_} ? : 6 45 51
122 qw(url bearer timeout)),
123 %kv,
124 );
125 }
126  
127 defined $kv{url}
128 64 ▶ or die "HTTP client requires a URL\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $kv{"url"} or die "HTTP client requires a URL\n" 64 0 64
129 !exists $kv{username} && !exists $kv{password}
130 64 ▶ or die "HTTP Basic authentication is unsupported\n";
Branch: 1 branch
BranchTrueFalseTotal
exists $kv{"username"} || exists $kv{"password"} and die "HTTP Basic authentication is unsupported\n" 2 62 64
Condition66%2/3
exists $kv{"username"} or exists $kv{"password"}
l!l&&r!l&&!r
2062
MC/DC50%1/2
exists $kv{"username"} or exists $kv{"password"}
exists $kv{"username"} exists $kv{"password"}
Truth table66%2/3
A or B
A= exists $kv{"username"}B= exists $kv{"password"}
ABresult
1X1
011
000
131 62 ▶ die "Invalid bearer token\n" if defined $kv{bearer} && $kv{bearer} !~ /\A[^\s]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $kv{"bearer"} and not $kv{"bearer"} =~ /\A[^\s]+\z/u 1 61 62
Condition100%3/3
defined $kv{"bearer"} and not $kv{"bearer"} =~ /\A[^\s]+\z/u
!ll&&!rl&&r
37241
MC/DC100%2/2
defined $kv{"bearer"} and not $kv{"bearer"} =~ /\A[^\s]+\z/u
defined $kv{"bearer"} not $kv{"bearer"} =~ /\A[^\s]+\z/u
Truth table100%3/3
A and not(B)
A= defined $kv{"bearer"}B= not $kv{"bearer"} =~ /\A[^\s]+\z/u
ABresult
0X0
100
111
132  
133 61 $class->SUPER::new (timeout => 300, %kv)
134 }
135  
136 188 ▶sub _send {
Subroutine _send: called CC=20 SCAR=31.9
137 188 my ($self, $message, $done) = @_;
138  
139 my $key = exists $message->{id} && !exists $message->{result} && !exists $message->{error}
140 188 ▶ ? $message->{id} : "send:" . ++$self->{send_id};
Branch: 1 branch
BranchTrueFalseTotal
exists $message->{'id'} && !exists $message->{'result'} && !exists $message->{'error'} ? : 180 8 188
Condition66%4/6
exists $message->{"id"} and not exists $message->{"result"} and not exists $message->{"error"}
!ll&&!rl&&r
80180
exists $message->{"id"} and not exists $message->{"result"}
!ll&&!rl&&r
80180
MC/DC33%1/3
exists $message->{"id"} and not exists $message->{"result"} and not exists $message->{"error"}
exists $message->{"id"} not exists $message->{"result"} not exists $message->{"error"}
Truth table50%2/4
A and not(B) and not(C)
A= exists $message->{"id"}B= not exists $message->{"result"}C= not exists $message->{"error"}
ABCresult
0XX0
10X0
1100
1111
141 188 my $generation = $self->{generation};
142 my %headers = (
143 188 ▶ %{$self->{headers} || {}},
Condition50%1/2
$self->{'headers'} || {}
l!l
0188
MC/DC0%0/1
$self->{'headers'} || {}
$self->{'headers'}
Truth table50%1/2
A
A= $self->{'headers'}
Aresult
11
00
144 "content-type" => "application/json",
145 accept => "application/json, text/event-stream",
146 );
147  
148 188 ▶ $headers{authorization} = "Bearer $self->{bearer}" if defined $self->{bearer};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"bearer"} 66 122 188
149 188 ▶ $headers{"mcp-protocol-version"} = $self->{protocol_version} if defined $self->{protocol_version};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"protocol_version"} 188 0 188
150 $headers{"mcp-session-id"} = $self->{session}
151 188 ▶ if $self->{protocol_version} lt "2026" && defined $self->{session};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"protocol_version"} lt 2026 and defined $self->{"session"} 4 184 188
Condition100%3/3
$self->{"protocol_version"} lt 2026 and defined $self->{"session"}
!ll&&!rl&&r
167174
MC/DC100%2/2
$self->{"protocol_version"} lt 2026 and defined $self->{"session"}
$self->{"protocol_version"} lt 2026 defined $self->{"session"}
Truth table100%3/3
A and B
A= $self->{"protocol_version"} lt 2026B= defined $self->{"session"}
ABresult
0X0
100
111
152  
153 188 ▶ if ($self->{protocol_version} ge "2026" && exists $message->{method} && exists $message->{id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"protocol_version"} ge 2026 and exists $message->{"method"} and exists $message->{"id"}) 166 22 188
Condition83%5/6
$self->{"protocol_version"} ge 2026 and exists $message->{"method"} and exists $message->{"id"}
!ll&&!rl&&r
211166
$self->{"protocol_version"} ge 2026 and exists $message->{"method"}
!ll&&!rl&&r
210167
MC/DC66%2/3
$self->{"protocol_version"} ge 2026 and exists $message->{"method"} and exists $message->{"id"}
$self->{"protocol_version"} ge 2026 exists $message->{"method"} exists $message->{"id"}
Truth table75%3/4
A and B and C
A= $self->{"protocol_version"} ge 2026B= exists $message->{"method"}C= exists $message->{"id"}
ABCresult
0XX0
10X0
1100
1111
154 166 $headers{"mcp-method"} = $message->{method};
155 166 ▶ if ($message->{method} =~ /\A(?:tools\/call|prompts\/get|resources\/read)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message->{"method"} =~ m[\A(?:tools/call|prompts/get|resources/read)\z]u) 85 81 166
156 85 ▶ my $name = exists $message->{params}{name} ? $message->{params}{name} : $message->{params}{uri};
Branch: 1 branch
BranchTrueFalseTotal
exists $message->{'params'}{'name'} ? : 85 0 85
157 85 ▶ $headers{"mcp-name"} = $name =~ /[^\x20-\x7e]/
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /[^\x20-\x7e]/u ? : 1 84 85
158 ? "=?base64?" . MIME::Base64::encode_base64 (AnyEvent::MCP::utf8enc ($name), "") . "?="
159 : $name;
160 }
161 }
162  
163 188 my ($buffer, $sse, $received, $failure) = ("", 0, 0);
164 188 ▶ my $limit = $self->{max_size} || 8 * 1024 * 1024;
Condition50%1/2
$self->{'max_size'} || 8388608
l!l
0188
MC/DC0%0/1
$self->{'max_size'} || 8388608
$self->{'max_size'}
Truth table50%1/2
A
A= $self->{'max_size'}
Aresult
11
00
165 188 weaken $self;
166  
167 173 ▶ my $deliver = sub {
Subroutine __ANON__: called CC=6 SCAR=19.9
168 173 my ($response) = @_;
169  
170 173 ▶ if (ref $response eq "HASH" && !exists $response->{method}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $response eq "HASH" and not exists $response->{"method"}) 171 2 173
Condition66%2/3
ref $response eq "HASH" and not exists $response->{"method"}
!ll&&!rl&&r
02171
MC/DC50%1/2
ref $response eq "HASH" and not exists $response->{"method"}
ref $response eq "HASH" not exists $response->{"method"}
Truth table66%2/3
A and not(B)
A= ref $response eq "HASH"B= not exists $response->{"method"}
ABresult
0X0
100
111
171 die "HTTP response id mismatch\n"
172 unless exists $message->{id} && defined $response->{id}
173 171 ▶ && "$response->{id}" eq "$message->{id}";
Branch: 1 branch
BranchTrueFalseTotal
unless exists $message->{"id"} and defined $response->{"id"} and qq[$response->{"id"}] eq qq[$message->{"id"}] 0 171 171
Condition33%2/6
exists $message->{"id"} and defined $response->{"id"} and qq[$response->{"id"}] eq qq[$message->{"id"}]
!ll&&!rl&&r
00171
exists $message->{"id"} and defined $response->{"id"}
!ll&&!rl&&r
00171
MC/DC0%0/3
exists $message->{"id"} and defined $response->{"id"} and qq[$response->{"id"}] eq qq[$message->{"id"}]
exists $message->{"id"} defined $response->{"id"} qq[$response->{"id"}] eq qq[$message->{"id"}]
Truth table25%1/4
A and B and C
A= exists $message->{"id"}B= defined $response->{"id"}C= qq[$response->{"id"}] eq qq[$message->{"id"}]
ABCresult
0XX0
10X0
1100
1111
174 171 $received = 1;
175 }
176 173 $self->_receive ($response);
177 188 };
178  
179 188 my $guard;
180 188 my $ok = eval {
181 $guard = AnyEvent::HTTP::http_request POST => $self->{url},
182 1504 ▶ (map { exists $self->{$_} ? ($_ => $self->{$_}) : () }
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{$_} ? : 188 1316 1504
183 qw(timeout proxy tls_ctx handle_params sessionid on_prepare on_connect tcp_connect)),
184 headers => \%headers,
185 body => JSON::XS::encode_json ($message),
186 recurse => 0,
187 persistent => 0,
188 187 ▶ on_header => sub {
Subroutine __ANON__: called CC=7 SCAR=20.2
189 187 my ($hdr) = @_;
190  
191 187 ▶ return 0 unless $self && $self->{generation} == $generation;
Branch: 1 branch
BranchTrueFalseTotal
unless $self and $self->{"generation"} == $generation 0 187 187
Condition33%1/3
$self and $self->{"generation"} == $generation
!ll&&!rl&&r
00187
MC/DC0%0/2
$self and $self->{"generation"} == $generation
$self $self->{"generation"} == $generation
Truth table33%1/3
A and B
A= $selfB= $self->{"generation"} == $generation
ABresult
0X0
100
111
192 187 $sse = $hdr->{"content-type"} =~ m{\Atext/event-stream(?:\s*;|\z)}i;
193 187 ▶ if ($message->{method} eq "initialize" && $hdr->{Status} >= 200 && $hdr->{Status} < 300
Branch: 1 branch
BranchTrueFalseTotal
if ($message->{"method"} eq "initialize" and $hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300 and defined $hdr->{"mcp-session-id"}) 2 185 187
Condition77%7/9
$message->{"method"} eq "initialize" and $hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300 and defined $hdr->{"mcp-session-id"}
!ll&&!rl&&r
18052
$message->{"method"} eq "initialize" and $hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300
!ll&&!rl&&r
18007
$message->{"method"} eq "initialize" and $hdr->{"Status"} >= 200
!ll&&!rl&&r
18007
MC/DC50%2/4
$message->{"method"} eq "initialize" and $hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300 and defined $hdr->{"mcp-session-id"}
$message->{"method"} eq "initialize" $hdr->{"Status"} >= 200 $hdr->{"Status"} < 300 defined $hdr->{"mcp-session-id"}
Truth table60%3/5
A and B and C and D
A= $message->{"method"} eq "initialize"B= $hdr->{"Status"} >= 200C= $hdr->{"Status"} < 300D= defined $hdr->{"mcp-session-id"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
194 && defined $hdr->{"mcp-session-id"}) {
195 2 $self->{session} = $hdr->{"mcp-session-id"};
196 }
197 1
198 187 },
199 175 ▶ on_body => sub {
Subroutine __ANON__: called CC=9 SCAR=23.0
200 175 my ($chunk, $hdr) = @_;
201  
202 175 ▶ return 0 unless $self && $self->{generation} == $generation;
Branch: 1 branch
BranchTrueFalseTotal
unless $self and $self->{"generation"} == $generation 0 175 175
Condition33%1/3
$self and $self->{"generation"} == $generation
!ll&&!rl&&r
00175
MC/DC0%0/2
$self and $self->{"generation"} == $generation
$self $self->{"generation"} == $generation
Truth table33%1/3
A and B
A= $selfB= $self->{"generation"} == $generation
ABresult
0X0
100
111
203 175 $buffer .= $chunk;
204  
205 175 my $ok = eval {
206 175 ▶ if ($sse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sse) 5 170 175
207 5 ▶ while ($buffer =~ s/\A(.*?)(?:\r\n\r\n|\n\n|\r\r)//s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer =~ s/\A(.*?)(?:\r\n\r\n|\n\n|\r\r)//su) 4 5 9
208 4 my $event = $1;
209 4 ▶ die "SSE event exceeds size limit\n" if length $event > $limit;
Branch: 1 branch
BranchTrueFalseTotal
if length $event > $limit 0 4 4
210 4 my @data = $event =~ /^data:[ \t]?(.*?)(?:\r?$)/mg;
211 4 ▶ $deliver->(JSON::XS::decode_json join "\n", @data) if @data;
Branch: 1 branch
BranchTrueFalseTotal
if @data 4 0 4
212 }
213 }
214 175 ▶ die "HTTP response exceeds size limit\n" if length $buffer > $limit;
Branch: 1 branch
BranchTrueFalseTotal
if length $buffer > $limit 0 175 175
215 175 1
216 };
217 175 ▶ $failure = $@ unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 175 175
218 175 $ok
219 },
220 188 ▶ sub {
Subroutine __ANON__: called CC=19 SCAR=31.7
221 188 my (undef, $hdr) = @_;
222  
223 188 ▶ return unless $self && $self->{generation} == $generation;
Branch: 1 branch
BranchTrueFalseTotal
unless $self and $self->{"generation"} == $generation 0 188 188
Condition33%1/3
$self and $self->{"generation"} == $generation
!ll&&!rl&&r
00188
MC/DC0%0/2
$self and $self->{"generation"} == $generation
$self $self->{"generation"} == $generation
Truth table33%1/3
A and B
A= $selfB= $self->{"generation"} == $generation
ABresult
0X0
100
111
224 188 delete $self->{http_requests}{$key};
225  
226 188 ▶ if ($hdr->{Status} == 404 && defined $self->{session} && !$received) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdr->{"Status"} == 404 and defined $self->{"session"} and not $received) 2 186 188
Condition83%5/6
$hdr->{"Status"} == 404 and defined $self->{"session"} and not $received
!ll&&!rl&&r
18602
$hdr->{"Status"} == 404 and defined $self->{"session"}
!ll&&!rl&&r
18242
MC/DC66%2/3
$hdr->{"Status"} == 404 and defined $self->{"session"} and not $received
$hdr->{"Status"} == 404 defined $self->{"session"} not $received
Truth table75%3/4
A and B and not(C)
A= $hdr->{"Status"} == 404B= defined $self->{"session"}C= not $received
ABCresult
0XX0
10X0
1100
1111
227 2 return $self->close ("MCP session expired")
228 }
229  
230 186 my $ok = eval {
231 186 ▶ die $failure if $failure;
Branch: 1 branch
BranchTrueFalseTotal
if $failure 0 186 186
232 186 ▶ if (!$sse && length $buffer) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $sse and length $buffer) 169 17 186
Condition100%3/3
not $sse and length $buffer
!ll&&!rl&&r
215169
MC/DC100%2/2
not $sse and length $buffer
not $sse length $buffer
Truth table100%3/3
not(A) and B
A= not $sseB= length $buffer
ABresult
0X0
100
111
233 169 my $response = eval { JSON::XS::decode_json $buffer };
234 169 ▶ if (ref $response eq "HASH" && ($hdr->{Status} >= 200 && $hdr->{Status} < 300
Branch: 1 branch
BranchTrueFalseTotal
if (ref $response eq 'HASH' and $hdr->{'Status'} >= 200 && $hdr->{'Status'} < 300 || ref $response->{'error'} eq 'HASH') { } 169 0 169
Condition55%5/9
ref $response eq "HASH" and $hdr->{"Status"} >= 200 && $hdr->{"Status"} < 300 || ref $response->{"error"} eq "HASH"
!ll&&!rl&&r
00169
$hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300 or ref $response->{"error"} eq "HASH"
l!l&&r!l&&!r
16360
$hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300
!ll&&!rl&&r
06163
MC/DC0%0/4
ref $response eq "HASH" and $hdr->{"Status"} >= 200 && $hdr->{"Status"} < 300 || ref $response->{"error"} eq "HASH"
ref $response eq "HASH" $hdr->{"Status"} >= 200 $hdr->{"Status"} < 300 ref $response->{"error"} eq "HASH"
Truth table33%2/6
A and B and C or D
A= ref $response eq "HASH"B= $hdr->{"Status"} >= 200C= $hdr->{"Status"} < 300D= ref $response->{"error"} eq "HASH"
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
235 || ref $response->{error} eq "HASH")) {
236 169 $deliver->($response);
237 } else {
238 0 die "HTTP $hdr->{Status} $hdr->{Reason}\n"
239 }
240 }
241  
242 die "HTTP $hdr->{Status} $hdr->{Reason}\n"
243 186 ▶ unless $hdr->{Status} >= 200 && $hdr->{Status} < 300;
Branch: 1 branch
BranchTrueFalseTotal
unless $hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300 13 173 186
Condition66%2/3
$hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300
!ll&&!rl&&r
013173
MC/DC50%1/2
$hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300
$hdr->{"Status"} >= 200 $hdr->{"Status"} < 300
Truth table66%2/3
A and B
A= $hdr->{"Status"} >= 200B= $hdr->{"Status"} < 300
ABresult
0X0
100
111
244 die "HTTP response has no matching JSON-RPC reply\n"
245 173 ▶ if exists $message->{id} && exists $message->{method} && !$received;
Branch: 1 branch
BranchTrueFalseTotal
if exists $message->{"id"} and exists $message->{"method"} and not $received 0 173 173
Condition66%4/6
exists $message->{"id"} and exists $message->{"method"} and not $received
!ll&&!rl&&r
81650
exists $message->{"id"} and exists $message->{"method"}
!ll&&!rl&&r
80165
MC/DC0%0/3
exists $message->{"id"} and exists $message->{"method"} and not $received
exists $message->{"id"} exists $message->{"method"} not $received
Truth table50%2/4
A and B and not(C)
A= exists $message->{"id"}B= exists $message->{"method"}C= not $received
ABCresult
0XX0
10X0
1100
1111
246 173 1
247 };
248 186 ▶ $done->($ok ? (1, undef) : (0, { transport => 1, message => "$@" }));
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 173 13 186
249 188 };
250 188 1
251 };
252 188 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 188 0 188
253 188 ▶ $self->{http_requests}{$key} = $guard if $self && $guard;
Branch: 1 branch
BranchTrueFalseTotal
if $self and $guard 188 0 188
Condition33%1/3
$self and $guard
!ll&&!rl&&r
00188
MC/DC0%0/2
$self and $guard
$self $guard
Truth table33%1/3
A and B
A= $selfB= $guard
ABresult
0X0
100
111
254 } else {
255 0 $done->(0, { transport => 1, message => "$@" });
256 }
257 }
258  
259 0 ▶sub _abort {
Subroutine _abort: not called CC=1 SCAR=6.9
260 0 my ($self, $id) = @_;
261  
262 0 delete $self->{http_requests}{$id};
263 }
264  
265 115 ▶sub _shutdown {
Subroutine _shutdown: called CC=1 SCAR=0.0
266 115 my ($self) = @_;
267  
268 115 delete @$self{qw(http_requests session)};
269 }
270  
271 33 1
« blib/lib/AnyEvent/MCP/Client.pm ↑ Summary blib/lib/AnyEvent/MCP/Workdirs.pm »