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 34 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
108 34 ▶use parent "AnyEvent::MCP::Client";
Subroutine BEGIN: called CC=1 SCAR=0.0
109 34 ▶use AnyEvent::HTTP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
110 34 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
111 34 ▶use MIME::Base64 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
112 34 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
113 34 ▶use AnyEvent::MCP::Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 65 ▶sub new {
Subroutine new: called CC=9 SCAR=22.0
Pod documented
116 65 my ($class, %kv) = @_;
117  
118 65 ▶ if (defined $kv{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $kv{"name"}) 18 47 65
119 18 ▶ 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
216
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 18 ▶ (map { exists $settings->{$_} ? ($_ => $settings->{$_}) : () }
Branch: 1 branch
BranchTrueFalseTotal
exists $settings->{$_} ? : 6 48 54
122 qw(url bearer timeout)),
123 %kv,
124 );
125 }
126  
127 defined $kv{url}
128 65 ▶ or die "HTTP client requires a URL\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $kv{"url"} or die "HTTP client requires a URL\n" 65 0 65
129 !exists $kv{username} && !exists $kv{password}
130 65 ▶ 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 63 65
Condition66%2/3
exists $kv{"username"} or exists $kv{"password"}
l!l&&r!l&&!r
2063
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 63 ▶ 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 62 63
Condition100%3/3
defined $kv{"bearer"} and not $kv{"bearer"} =~ /\A[^\s]+\z/u
!ll&&!rl&&r
38241
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 62 $class->SUPER::new (timeout => 300, %kv)
134 }
135  
136 199 ▶sub _send {
Subroutine _send: called CC=20 SCAR=31.9
137 199 my ($self, $message, $done) = @_;
138  
139 my $key = exists $message->{id} && !exists $message->{result} && !exists $message->{error}
140 199 ▶ ? $message->{id} : "send:" . ++$self->{send_id};
Branch: 1 branch
BranchTrueFalseTotal
exists $message->{'id'} && !exists $message->{'result'} && !exists $message->{'error'} ? : 191 8 199
Condition66%4/6
exists $message->{"id"} and not exists $message->{"result"} and not exists $message->{"error"}
!ll&&!rl&&r
80191
exists $message->{"id"} and not exists $message->{"result"}
!ll&&!rl&&r
80191
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 199 my $generation = $self->{generation};
142 my %headers = (
143 199 ▶ %{$self->{headers} || {}},
Condition50%1/2
$self->{'headers'} || {}
l!l
0199
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 199 ▶ $headers{authorization} = "Bearer $self->{bearer}" if defined $self->{bearer};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"bearer"} 71 128 199
149 199 ▶ $headers{"mcp-protocol-version"} = $self->{protocol_version} if defined $self->{protocol_version};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"protocol_version"} 199 0 199
150 $headers{"mcp-session-id"} = $self->{session}
151 199 ▶ if $self->{protocol_version} lt "2026" && defined $self->{session};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"protocol_version"} lt 2026 and defined $self->{"session"} 4 195 199
Condition100%3/3
$self->{"protocol_version"} lt 2026 and defined $self->{"session"}
!ll&&!rl&&r
178174
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 199 ▶ 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"}) 177 22 199
Condition83%5/6
$self->{"protocol_version"} ge 2026 and exists $message->{"method"} and exists $message->{"id"}
!ll&&!rl&&r
211177
$self->{"protocol_version"} ge 2026 and exists $message->{"method"}
!ll&&!rl&&r
210178
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 177 $headers{"mcp-method"} = $message->{method};
155 177 ▶ 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 92 177
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 199 my ($buffer, $sse, $received, $failure) = ("", 0, 0);
164 199 ▶ my $limit = $self->{max_size} || 8 * 1024 * 1024;
Condition50%1/2
$self->{'max_size'} || 8388608
l!l
0199
MC/DC0%0/1
$self->{'max_size'} || 8388608
$self->{'max_size'}
Truth table50%1/2
A
A= $self->{'max_size'}
Aresult
11
00
165 199 weaken $self;
166  
167 184 ▶ my $deliver = sub {
Subroutine __ANON__: called CC=6 SCAR=19.9
168 184 my ($response) = @_;
169  
170 184 ▶ if (ref $response eq "HASH" && !exists $response->{method}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $response eq "HASH" and not exists $response->{"method"}) 182 2 184
Condition66%2/3
ref $response eq "HASH" and not exists $response->{"method"}
!ll&&!rl&&r
02182
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 182 ▶ && "$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 182 182
Condition33%2/6
exists $message->{"id"} and defined $response->{"id"} and qq[$response->{"id"}] eq qq[$message->{"id"}]
!ll&&!rl&&r
00182
exists $message->{"id"} and defined $response->{"id"}
!ll&&!rl&&r
00182
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 182 $received = 1;
175 }
176 184 $self->_receive ($response);
177 199 };
178  
179 199 my $guard;
180 199 my $ok = eval {
181 $guard = AnyEvent::HTTP::http_request POST => $self->{url},
182 1592 ▶ (map { exists $self->{$_} ? ($_ => $self->{$_}) : () }
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{$_} ? : 199 1393 1592
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 198 ▶ on_header => sub {
Subroutine __ANON__: called CC=7 SCAR=20.2
189 198 my ($hdr) = @_;
190  
191 198 ▶ return 0 unless $self && $self->{generation} == $generation;
Branch: 1 branch
BranchTrueFalseTotal
unless $self and $self->{"generation"} == $generation 0 198 198
Condition33%1/3
$self and $self->{"generation"} == $generation
!ll&&!rl&&r
00198
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 198 $sse = $hdr->{"content-type"} =~ m{\Atext/event-stream(?:\s*;|\z)}i;
193 198 ▶ 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 196 198
Condition77%7/9
$message->{"method"} eq "initialize" and $hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300 and defined $hdr->{"mcp-session-id"}
!ll&&!rl&&r
19152
$message->{"method"} eq "initialize" and $hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300
!ll&&!rl&&r
19107
$message->{"method"} eq "initialize" and $hdr->{"Status"} >= 200
!ll&&!rl&&r
19107
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 198 },
199 211 ▶ on_body => sub {
Subroutine __ANON__: called CC=9 SCAR=23.0
200 211 my ($chunk, $hdr) = @_;
201  
202 211 ▶ return 0 unless $self && $self->{generation} == $generation;
Branch: 1 branch
BranchTrueFalseTotal
unless $self and $self->{"generation"} == $generation 0 211 211
Condition33%1/3
$self and $self->{"generation"} == $generation
!ll&&!rl&&r
00211
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 211 $buffer .= $chunk;
204  
205 211 my $ok = eval {
206 211 ▶ if ($sse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sse) 5 206 211
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 211 ▶ die "HTTP response exceeds size limit\n" if length $buffer > $limit;
Branch: 1 branch
BranchTrueFalseTotal
if length $buffer > $limit 0 211 211
215 211 1
216 };
217 211 ▶ $failure = $@ unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 211 211
218 211 $ok
219 },
220 199 ▶ sub {
Subroutine __ANON__: called CC=19 SCAR=31.7
221 199 my (undef, $hdr) = @_;
222  
223 199 ▶ return unless $self && $self->{generation} == $generation;
Branch: 1 branch
BranchTrueFalseTotal
unless $self and $self->{"generation"} == $generation 0 199 199
Condition33%1/3
$self and $self->{"generation"} == $generation
!ll&&!rl&&r
00199
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 199 delete $self->{http_requests}{$key};
225  
226 199 ▶ if ($hdr->{Status} == 404 && defined $self->{session} && !$received) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdr->{"Status"} == 404 and defined $self->{"session"} and not $received) 2 197 199
Condition83%5/6
$hdr->{"Status"} == 404 and defined $self->{"session"} and not $received
!ll&&!rl&&r
19702
$hdr->{"Status"} == 404 and defined $self->{"session"}
!ll&&!rl&&r
19342
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 197 my $ok = eval {
231 197 ▶ die $failure if $failure;
Branch: 1 branch
BranchTrueFalseTotal
if $failure 0 197 197
232 197 ▶ if (!$sse && length $buffer) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $sse and length $buffer) 180 17 197
Condition100%3/3
not $sse and length $buffer
!ll&&!rl&&r
215180
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 180 my $response = eval { JSON::XS::decode_json $buffer };
234 180 ▶ 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') { } 180 0 180
Condition55%5/9
ref $response eq "HASH" and $hdr->{"Status"} >= 200 && $hdr->{"Status"} < 300 || ref $response->{"error"} eq "HASH"
!ll&&!rl&&r
00180
$hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300 or ref $response->{"error"} eq "HASH"
l!l&&r!l&&!r
17460
$hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300
!ll&&!rl&&r
06174
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 180 $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 197 ▶ unless $hdr->{Status} >= 200 && $hdr->{Status} < 300;
Branch: 1 branch
BranchTrueFalseTotal
unless $hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300 13 184 197
Condition66%2/3
$hdr->{"Status"} >= 200 and $hdr->{"Status"} < 300
!ll&&!rl&&r
013184
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 184 ▶ if exists $message->{id} && exists $message->{method} && !$received;
Branch: 1 branch
BranchTrueFalseTotal
if exists $message->{"id"} and exists $message->{"method"} and not $received 0 184 184
Condition66%4/6
exists $message->{"id"} and exists $message->{"method"} and not $received
!ll&&!rl&&r
81760
exists $message->{"id"} and exists $message->{"method"}
!ll&&!rl&&r
80176
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 184 1
247 };
248 197 ▶ $done->($ok ? (1, undef) : (0, { transport => 1, message => "$@" }));
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 184 13 197
249 199 };
250 199 1
251 };
252 199 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) { } 199 0 199
253 199 ▶ $self->{http_requests}{$key} = $guard if $self && $guard;
Branch: 1 branch
BranchTrueFalseTotal
if $self and $guard 199 0 199
Condition33%1/3
$self and $guard
!ll&&!rl&&r
00199
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 116 ▶sub _shutdown {
Subroutine _shutdown: called CC=1 SCAR=0.0
266 116 my ($self) = @_;
267  
268 116 delete @$self{qw(http_requests session)};
269 }
270  
271 34 1
« blib/lib/AnyEvent/MCP/Client.pm ↑ Summary blib/lib/AnyEvent/MCP/Workdirs.pm »