blib/lib/Discord/Client/Gateway/Shards.pm

filter: Statementstmt 95.2% 180 / 189 Branchbran 70.8% 51 / 72 Conditioncond 48.8% 42 / 86 MC/DCmcdc 21.2% 10 / 47 Subroutinesub 91.8% 34 / 37 Podpod 100% 13 / 13 totaltotal 74.3% 330 / 444 CC 74 SCAR 18.9
CC
74
Cov
79%
new
17.8
send
11.3
_start_shards
9.4
CRAP 6.6
« blib/lib/Discord/Client.pm ↑ Summary blib/lib/Discord/Client/Gateway/WebSocket.pm »
1 package Discord::Client::Gateway::Shards;
2  
3 2 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use IO::Async::Loop;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Math::BigInt;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Discord::Client::Gateway;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Discord::Client::Gateway::IdentifyLimiter;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Discord::Client::REST;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Discord::Client::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 our $VERSION = '0.002';
17  
18 12 ▶sub new {
Subroutine new: called CC=12 SCAR=28.8
Pod documented
19 12 my ( $class, %args ) = @_;
20  
21 # Bound shard creation before constructing shared discovery resources.
22 12 ▶ my $count = $args{shards} // 'auto';
Condition100%2/2
$args{"shards"} // "auto"
l!l
84
MC/DC100%1/1
$args{"shards"} // "auto"
$args{"shards"}
Truth table100%2/2
A
A= $args{"shards"}
Aresult
11
00
23 12 ▶ croak 'shards must be auto or a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $count and $count eq "auto" || $count =~ /\A[1-9]\d*\z/u 0 12 12
Condition50%3/6
not ref $count and $count eq "auto" || $count =~ /\A[1-9]\d*\z/u
!ll&&!rl&&r
0012
$count eq "auto" or $count =~ /\A[1-9]\d*\z/u
l!l&&r!l&&!r
570
MC/DC0%0/3
not ref $count and $count eq "auto" || $count =~ /\A[1-9]\d*\z/u
not ref $count $count eq "auto" $count =~ /\A[1-9]\d*\z/u
Truth table50%2/4
not(A) and B or C
A= not ref $countB= $count eq "auto"C= $count =~ /\A[1-9]\d*\z/u
ABCresult
0XX0
1000
11X1
1011
24 unless !ref($count) && ( $count eq 'auto' || $count =~ /\A[1-9]\d*\z/ );
25 12 ▶ my $loop = $args{loop} // IO::Async::Loop->new;
Condition33%1/3
$args{"loop"} // "IO::Async::Loop"->new
l!l&&r!l&&!r
1200
MC/DC0%0/2
$args{"loop"} // "IO::Async::Loop"->new
$args{"loop"} "IO::Async::Loop"->new
Truth table33%1/3
A // B
A= $args{"loop"}B= "IO::Async::Loop"->new
ABresult
1X1
011
000
26 12 ▶ my $max = $args{max_shards} // 1024;
Condition100%2/2
$args{"max_shards"} // 1024
l!l
111
MC/DC100%1/1
$args{"max_shards"} // 1024
$args{"max_shards"}
Truth table100%2/2
A
A= $args{"max_shards"}
Aresult
11
00
27 12 ▶ croak 'max_shards must be a positive integer' unless !ref($max) && $max =~ /\A[1-9]\d*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $max and $max =~ /\A[1-9]\d*\z/u 0 12 12
Condition33%1/3
not ref $max and $max =~ /\A[1-9]\d*\z/u
!ll&&!rl&&r
0012
MC/DC0%0/2
not ref $max and $max =~ /\A[1-9]\d*\z/u
not ref $max $max =~ /\A[1-9]\d*\z/u
Truth table33%1/3
not(A) and B
A= not ref $maxB= $max =~ /\A[1-9]\d*\z/u
ABresult
0X0
100
111
28 12 my $self = bless {
29 args => \%args,
30 count => $count,
31 loop => $loop,
32 shards => {},
33 handlers => {},
34 dispatch_observers => [],
35 state => 'idle',
36 max_shards => $max,
37 completion => $loop->new_future
38 }, $class;
39  
40 # All children share one REST client and one Identify budget.
41 12 ▶ $self->{rest} = $args{rest} // Discord::Client::REST->new( token => $args{token}, loop => $loop );
Condition33%1/3
$args{"rest"} // "Discord::Client::REST"->new("token", $args{"token"}, "loop", $loop)
l!l&&r!l&&!r
1200
MC/DC0%0/2
$args{"rest"} // "Discord::Client::REST"->new("token", $args{"token"}, "loop", $loop)
$args{"rest"} "Discord::Client::REST"->new("token", $args{"token"}, "loop", $loop)
Truth table33%1/3
A // B
A= $args{"rest"}B= "Discord::Client::REST"->new("token", $args{"token"}, "loop", $loop)
ABresult
1X1
011
000
42 12 $self->{own_rest} = !$args{rest};
43 $self->{limiter} = Discord::Client::Gateway::IdentifyLimiter->new(
44 loop => $loop,
45 rest => $self->{rest},
46 ( exists( $args{clock} ) ? ( clock => $args{clock} ) : () ),
47 12 ▶ ( exists( $args{delay} ) ? ( delay => $args{delay} ) : () )
Branch: 2 branches
BranchTrueFalseTotal
exists $args{'clock'} ? : 12 0 12
exists $args{'delay'} ? : 12 0 12
48 );
49 12 return $self;
50 }
51  
52 0 ▶sub loop { $_[0]->{loop} }
Subroutine loop: not called CC=1 SCAR=6.9
Pod documented
53 4 ▶sub shards { +{ %{ $_[0]->{shards} } } }
Subroutine shards: called CC=1 SCAR=0.0
Pod documented
54 0 ▶sub identify_limiter { $_[0]->{limiter} }
Subroutine identify_limiter: not called CC=1 SCAR=6.9
Pod documented
55 2 ▶sub completion { $_[0]->{completion} }
Subroutine completion: called CC=1 SCAR=0.0
Pod documented
56  
57 20 ▶sub state {
Subroutine state: called CC=5 SCAR=16.1
Pod documented
58 20 my ($self) = @_;
59  
60 # Readiness reflects every live child, including temporary reconnects.
61 20 ▶ return 'closed' if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 2 18 20
62 18 ▶ return 'ready' if keys( %{ $self->{shards} } ) && !grep { $_->state ne 'ready' } values %{ $self->{shards} };
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$$self{"shards"};} and not grep({$_->state ne "ready";} values %{$$self{"shards"};}) 3 15 18
Condition100%3/3
keys %{$$self{"shards"};} and not grep({$_->state ne "ready";} values %{$$self{"shards"};})
!ll&&!rl&&r
1233
MC/DC100%2/2
keys %{$$self{"shards"};} and not grep({$_->state ne "ready";} values %{$$self{"shards"};})
keys %{$$self{"shards"};} not grep({$_->state ne "ready";} values %{$$self{"shards"};})
Truth table100%3/3
A and not(B)
A= keys %{$$self{"shards"};}B= not grep({$_->state ne "ready";} values %{$$self{"shards"};})
ABresult
0X0
100
111
63 15 ▶ return $self->{state} eq 'ready' ? 'reconnecting' : $self->{state};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'state'} eq 'ready' ? : 3 12 15
64 }
65  
66 12 ▶sub on {
Subroutine on: called CC=6 SCAR=18.6
Pod documented
67 12 my ( $self, $event, $callback ) = @_;
68 12 ▶ croak 'Event and callback required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $event and not ref $event and length $event and ref $callback eq "CODE" 2 10 12
Condition55%5/9
defined $event and not ref $event and length $event and ref $callback eq "CODE"
!ll&&!rl&&r
2010
defined $event and not ref $event and length $event
!ll&&!rl&&r
0210
defined $event and not ref $event
!ll&&!rl&&r
0012
MC/DC25%1/4
defined $event and not ref $event and length $event and ref $callback eq "CODE"
defined $event not ref $event length $event ref $callback eq "CODE"
Truth table40%2/5
A and not(B) and C and D
A= defined $eventB= not ref $eventC= length $eventD= ref $callback eq "CODE"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
69 unless defined($event)
70 && !ref($event)
71 && length($event)
72 && ref($callback) eq 'CODE';
73  
74 # Remember listeners for future children and attach them to existing ones.
75 10 push @{ $self->{handlers}{$event} }, $callback;
76 10 $_->on( $event => $callback ) for values %{ $self->{shards} };
77 10 return $self;
78 }
79  
80 # Forward internal state observers to existing and future child connections.
81 2 ▶sub _on_dispatch {
Subroutine _on_dispatch: called CC=3 SCAR=11.0
82 2 my ( $self, $callback ) = @_;
83 2 ▶ croak 'dispatch observer must be a code reference' unless ref($callback) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callback eq "CODE" 0 2 2
84  
85 # Register SDK state observers for both existing and future children.
86 2 push @{ $self->{dispatch_observers} }, $callback;
87 2 $_->_on_dispatch($callback) for values %{ $self->{shards} };
88 2 return $self;
89 }
90  
91 3 ▶sub _failed {
Subroutine _failed: called CC=1 SCAR=0.0
92 3 my ( $self, $message, $category ) = @_;
93 3 my $error = Discord::Client::Error->new( message => $message, category => $category );
94 3 return $self->{loop}->new_future->fail( $message, $category, $error );
95 }
96  
97 13 ▶sub connect {
Subroutine connect: called CC=7 SCAR=20.4
Pod documented
98 13 my ($self) = @_;
99  
100 # Coalesce startup waits and reject attempts to restart a closed manager.
101 13 ▶ return $self->_failed( 'Shard manager is closed', 'shutdown' ) if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 13 13
102 13 ▶ return $self->{loop}->new_future->done($self) if $self->state eq 'ready';
Branch: 1 branch
BranchTrueFalseTotal
if $self->state eq "ready" 0 13 13
103 13 ▶ return $self->{ready} if $self->{ready} && !$self->{ready}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ready"} and not $self->{"ready"}->is_ready 0 13 13
Condition33%1/3
$self->{"ready"} and not $self->{"ready"}->is_ready
!ll&&!rl&&r
1300
MC/DC0%0/2
$self->{"ready"} and not $self->{"ready"}->is_ready
$self->{"ready"} not $self->{"ready"}->is_ready
Truth table33%1/3
A and not(B)
A= $self->{"ready"}B= not $self->{"ready"}->is_ready
ABresult
0X0
100
111
104 13 my $future = $self->{loop}->new_future;
105 13 $self->{ready} = $future;
106 13 ▶ $future->on_cancel( sub { $self->close } );
Subroutine __ANON__: called CC=1 SCAR=0.0
107  
108 # During recovery, observe each child until the full group becomes ready again.
109 13 ▶ if ( $self->{running} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"running"}) 2 11 13
110 2 my $weak = $self;
111 2 weaken($weak);
112 4 ▶ $_->connect->on_ready( sub { $weak->_maybe_ready if $weak && !$weak->{closed} } )
Subroutine __ANON__: called CC=3 SCAR=14.2
Branch: 1 branch
BranchTrueFalseTotal
if $weak and not $weak->{"closed"} 4 0 4
Condition33%1/3
$weak and not $weak->{"closed"}
!ll&&!rl&&r
004
MC/DC0%0/2
$weak and not $weak->{"closed"}
$weak not $weak->{"closed"}
Truth table33%1/3
A and not(B)
A= $weakB= not $weak->{"closed"}
ABresult
0X0
100
111
113 2 for values %{ $self->{shards} };
114 2 return $future;
115 }
116  
117 # Discover metadata before choosing the automatic shard count.
118 11 $self->{running} = 1;
119 11 $self->{state} = 'discovering';
120 11 my $info = $self->{limiter}->info;
121 11 $self->{discovery} = $info;
122 $info->on_ready(
123 11 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
124 11 delete $self->{discovery};
125 11 ▶ return if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 1 10 11
126 10 ▶ unless ( $info->is_done ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($info->is_done) 0 10 10
127 0 my $error = $self->_failed( 'Shard discovery failed', 'transport' );
128 0 $self->_fatal($error);
129 0 return;
130 }
131 10 my ($metadata) = $info->result;
132 10 $self->_start_shards($metadata);
133 }
134 11 );
135 11 return $future;
136 }
137  
138 10 ▶sub _start_shards {
Subroutine _start_shards: called CC=9 SCAR=22.5
139 10 my ( $self, $metadata ) = @_;
140  
141 # Validate the server recommendation against the configured process capacity.
142 10 ▶ my $count = $self->{count} eq 'auto' ? $metadata->{shards} : $self->{count};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'count'} eq 'auto' ? : 3 7 10
143 10 ▶ unless ( defined($count) && !ref($count) && $count =~ /\A[1-9]\d*\z/ && $count <= $self->{max_shards} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $count and not ref $count and $count =~ /\A[1-9]\d*\z/u and $count <= $self->{"max_shards"}) 1 9 10
Condition44%4/9
defined $count and not ref $count and $count =~ /\A[1-9]\d*\z/u and $count <= $self->{"max_shards"}
!ll&&!rl&&r
019
defined $count and not ref $count and $count =~ /\A[1-9]\d*\z/u
!ll&&!rl&&r
0010
defined $count and not ref $count
!ll&&!rl&&r
0010
MC/DC25%1/4
defined $count and not ref $count and $count =~ /\A[1-9]\d*\z/u and $count <= $self->{"max_shards"}
defined $count not ref $count $count =~ /\A[1-9]\d*\z/u $count <= $self->{"max_shards"}
Truth table40%2/5
A and not(B) and C and D
A= defined $countB= not ref $countC= $count =~ /\A[1-9]\d*\z/uD= $count <= $self->{"max_shards"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
144 1 $self->_fatal( $self->_failed( 'Shard count is invalid or exceeds client capacity', 'request' ) );
145 1 return;
146 }
147 9 $self->{total} = 0 + $count;
148 9 $self->{state} = 'connecting';
149  
150 # Construct children with explicit shard identities and a shared Identify limiter.
151 9 for my $id ( 0 .. $count - 1 ) {
152 14 my $gateway = eval {
153 Discord::Client::Gateway->new(
154 14 %{ $self->{args} },
155 loop => $self->{loop},
156 rest => $self->{rest},
157 shard => [ $id, 0 + $count ],
158 identify_limiter => $self->{limiter},
159 14 );
160 };
161 14 ▶ unless ($gateway) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gateway) 1 13 14
162 1 $self->_fatal( $self->_failed( 'Invalid shard configuration', 'request' ) );
163 1 last;
164 }
165 13 $self->{shards}{$id} = $gateway;
166 13 $self->_attach_shard($gateway);
167 13 ▶ last if $self->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closed"} 0 13 13
168 }
169 }
170  
171 13 ▶sub _attach_shard {
Subroutine _attach_shard: called CC=4 SCAR=14.0
172 13 my ( $self, $gateway ) = @_;
173  
174 # Install state observers and application handlers before opening the child.
175 13 $gateway->_on_dispatch($_) for @{ $self->{dispatch_observers} };
176 13 for my $event ( keys %{ $self->{handlers} } ) {
177 7 $gateway->on( $event => $_ ) for @{ $self->{handlers}{$event} };
178 }
179  
180 # Child failures stop the group without making children own their manager.
181 13 my $weak = $self;
182 13 weaken($weak);
183 $gateway->completion->on_fail(
184 1 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=13.1
185 1 ▶ return unless $weak && !$weak->{closed};
Branch: 1 branch
BranchTrueFalseTotal
unless $weak and not $weak->{"closed"} 0 1 1
Condition33%1/3
$weak and not $weak->{"closed"}
!ll&&!rl&&r
001
MC/DC0%0/2
$weak and not $weak->{"closed"}
$weak not $weak->{"closed"}
Truth table33%1/3
A and not(B)
A= $weakB= not $weak->{"closed"}
ABresult
0X0
100
111
186 1 $weak->_fatal( $weak->{loop}->new_future->fail(@_) );
187 }
188 13 );
189 $gateway->connect->on_ready(
190 13 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
191 13 ▶ $weak->_maybe_ready if $weak && !$weak->{closed};
Branch: 1 branch
BranchTrueFalseTotal
if $weak and not $weak->{"closed"} 12 1 13
Condition66%2/3
$weak and not $weak->{"closed"}
!ll&&!rl&&r
0112
MC/DC50%1/2
$weak and not $weak->{"closed"}
$weak not $weak->{"closed"}
Truth table66%2/3
A and not(B)
A= $weakB= not $weak->{"closed"}
ABresult
0X0
100
111
192 }
193 13 );
194 }
195  
196 16 ▶sub _maybe_ready {
Subroutine _maybe_ready: called CC=6 SCAR=18.8
197 16 my ($self) = @_;
198  
199 # Complete startup only when the expected number of children are all ready.
200 return
201 16 ▶ unless keys( %{ $self->{shards} } ) == ( $self->{total} // -1 )
Condition50%1/2
$self->{"total"} // -1
l!l
160
MC/DC0%0/1
$self->{"total"} // -1
$self->{"total"}
Truth table50%1/2
A
A= $self->{"total"}
Aresult
11
00
202 16 ▶ && !grep { $_->state ne 'ready' } values %{ $self->{shards} };
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$$self{"shards"};} == ($self->{"total"} // -1) and not grep({$_->state ne "ready";} values %{$$self{"shards"};}) 7 9 16
Condition66%2/3
keys %{$$self{"shards"};} == ($self->{"total"} // -1) and not grep({$_->state ne "ready";} values %{$$self{"shards"};})
!ll&&!rl&&r
079
MC/DC50%1/2
keys %{$$self{"shards"};} == ($self->{"total"} // -1) and not grep({$_->state ne "ready";} values %{$$self{"shards"};})
keys %{$$self{"shards"};} == ($self->{"total"} // -1) not grep({$_->state ne "ready";} values %{$$self{"shards"};})
Truth table66%2/3
A and not(B)
A= keys %{$$self{"shards"};} == ($self->{"total"} // -1)B= not grep({$_->state ne "ready";} values %{$$self{"shards"};})
ABresult
0X0
100
111
203 9 $self->{state} = 'ready';
204 9 my $future = delete $self->{ready};
205 9 ▶ $future->done($self) if $future && !$future->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $future and not $future->is_ready 9 0 9
Condition33%1/3
$future and not $future->is_ready
!ll&&!rl&&r
009
MC/DC0%0/2
$future and not $future->is_ready
$future not $future->is_ready
Truth table33%1/3
A and not(B)
A= $futureB= not $future->is_ready
ABresult
0X0
100
111
206 }
207  
208 3 ▶sub _fatal {
Subroutine _fatal: called CC=4 SCAR=15.6
209 3 my ( $self, $failure ) = @_;
210  
211 # Publish the failure before shutdown can settle outstanding lifetime observers.
212 3 ▶ $self->{ready}->fail( $failure->failure ) if $self->{ready} && !$self->{ready}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ready"} and not $self->{"ready"}->is_ready 3 0 3
Condition33%1/3
$self->{"ready"} and not $self->{"ready"}->is_ready
!ll&&!rl&&r
003
MC/DC0%0/2
$self->{"ready"} and not $self->{"ready"}->is_ready
$self->{"ready"} not $self->{"ready"}->is_ready
Truth table33%1/3
A and not(B)
A= $self->{"ready"}B= not $self->{"ready"}->is_ready
ABresult
0X0
100
111
213 3 ▶ $self->{completion}->fail( $failure->failure ) unless $self->{completion}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"completion"}->is_ready 3 0 3
214 3 $self->close;
215 }
216  
217 4 ▶sub shard_for_guild {
Subroutine shard_for_guild: called CC=6 SCAR=19.9
Pod documented
218 4 my ( $self, $guild_id ) = @_;
219 4 ▶ croak 'Shard count is not discovered' unless $self->{total};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"total"} 0 4 4
220 4 ▶ croak 'Invalid guild ID' unless defined($guild_id) && !ref($guild_id) && $guild_id =~ /\A\d{1,20}\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $guild_id and not ref $guild_id and $guild_id =~ /\A\d{1,20}\z/u 0 4 4
Condition33%2/6
defined $guild_id and not ref $guild_id and $guild_id =~ /\A\d{1,20}\z/u
!ll&&!rl&&r
004
defined $guild_id and not ref $guild_id
!ll&&!rl&&r
004
MC/DC0%0/3
defined $guild_id and not ref $guild_id and $guild_id =~ /\A\d{1,20}\z/u
defined $guild_id not ref $guild_id $guild_id =~ /\A\d{1,20}\z/u
Truth table25%1/4
A and not(B) and C
A= defined $guild_idB= not ref $guild_idC= $guild_id =~ /\A\d{1,20}\z/u
ABCresult
0XX0
10X0
1100
1111
221  
222 # Use integer arithmetic so routing also works on Perls with smaller native integers.
223 4 my $id = Math::BigInt->new($guild_id);
224 4 ▶ croak 'Guild ID exceeds uint64' if $id->bcmp('18446744073709551615') > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $id->bcmp("18446744073709551615") > 0 1 3 4
225 3 return $id->brsft(22)->bmod( $self->{total} )->numify;
226 }
227  
228 2 ▶sub send {
Subroutine send: called CC=8 SCAR=24.2
Pod documented
229 2 my ( $self, $opcode, $data, %args ) = @_;
230  
231 # Resolve the target explicitly; a guild ID takes precedence over a shard ID.
232 2 my ( $id, $error );
233 2 ▶ if ( exists $args{guild_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'guild_id'}) { } 1 1 2
234 1 $id = eval { $self->shard_for_guild( $args{guild_id} ) };
235 1 $error = $@;
236 }
237 else {
238 1 ▶ $id = $args{shard_id} // 0;
Condition50%1/2
$args{"shard_id"} // 0
l!l
10
MC/DC0%0/1
$args{"shard_id"} // 0
$args{"shard_id"}
Truth table50%1/2
A
A= $args{"shard_id"}
Aresult
11
00
239 }
240 return $self->_failed( 'Invalid target shard', 'request' )
241 2 ▶ if $error || !defined($id) || ref($id) || $id !~ /\A\d+\z/ || !$self->{shards}{$id};
Branch: 1 branch
BranchTrueFalseTotal
if $error or not defined $id or ref $id or not $id =~ /\A\d+\z/u or not $self->{"shards"}{$id} 0 2 2
Condition33%4/12
$error or not defined $id or ref $id or not $id =~ /\A\d+\z/u or not $self->{"shards"}{$id}
l!l&&r!l&&!r
002
$error or not defined $id or ref $id or not $id =~ /\A\d+\z/u
l!l&&r!l&&!r
002
$error or not defined $id or ref $id
l!l&&r!l&&!r
002
$error or not defined $id
l!l&&r!l&&!r
002
MC/DC0%0/5
$error or not defined $id or ref $id or not $id =~ /\A\d+\z/u or not $self->{"shards"}{$id}
$error not defined $id ref $id not $id =~ /\A\d+\z/u not $self->{"shards"}{$id}
Truth table16%1/6
A or not(B) or C or not(D) or not(E)
A= $errorB= not defined $idC= ref $idD= not $id =~ /\A\d+\z/uE= not $self->{"shards"}{$id}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
242 2 return $self->{shards}{$id}->send( $opcode, $data );
243 }
244  
245 1 ▶sub broadcast {
Subroutine broadcast: called CC=2 SCAR=7.0
Pod documented
246 1 my ( $self, $opcode, $data ) = @_;
247 1 ▶ return $self->_failed( 'Shards are not ready', 'state' ) unless $self->state eq 'ready';
Branch: 1 branch
BranchTrueFalseTotal
unless $self->state eq "ready" 0 1 1
248 1 return Future->needs_all( map { $_->send( $opcode, $data ) } values %{ $self->{shards} } );
249 }
250  
251 0 ▶sub stats {
Subroutine stats: not called CC=1 SCAR=6.9
Pod documented
252 0 my ($self) = @_;
253 return {
254 state => $self->state,
255 total => $self->{total},
256 identify => $self->{limiter}->stats,
257 0 shards => { map { $_ => $self->{shards}{$_}->stats } keys %{ $self->{shards} } }
258 };
259 }
260  
261 12 ▶sub close {
Subroutine close: called CC=5 SCAR=16.1
Pod documented
262 12 my ($self) = @_;
263 12 ▶ return $self->{closing} if $self->{closing};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"closing"} 0 12 12
264  
265 # Stop group admission before closing children and the shared scheduler.
266 12 $self->{closed} = 1;
267 12 $self->{state} = 'closed';
268 $self->{ready}->fail( $self->_failed( 'Shard manager closed', 'shutdown' )->failure )
269 12 ▶ if $self->{ready} && !$self->{ready}->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ready"} and not $self->{"ready"}->is_ready 1 11 12
Condition100%3/3
$self->{"ready"} and not $self->{"ready"}->is_ready
!ll&&!rl&&r
831
MC/DC100%2/2
$self->{"ready"} and not $self->{"ready"}->is_ready
$self->{"ready"} not $self->{"ready"}->is_ready
Truth table100%3/3
A and not(B)
A= $self->{"ready"}B= not $self->{"ready"}->is_ready
ABresult
0X0
100
111
270 12 my @closing = map { $_->close } values %{ $self->{shards} };
271 12 push @closing, $self->{limiter}->close;
272 12 ▶ push @closing, $self->{rest}->close if $self->{own_rest};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"own_rest"} 0 12 12
273 12 $self->{handlers} = {};
274 12 $self->{dispatch_observers} = [];
275  
276 # The manager lifetime ends only after all shutdown Futures settle.
277 12 my $future = $self->{closing} = Future->needs_all(@closing);
278 12 ▶ $future->on_ready( sub { $self->{completion}->done unless $self->{completion}->is_ready } );
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"completion"}->is_ready 9 3 12
279 12 return $future;
280 }
281  
282 2 1;
283  
284 __END__
« blib/lib/Discord/Client.pm ↑ Summary blib/lib/Discord/Client/Gateway/WebSocket.pm »