blib/lib/Discord/Client/Interactions.pm

filter: Statementstmt 96.9% 157 / 162 Branchbran 79.2% 65 / 82 Conditioncond 75.0% 54 / 72 MC/DCmcdc 53.6% 22 / 41 Subroutinesub 100% 25 / 25 Podpod 100% 4 / 4 totaltotal 84.7% 327 / 386 CC 72 SCAR 25.7
CC
72
Cov
87%
handle
22.6
new
20.5
_check_job
16.0
CRAP 13.1
« blib/lib/Discord/Client/Gateway/IdentifyLimiter.pm ↑ Summary blib/lib/Discord/Client/UI.pm »
1 package Discord::Client::Interactions;
2  
3 9 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use IO::Async::Loop;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Scalar::Util qw(blessed refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Discord::Client::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Discord::Client::Interaction;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 9 our $VERSION = '0.002';
14  
15 51 ▶sub new {
Subroutine new: called CC=15 SCAR=30.2
Pod documented
16 51 my ( $class, %args ) = @_;
17  
18 # Validate bounded work and replay settings before accepting any payloads.
19 51 ▶ croak 'A command registry is required' unless $args{commands};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"commands"} 0 51 51
20 51 for my $key (qw(max_pending max_seen seen_ttl)) {
21 croak "$key must be a positive integer"
22 if exists( $args{$key} )
23 153 ▶ && ( !defined( $args{$key} ) || ref( $args{$key} ) || $args{$key} !~ /\A[1-9]\d*\z/ );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$key} and !defined($args{$key}) || ref $args{$key} || !($args{$key} =~ /\A[1-9]\d*\z/u) 0 153 153
Condition44%4/9
exists $args{$key} and !defined($args{$key}) || ref $args{$key} || !($args{$key} =~ /\A[1-9]\d*\z/u)
!ll&&!rl&&r
96570
not defined $args{$key} or ref $args{$key} or not $args{$key} =~ /\A[1-9]\d*\z/u
l!l&&r!l&&!r
0057
not defined $args{$key} or ref $args{$key}
l!l&&r!l&&!r
0057
MC/DC0%0/4
exists $args{$key} and !defined($args{$key}) || ref $args{$key} || !($args{$key} =~ /\A[1-9]\d*\z/u)
exists $args{$key} not defined $args{$key} ref $args{$key} not $args{$key} =~ /\A[1-9]\d*\z/u
Truth table40%2/5
A and not(B) or C or not(D)
A= exists $args{$key}B= not defined $args{$key}C= ref $args{$key}D= not $args{$key} =~ /\A[1-9]\d*\z/u
ABCDresult
0XXX0
10000
11XX1
101X1
10011
24 }
25 51 for my $key (qw(clock delay on_error)) {
26 153 ▶ croak "$key must be a code reference" if exists( $args{$key} ) && ref( $args{$key} ) ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$key} and ref $args{$key} ne "CODE" 0 153 153
Condition66%2/3
exists $args{$key} and ref $args{$key} ne "CODE"
!ll&&!rl&&r
311220
MC/DC0%0/2
exists $args{$key} and ref $args{$key} ne "CODE"
exists $args{$key} ref $args{$key} ne "CODE"
Truth table66%2/3
A and B
A= exists $args{$key}B= ref $args{$key} ne "CODE"
ABresult
0X0
100
111
27 }
28  
29 # Keep active work separate from retained IDs used to suppress duplicate effects.
30 return bless {
31 loop => $args{loop} // IO::Async::Loop->new,
32 commands => $args{commands},
33 rest => $args{rest},
34 6 ▶ clock => $args{clock} // sub { clock_gettime(CLOCK_MONOTONIC) },
Subroutine __ANON__: called CC=1 SCAR=0.0
35 delay => $args{delay},
36 max_pending => $args{max_pending} // 512,
37 max_seen => $args{max_seen} // 10000,
38 seen_ttl => $args{seen_ttl} // 900,
39 on_error => $args{on_error},
40 51 ▶ seen => {},
Condition83%10/12
$args{"loop"} // "IO::Async::Loop"->new
l!l&&r!l&&!r
4830
$args{"clock"} // sub { &clock_gettime(scalar CLOCK_MONOTONIC()); }
l!l&&r!l&&!r
36150
$args{"max_pending"} // 512
l!l
1932
$args{"max_seen"} // 10000
l!l
2031
$args{"seen_ttl"} // 900
l!l
1833
MC/DC0%0/2
$args{"loop"} // "IO::Async::Loop"->new
$args{"loop"} "IO::Async::Loop"->new
MC/DC0%0/2
$args{"clock"} // sub { &clock_gettime(scalar CLOCK_MONOTONIC()); }
$args{"clock"} sub { &clock_gettime(scalar CLOCK_MONOTONIC()); }
MC/DC100%1/1
$args{"max_pending"} // 512
$args{"max_pending"}
MC/DC100%1/1
$args{"max_seen"} // 10000
$args{"max_seen"}
MC/DC100%1/1
$args{"seen_ttl"} // 900
$args{"seen_ttl"}
Truth table66%2/3
A // B
A= $args{"loop"}B= "IO::Async::Loop"->new
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $args{"clock"}B= sub { &clock_gettime(scalar CLOCK_MONOTONIC()); }
ABresult
1X1
011
000
Truth table100%2/2
A
A= $args{"max_pending"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"max_seen"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"seen_ttl"}
Aresult
11
00
41 jobs => {},
42 counters => {}
43 }, $class;
44 }
45  
46 11 ▶sub _error {
Subroutine _error: called CC=1 SCAR=0.0
47 11 my ( $self, $message, $category ) = @_;
48 11 return Discord::Client::Error->new( message => $message, category => $category );
49 }
50  
51 4 ▶sub _failed {
Subroutine _failed: called CC=1 SCAR=0.0
52 4 my ( $self, $message, $category ) = @_;
53 4 my $error = $self->_error( $message, $category );
54 4 return $self->{loop}->new_future->fail( $message, $category, $error );
55 }
56  
57 9 ▶sub _report {
Subroutine _report: called CC=3 SCAR=11.4
58 9 my ( $self, $error, $context ) = @_;
59  
60 # Application error hooks receive sanitized failures and cannot break dispatch.
61 9 ++$self->{counters}{errors};
62 9 ▶ if ( $self->{on_error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'on_error'}) { } 9 0 9
63 9 my $ok = eval {
64 9 $self->{on_error}->( $error, $context );
65 9 1;
66 };
67 9 ▶ warn "Interaction error handler failed\n" unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 9 9
68 }
69 else {
70 0 warn $error->message . "\n";
71 }
72 }
73  
74 1081 ▶sub handle {
Subroutine handle: called CC=22 SCAR=31.2
Pod documented
75 1081 my ( $self, $payload, %args ) = @_;
76 1081 ▶ return $self->_failed( 'Interaction dispatcher is closed', 'shutdown' ) if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 1081 1081
77 1081 my $now = $self->{clock}->();
78  
79 # A replay window must not expire an ID while its handler can still act.
80 1081 for my $id ( keys %{ $self->{seen} } ) {
81 delete $self->{seen}{$id}
82 if $self->{seen}{$id}{expires} <= $now
83 524829 ▶ && $self->{seen}{$id}{result}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"seen"}{$id}{"expires"} <= $now and $self->{"seen"}{$id}{"result"}->is_ready 7 524822 524829
Condition100%3/3
$self->{"seen"}{$id}{"expires"} <= $now and $self->{"seen"}{$id}{"result"}->is_ready
!ll&&!rl&&r
52482027
MC/DC100%2/2
$self->{"seen"}{$id}{"expires"} <= $now and $self->{"seen"}{$id}{"result"}->is_ready
$self->{"seen"}{$id}{"expires"} <= $now $self->{"seen"}{$id}{"result"}->is_ready
Truth table100%3/3
A and B
A= $self->{"seen"}{$id}{"expires"} <= $nowB= $self->{"seen"}{$id}{"result"}->is_ready
ABresult
0X0
100
111
84 }
85 1081 ▶ my $id = ref($payload) eq 'HASH' ? $payload->{id} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $payload eq 'HASH' ? : 1081 0 1081
86 1081 ▶ if ( defined($id) && !ref($id) && exists $self->{seen}{$id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id and not ref $id and exists $self->{"seen"}{$id}) 2 1079 1081
Condition50%3/6
defined $id and not ref $id and exists $self->{"seen"}{$id}
!ll&&!rl&&r
010792
defined $id and not ref $id
!ll&&!rl&&r
001081
MC/DC33%1/3
defined $id and not ref $id and exists $self->{"seen"}{$id}
defined $id not ref $id exists $self->{"seen"}{$id}
Truth table50%2/4
A and not(B) and C
A= defined $idB= not ref $idC= exists $self->{"seen"}{$id}
ABCresult
0XX0
10X0
1100
1111
87 2 ++$self->{counters}{duplicates};
88 2 ▶ return $args{acknowledgement_only} ? $self->{seen}{$id}{ack} : $self->{seen}{$id}{result};
Branch: 1 branch
BranchTrueFalseTotal
$args{'acknowledgement_only'} ? : 1 1 2
89 }
90  
91 # Reject overload before constructing a context or invoking application code.
92 return $self->_failed( 'Interaction work capacity exceeded', 'queue_full' )
93 1079 ▶ if keys( %{ $self->{jobs} } ) >= $self->{max_pending} || keys( %{ $self->{seen} } ) >= $self->{max_seen};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"jobs"};} >= $self->{"max_pending"} or keys %{$$self{"seen"};} >= $self->{"max_seen"} 4 1075 1079
Condition100%3/3
keys %{$$self{"jobs"};} >= $self->{"max_pending"} or keys %{$$self{"seen"};} >= $self->{"max_seen"}
l!l&&r!l&&!r
221075
MC/DC100%2/2
keys %{$$self{"jobs"};} >= $self->{"max_pending"} or keys %{$$self{"seen"};} >= $self->{"max_seen"}
keys %{$$self{"jobs"};} >= $self->{"max_pending"} keys %{$$self{"seen"};} >= $self->{"max_seen"}
Truth table100%3/3
A or B
A= keys %{$$self{"jobs"};} >= $self->{"max_pending"}B= keys %{$$self{"seen"};} >= $self->{"max_seen"}
ABresult
1X1
011
000
94  
95 # Use the same monotonic clock for receipt time, deadlines and replay retention.
96 my %context_options = (
97 payload => $payload,
98 loop => $self->{loop},
99 rest => $self->{rest},
100 clock => $self->{clock},
101 1075 );
102 1075 ▶ $context_options{delay} = $self->{delay} if $self->{delay};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"delay"} 1072 3 1075
103 1075 for my $name (qw(received_at initial_sender)) {
104 2150 ▶ $context_options{$name} = $args{$name} if exists $args{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{$name} 2119 31 2150
105 }
106 1075 my $context = eval { Discord::Client::Interaction->new(%context_options) };
107 1075 ▶ return $self->_failed( 'Invalid interaction payload', 'protocol' ) if !$context || $@;
Branch: 1 branch
BranchTrueFalseTotal
if not $context or $@ 0 1075 1075
Condition33%1/3
not $context or $@
l!l&&r!l&&!r
001075
MC/DC0%0/2
not $context or $@
not $context $@
Truth table33%1/3
not(A) or B
A= not $contextB= $@
ABresult
1X1
011
000
108 1075 ▶ if ( $context->acknowledgement->is_failed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context->acknowledgement->is_failed) 2 1073 1075
109 2 $self->_report( ( $context->acknowledgement->failure )[2], $context );
110 2 return $self->{loop}->new_future->fail( $context->acknowledgement->failure );
111 }
112  
113 # Reserve the ID and active slot before invoking handlers that can re-enter dispatch.
114 1073 my $result = $self->{loop}->new_future;
115 1073 my $job = { context => $context, result => $result };
116 1073 my $key = refaddr($job);
117 1073 $self->{jobs}{$key} = $job;
118 $self->{seen}{ $context->id } =
119 1073 { expires => $now + $self->{seen_ttl}, ack => $context->acknowledgement, result => $result };
120 1073 ++$self->{counters}{received};
121  
122 # Release work capacity on every terminal result; unanswered contexts also close.
123 $result->on_ready(
124 1073 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
125 1073 delete $self->{jobs}{$key};
126 1073 ▶ $context->close unless $context->acknowledgement->is_done;
Branch: 1 branch
BranchTrueFalseTotal
unless $context->acknowledgement->is_done 6 1067 1073
127 }
128 1073 );
129 $result->on_cancel(
130 7 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
131 7 $context->close;
132 7 ▶ $job->{handler}->cancel if $job->{handler} && !$job->{handler}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $job->{"handler"} and not $job->{"handler"}->is_ready 3 4 7
Condition100%3/3
$job->{"handler"} and not $job->{"handler"}->is_ready
!ll&&!rl&&r
133
MC/DC100%2/2
$job->{"handler"} and not $job->{"handler"}->is_ready
$job->{"handler"} not $job->{"handler"}->is_ready
Truth table100%3/3
A and not(B)
A= $job->{"handler"}B= not $job->{"handler"}->is_ready
ABresult
0X0
100
111
133 }
134 1073 );
135 1073 $job->{handler} = $self->_invoke_handler($job);
136  
137 # Shutdown can run inside the handler before its Future is registered.
138 # Cancel that returned work even though the result has already settled.
139 1073 ▶ if ( $result->is_ready ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->is_ready) 1 1072 1073
140 1 ▶ $job->{handler}->cancel unless $job->{handler}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $job->{"handler"}->is_ready 1 0 1
141 1 ▶ return $args{acknowledgement_only} ? $context->acknowledgement : $result;
Branch: 1 branch
BranchTrueFalseTotal
$args{'acknowledgement_only'} ? : 0 1 1
142 }
143  
144 1072 $self->_watch_job($job);
145 1072 ▶ return $args{acknowledgement_only} ? $context->acknowledgement : $result;
Branch: 1 branch
BranchTrueFalseTotal
$args{'acknowledgement_only'} ? : 24 1048 1072
146 }
147  
148 1073 ▶sub _invoke_handler {
Subroutine _invoke_handler: called CC=10 SCAR=24.6
149 1073 my ( $self, $job ) = @_;
150 1073 my $context = $job->{context};
151  
152 # Resolve the local declaration before calling application code.
153 1073 my $handler = eval { $self->{commands}->handler_for($context) };
154 1073 ▶ if ( !$handler || $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $handler or $@) 0 1073 1073
Condition33%1/3
not $handler or $@
l!l&&r!l&&!r
001073
MC/DC0%0/2
not $handler or $@
not $handler $@
Truth table33%1/3
not(A) or B
A= not $handlerB= $@
ABresult
1X1
011
000
155 0 ▶ my $message = $@ ? 'Invalid interaction command options' : 'No handler for this interaction';
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 0 0
156 0 $self->_record_job_error( $job, $message, 'command' );
157 0 return $self->{loop}->new_future->done;
158 }
159  
160 # Capture synchronous failures; asynchronous work is observed by the job watcher.
161 1073 my $work = eval { $handler->($context) };
162 1073 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 1072 1073
163 1 $self->_record_job_error( $job, 'Interaction handler failed', 'handler' );
164 1 return $self->{loop}->new_future->done;
165 }
166  
167 # Autocomplete handlers may return choices directly instead of sending a response.
168 1072 ▶ if ( $context->type == 4 && ref($work) eq 'ARRAY' && !$context->responded ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context->type == 4 and ref $work eq "ARRAY" and not $context->responded) 1 1071 1072
Condition83%5/6
$context->type == 4 and ref $work eq "ARRAY" and not $context->responded
!ll&&!rl&&r
107101
$context->type == 4 and ref $work eq "ARRAY"
!ll&&!rl&&r
107011
MC/DC66%2/3
$context->type == 4 and ref $work eq "ARRAY" and not $context->responded
$context->type == 4 ref $work eq "ARRAY" not $context->responded
Truth table75%3/4
A and B and not(C)
A= $context->type == 4B= ref $work eq "ARRAY"C= not $context->responded
ABCresult
0XX0
10X0
1100
1111
169 1 return $context->autocomplete($work);
170 }
171 1071 ▶ return $work if blessed($work) && $work->isa('Future');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($work) and $work->isa("Future") 1069 2 1071
Condition66%2/3
builtin::blessed($work) and $work->isa("Future")
!ll&&!rl&&r
201069
MC/DC50%1/2
builtin::blessed($work) and $work->isa("Future")
builtin::blessed($work) $work->isa("Future")
Truth table66%2/3
A and B
A= builtin::blessed($work)B= $work->isa("Future")
ABresult
0X0
100
111
172 2 return $self->{loop}->new_future->done;
173 }
174  
175 7 ▶sub _record_job_error {
Subroutine _record_job_error: called CC=2 SCAR=6.9
176 7 my ( $self, $job, $message, $category ) = @_;
177 7 $job->{error} = $self->_error( $message, $category );
178 7 ▶ $self->_report( $job->{error}, $job->{context} ) unless $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"closed"} 5 2 7
179 }
180  
181 1072 ▶sub _watch_job {
Subroutine _watch_job: called CC=1 SCAR=0.0
182 1072 my ( $self, $job ) = @_;
183 1072 my $context = $job->{context};
184 1072 my $work = $job->{handler};
185  
186 # Recheck both completion paths because acknowledgement and handler work can settle in either order.
187 1072 ▶ my $check = sub { $self->_check_job($job) };
Subroutine __ANON__: called CC=1 SCAR=0.0
188 $work->on_ready(
189 1072 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
190 # Resolve asynchronously produced suggestions only if the handler has not already replied.
191 1072 ▶ if ( $context->type == 4 && $work->is_done && !$context->responded ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context->type == 4 and $work->is_done and not $context->responded) 1 1071 1072
Condition83%5/6
$context->type == 4 and $work->is_done and not $context->responded
!ll&&!rl&&r
107011
$context->type == 4 and $work->is_done
!ll&&!rl&&r
107002
MC/DC66%2/3
$context->type == 4 and $work->is_done and not $context->responded
$context->type == 4 $work->is_done not $context->responded
Truth table75%3/4
A and B and not(C)
A= $context->type == 4B= $work->is_doneC= not $context->responded
ABCresult
0XX0
10X0
1100
1111
192 1 my ($choices) = $work->result;
193 1 ▶ if ( ref($choices) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $choices eq "ARRAY") 1 0 1
194 1 my $response = $context->autocomplete($choices);
195 1 $response->on_ready($check);
196 }
197 }
198 1072 $check->();
199 }
200 1072 );
201 1072 $context->acknowledgement->on_ready($check);
202 1072 $check->();
203 }
204  
205 3217 ▶sub _check_job {
Subroutine _check_job: called CC=16 SCAR=27.7
206 3217 my ( $self, $job ) = @_;
207 3217 my $result = $job->{result};
208 3217 ▶ return if $result->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $result->is_ready 2094 1123 3217
209  
210 1123 my $context = $job->{context};
211 1123 my $work = $job->{handler};
212 1123 my $acknowledgement = $context->acknowledgement;
213  
214 # Record a handler failure once, allowing an error hook to close the dispatcher.
215 1123 ▶ if ( $work->is_ready && !$work->is_done && !$job->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($work->is_ready and not $work->is_done and not $job->{"error"}) 6 1117 1123
Condition100%6/6
$work->is_ready and not $work->is_done and not $job->{"error"}
!ll&&!rl&&r
111616
$work->is_ready and not $work->is_done
!ll&&!rl&&r
4210747
MC/DC100%3/3
$work->is_ready and not $work->is_done and not $job->{"error"}
$work->is_ready not $work->is_done not $job->{"error"}
Truth table100%4/4
A and not(B) and not(C)
A= $work->is_readyB= not $work->is_doneC= not $job->{"error"}
ABCresult
0XX0
10X0
1100
1111
216 6 $self->_record_job_error( $job, 'Interaction handler failed', 'handler' );
217 }
218 1123 ▶ return if $result->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $result->is_ready 1 1122 1123
219  
220 # Failed acknowledgement ends the job and cancels any work that can no longer reply.
221 1122 ▶ if ( $acknowledgement->is_ready && !$acknowledgement->is_done ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($acknowledgement->is_ready and not $acknowledgement->is_done) 6 1116 1122
Condition100%3/3
$acknowledgement->is_ready and not $acknowledgement->is_done
!ll&&!rl&&r
3410826
MC/DC100%2/2
$acknowledgement->is_ready and not $acknowledgement->is_done
$acknowledgement->is_ready not $acknowledgement->is_done
Truth table100%3/3
A and not(B)
A= $acknowledgement->is_readyB= not $acknowledgement->is_done
ABresult
0X0
100
111
222 6 my $error = $job->{error};
223 6 ▶ unless ($error) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($error) 3 3 6
224 3 ▶ if ( $acknowledgement->is_failed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($acknowledgement->is_failed) { } 3 0 3
225 3 $error = ( $acknowledgement->failure )[2];
226 }
227 else {
228 0 $error = $self->_error( 'Interaction acknowledgement cancelled', 'cancelled' );
229 }
230 3 ▶ $self->_report( $error, $context ) unless $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"closed"} 2 1 3
231 }
232 6 ▶ $result->fail( $error->message, $error->category, $error ) unless $result->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $result->is_ready 6 0 6
233 6 ▶ $work->cancel unless $work->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $work->is_ready 1 5 6
234 6 return;
235 }
236  
237 # A reply may finish before the handler's deferred work. Both must settle
238 # before releasing the bounded active-handler slot.
239 1116 ▶ return unless $acknowledgement->is_done && $work->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $acknowledgement->is_done and $work->is_ready 50 1066 1116
Condition100%3/3
$acknowledgement->is_done and $work->is_ready
!ll&&!rl&&r
34161066
MC/DC100%2/2
$acknowledgement->is_done and $work->is_ready
$acknowledgement->is_done $work->is_ready
Truth table100%3/3
A and B
A= $acknowledgement->is_doneB= $work->is_ready
ABresult
0X0
100
111
240 1066 ▶ if ( my $error = $job->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $job->{'error'}) { } 3 1063 1066
241 3 $result->fail( $error->message, $error->category, $error );
242 }
243 else {
244 1063 ++$self->{counters}{handled};
245 1063 $result->done;
246 }
247 }
248  
249 32 ▶sub stats {
Subroutine stats: called CC=1 SCAR=0.0
Pod documented
250 32 my ($self) = @_;
251 return {
252 32 %{ $self->{counters} },
253 32 pending => scalar( keys %{ $self->{jobs} } ),
254 32 replay_entries => scalar( keys %{ $self->{seen} } ),
255 };
256 }
257  
258 50 ▶sub close {
Subroutine close: called CC=3 SCAR=11.0
Pod documented
259 50 my ($self) = @_;
260  
261 # Stop admission before cancelling a snapshot of jobs that can remove themselves.
262 50 $self->{closed} = 1;
263 50 my @jobs = values %{ $self->{jobs} };
264 50 for my $job (@jobs) {
265 5 ▶ $job->{result}->cancel unless $job->{result}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $job->{"result"}->is_ready 5 0 5
266 5 $job->{context}->close;
267 }
268 50 $self->{seen} = {};
269 50 return $self->{loop}->new_future->done;
270 }
271  
272 9 1;
273  
274 __END__
« blib/lib/Discord/Client/Gateway/IdentifyLimiter.pm ↑ Summary blib/lib/Discord/Client/UI.pm »