blib/lib/Discord/Client/Cache.pm

filter: Statementstmt 98.5% 134 / 136 Branchbran 78.1% 50 / 64 Conditioncond 63.4% 52 / 82 MC/DCmcdc 40.0% 18 / 45 Subroutinesub 100% 21 / 21 Podpod 100% 7 / 7 totaltotal 79.4% 282 / 355 CC 70 SCAR 25.6
CC
70
Cov
84%
apply
24.0
new
20.6
_key
15.2
CRAP 12.9
« blib/lib/Discord/Client/UI.pm ↑ Summary blib/lib/Discord/Client/Interaction/Verifier.pm »
1 package Discord::Client::Cache;
2  
3 3 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 our $VERSION = '0.002';
11  
12 6 ▶sub new {
Subroutine new: called CC=16 SCAR=30.3
Pod documented
13 6 my ( $class, %args ) = @_;
14  
15 # Bound both serialized data size and entry count; expiry uses monotonic time.
16 my $self = bless {
17 entries => {},
18 bytes => 0,
19 access_sequence => 0,
20 counters => {},
21 max_items => $args{max_items} // 1000,
22 max_bytes => $args{max_bytes} // 8 * 1024 * 1024,
23 max_entry_bytes => $args{max_entry_bytes} // 262144,
24 ttl => $args{ttl} // 300,
25 53 ▶ clock => $args{clock} // sub { clock_gettime(CLOCK_MONOTONIC) },
Subroutine __ANON__: called CC=1 SCAR=0.0
26 6 ▶ json => JSON::PP->new->utf8
Condition90%10/11
$args{"max_items"} // 1000
l!l
15
$args{"max_bytes"} // 8388608
l!l
15
$args{"max_entry_bytes"} // 262144
l!l
15
$args{"ttl"} // 300
l!l
15
$args{"clock"} // sub { &clock_gettime(scalar CLOCK_MONOTONIC()); }
l!l&&r!l&&!r
150
MC/DC100%1/1
$args{"max_items"} // 1000
$args{"max_items"}
MC/DC100%1/1
$args{"max_bytes"} // 8388608
$args{"max_bytes"}
MC/DC100%1/1
$args{"max_entry_bytes"} // 262144
$args{"max_entry_bytes"}
MC/DC100%1/1
$args{"ttl"} // 300
$args{"ttl"}
MC/DC0%0/2
$args{"clock"} // sub { &clock_gettime(scalar CLOCK_MONOTONIC()); }
$args{"clock"} sub { &clock_gettime(scalar CLOCK_MONOTONIC()); }
Truth table100%2/2
A
A= $args{"max_items"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"max_bytes"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"max_entry_bytes"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"ttl"}
Aresult
11
00
Truth table66%2/3
A // B
A= $args{"clock"}B= sub { &clock_gettime(scalar CLOCK_MONOTONIC()); }
ABresult
1X1
011
000
27 }, $class;
28  
29 # Reject invalid limits before any caller data can enter the cache.
30 6 for my $key (qw(max_items max_bytes max_entry_bytes ttl)) {
31 24 ▶ croak "$key must be a positive integer" unless !ref( $self->{$key} ) && $self->{$key} =~ /\A[1-9]\d*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $self->{$key} and $self->{$key} =~ /\A[1-9]\d*\z/u 0 24 24
Condition33%1/3
not ref $self->{$key} and $self->{$key} =~ /\A[1-9]\d*\z/u
!ll&&!rl&&r
0024
MC/DC0%0/2
not ref $self->{$key} and $self->{$key} =~ /\A[1-9]\d*\z/u
not ref $self->{$key} $self->{$key} =~ /\A[1-9]\d*\z/u
Truth table33%1/3
not(A) and B
A= not ref $self->{$key}B= $self->{$key} =~ /\A[1-9]\d*\z/u
ABresult
0X0
100
111
32 }
33 6 ▶ croak 'clock must be a code reference' unless ref( $self->{clock} ) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"clock"} eq "CODE" 0 6 6
34  
35 # Cache only explicitly supported resource snapshots, without automatic fetches.
36 6 ▶ my $types = $args{types} // [qw(guild channel user message)];
Condition100%2/2
$args{"types"} // ["guild", "channel", "user", "message"]
l!l
33
MC/DC100%1/1
$args{"types"} // ["guild", "channel", "user", "message"]
$args{"types"}
Truth table100%2/2
A
A= $args{"types"}
Aresult
11
00
37 6 ▶ croak 'types must be an array reference' unless ref($types) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $types eq "ARRAY" 0 6 6
38 6 for my $type (@$types) {
39 15 ▶ croak 'Unknown cache type'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and not ref $type and $type =~ /\A(?:guild|channel|user|message)\z/u 0 15 15
Condition33%2/6
defined $type and not ref $type and $type =~ /\A(?:guild|channel|user|message)\z/u
!ll&&!rl&&r
0015
defined $type and not ref $type
!ll&&!rl&&r
0015
MC/DC0%0/3
defined $type and not ref $type and $type =~ /\A(?:guild|channel|user|message)\z/u
defined $type not ref $type $type =~ /\A(?:guild|channel|user|message)\z/u
Truth table25%1/4
A and not(B) and C
A= defined $typeB= not ref $typeC= $type =~ /\A(?:guild|channel|user|message)\z/u
ABCresult
0XX0
10X0
1100
1111
40 unless defined($type) && !ref($type) && $type =~ /\A(?:guild|channel|user|message)\z/;
41 15 $self->{types}{$type} = 1;
42 }
43 6 return $self;
44 }
45  
46 47 ▶sub _key {
Subroutine _key: called CC=7 SCAR=27.2
47 47 my ( $type, $id ) = @_;
48  
49 # Include the resource type so equal IDs in different collections remain distinct.
50 47 ▶ croak 'Invalid cache type or ID'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and not ref $type and $type =~ /\A(?:guild|channel|user|message)\z/u and defined $id and not ref $id and $id =~ /\A\d{1,20}\z/u 0 47 47
Condition33%5/15
defined $type and not ref $type and $type =~ /\A(?:guild|channel|user|message)\z/u and defined $id and not ref $id and $id =~ /\A\d{1,20}\z/u
!ll&&!rl&&r
0047
defined $type and not ref $type and $type =~ /\A(?:guild|channel|user|message)\z/u and defined $id and not ref $id
!ll&&!rl&&r
0047
defined $type and not ref $type and $type =~ /\A(?:guild|channel|user|message)\z/u and defined $id
!ll&&!rl&&r
0047
defined $type and not ref $type and $type =~ /\A(?:guild|channel|user|message)\z/u
!ll&&!rl&&r
0047
defined $type and not ref $type
!ll&&!rl&&r
0047
MC/DC0%0/6
defined $type and not ref $type and $type =~ /\A(?:guild|channel|user|message)\z/u and defined $id and not ref $id and $id =~ /\A\d{1,20}\z/u
defined $type not ref $type $type =~ /\A(?:guild|channel|user|message)\z/u defined $id not ref $id $id =~ /\A\d{1,20}\z/u
Truth table14%1/7
A and not(B) and C and D and not(E) and F
A= defined $typeB= not ref $typeC= $type =~ /\A(?:guild|channel|user|message)\z/uD= defined $idE= not ref $idF= $id =~ /\A\d{1,20}\z/u
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
51 unless defined($type)
52 && !ref($type)
53 && $type =~ /\A(?:guild|channel|user|message)\z/
54 && defined($id)
55 && !ref($id)
56 && $id =~ /\A\d{1,20}\z/;
57 47 return "$type:$id";
58 }
59  
60 29 ▶sub _remove {
Subroutine _remove: called CC=2 SCAR=6.9
61 29 my ( $self, $key ) = @_;
62  
63 # Keep serialized-byte accounting correct for deletion and replacement alike.
64 29 my $old = delete $self->{entries}{$key};
65 29 ▶ $self->{bytes} -= $old->{size} if $old;
Branch: 1 branch
BranchTrueFalseTotal
if $old 13 16 29
66 29 return !!$old;
67 }
68  
69 47 ▶sub _expire {
Subroutine _expire: called CC=3 SCAR=11.0
70 47 my ($self) = @_;
71  
72 # Expiry is lazy and does not require another event-loop timer.
73 47 my $now = $self->{clock}->();
74 47 for my $key ( keys %{ $self->{entries} } ) {
75 86 ▶ next if $self->{entries}{$key}{expires} > $now;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"entries"}{$key}{"expires"} > $now 84 2 86
76 2 $self->_remove($key);
77 2 ++$self->{counters}{expired};
78 }
79 }
80  
81 24 ▶sub put {
Subroutine put: called CC=8 SCAR=20.8
Pod documented
82 24 my ( $self, $type, $data, %args ) = @_;
83  
84 # Validate identity before inspecting existing data or mutating storage.
85 24 ▶ croak 'Cached data must be a hash reference' unless ref($data) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 0 24 24
86 24 my $key = _key( $type, $data->{id} );
87 24 ▶ return 0 unless $self->{types}{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"types"}{$type} 4 20 24
88  
89 # Merge partial events only with live snapshots, including explicit null fields.
90 20 $self->_expire;
91 20 my $old = $self->{entries}{$key};
92 20 ▶ my $merged = $args{merge} && $old ? { %{ $old->{data} }, %$data } : {%$data};
Branch: 1 branch
BranchTrueFalseTotal
$args{'merge'} && $old ? : 4 16 20
Condition100%3/3
$args{"merge"} and $old
!ll&&!rl&&r
1424
MC/DC100%2/2
$args{"merge"} and $old
$args{"merge"} $old
Truth table100%3/3
A and B
A= $args{"merge"}B= $old
ABresult
0X0
100
111
93 20 my $encoded = eval { $self->{json}->encode($merged) };
94 20 ▶ croak 'Cache data must be JSON encodable' if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 20 20
95  
96 # An oversized replacement invalidates the old snapshot instead of leaving stale data.
97 20 ▶ if ( length($encoded) > $self->{max_entry_bytes} || length($encoded) > $self->{max_bytes} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $encoded > $self->{"max_entry_bytes"} or length $encoded > $self->{"max_bytes"}) 1 19 20
Condition66%2/3
length $encoded > $self->{"max_entry_bytes"} or length $encoded > $self->{"max_bytes"}
l!l&&r!l&&!r
1019
MC/DC50%1/2
length $encoded > $self->{"max_entry_bytes"} or length $encoded > $self->{"max_bytes"}
length $encoded > $self->{"max_entry_bytes"} length $encoded > $self->{"max_bytes"}
Truth table66%2/3
A or B
A= length $encoded > $self->{"max_entry_bytes"}B= length $encoded > $self->{"max_bytes"}
ABresult
1X1
011
000
98 1 ++$self->{counters}{oversized};
99 1 $self->_remove($key);
100 1 return 0;
101 }
102 19 $self->_remove($key);
103  
104 # Evict before committing a detached JSON snapshot and its fresh expiry time.
105 19 $self->_make_room( length($encoded) );
106 $self->{entries}{$key} = {
107 data => $self->{json}->decode($encoded),
108 size => length($encoded),
109 expires => $self->{clock}->() + $self->{ttl},
110 last_access_sequence => ++$self->{access_sequence},
111 19 type => $type,
112 };
113 19 $self->{bytes} += length($encoded);
114 19 ++$self->{counters}{stored};
115 19 return 1;
116 }
117  
118 19 ▶sub _make_room {
Subroutine _make_room: called CC=3 SCAR=11.0
119 19 my ( $self, $incoming_size ) = @_;
120  
121 # Access sequence numbers order reads and writes even when the clock has not advanced.
122 # Remove the oldest accesses until both capacity bounds can admit the incoming snapshot.
123 19 ▶ while ( keys( %{ $self->{entries} } ) >= $self->{max_items}
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$$self{"entries"};} >= $self->{"max_items"} or $self->{"bytes"} + $incoming_size > $self->{"max_bytes"}) 2 19 21
Condition100%3/3
keys %{$$self{"entries"};} >= $self->{"max_items"} or $self->{"bytes"} + $incoming_size > $self->{"max_bytes"}
l!l&&r!l&&!r
1119
MC/DC100%2/2
keys %{$$self{"entries"};} >= $self->{"max_items"} or $self->{"bytes"} + $incoming_size > $self->{"max_bytes"}
keys %{$$self{"entries"};} >= $self->{"max_items"} $self->{"bytes"} + $incoming_size > $self->{"max_bytes"}
Truth table100%3/3
A or B
A= keys %{$$self{"entries"};} >= $self->{"max_items"}B= $self->{"bytes"} + $incoming_size > $self->{"max_bytes"}
ABresult
1X1
011
000
124 || $self->{bytes} + $incoming_size > $self->{max_bytes} )
125 {
126 my ($least_recent_key) =
127 2 sort { $self->{entries}{$a}{last_access_sequence} <=> $self->{entries}{$b}{last_access_sequence} }
128 2 keys %{ $self->{entries} };
129 2 $self->_remove($least_recent_key);
130 2 ++$self->{counters}{evicted};
131 }
132 }
133  
134 20 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod documented
135 20 my ( $self, $type, $id ) = @_;
136  
137 # Expired entries are misses; reads update recency but not the write-based TTL.
138 20 my $key = _key( $type, $id );
139 20 $self->_expire;
140 20 my $entry = $self->{entries}{$key};
141 20 ▶ unless ($entry) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($entry) 6 14 20
142 6 ++$self->{counters}{misses};
143 6 return undef;
144 }
145 14 ++$self->{counters}{hits};
146 14 $entry->{last_access_sequence} = ++$self->{access_sequence};
147  
148 # Return a detached copy so caller mutations cannot corrupt the cache.
149 14 return $self->{json}->decode( $self->{json}->encode( $entry->{data} ) );
150 }
151  
152 3 ▶sub remove {
Subroutine remove: called CC=1 SCAR=0.0
Pod documented
153 3 my ( $self, $type, $id ) = @_;
154 3 return $self->_remove( _key( $type, $id ) );
155 }
156  
157 1 ▶sub clear {
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
158 1 my ($self) = @_;
159  
160 # Clear accounting together with snapshots so capacity is immediately reusable.
161 1 $self->{entries} = {};
162 1 $self->{bytes} = 0;
163 1 return;
164 }
165  
166 7 ▶sub stats {
Subroutine stats: called CC=1 SCAR=0.0
Pod documented
167 7 my ($self) = @_;
168 7 $self->_expire;
169 7 return { %{ $self->{counters} }, items => scalar( keys %{ $self->{entries} } ), bytes => $self->{bytes} };
170 }
171  
172 2 ▶sub _remove_related {
Subroutine _remove_related: called CC=5 SCAR=16.3
173 2 my ( $self, $field, $id ) = @_;
174  
175 # Delete observed dependants using explicit guild or channel references.
176 2 for my $key ( keys %{ $self->{entries} } ) {
177 7 my $data = $self->{entries}{$key}{data};
178 7 ▶ $self->_remove($key) if defined( $data->{$field} ) && !ref( $data->{$field} ) && $data->{$field} eq $id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $data->{$field} and not ref $data->{$field} and $data->{$field} eq $id 2 5 7
Condition66%4/6
defined $data->{$field} and not ref $data->{$field} and $data->{$field} eq $id
!ll&&!rl&&r
502
defined $data->{$field} and not ref $data->{$field}
!ll&&!rl&&r
502
MC/DC33%1/3
defined $data->{$field} and not ref $data->{$field} and $data->{$field} eq $id
defined $data->{$field} not ref $data->{$field} $data->{$field} eq $id
Truth table50%2/4
A and not(B) and C
A= defined $data->{$field}B= not ref $data->{$field}C= $data->{$field} eq $id
ABCresult
0XX0
10X0
1100
1111
179 }
180 }
181  
182 23 ▶sub _store_observed {
Subroutine _store_observed: called CC=5 SCAR=16.6
183 23 my ( $self, $type, $data, %options ) = @_;
184  
185 # Ignore event fragments without a valid resource identity.
186 return
187 23 ▶ unless ref($data) eq 'HASH' && defined( $data->{id} ) && !ref( $data->{id} ) && $data->{id} =~ /\A\d{1,20}\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" and defined $data->{"id"} and not ref $data->{"id"} and $data->{"id"} =~ /\A\d{1,20}\z/u 6 17 23
Condition66%6/9
ref $data eq "HASH" and defined $data->{"id"} and not ref $data->{"id"} and $data->{"id"} =~ /\A\d{1,20}\z/u
!ll&&!rl&&r
6017
ref $data eq "HASH" and defined $data->{"id"} and not ref $data->{"id"}
!ll&&!rl&&r
6017
ref $data eq "HASH" and defined $data->{"id"}
!ll&&!rl&&r
6017
MC/DC25%1/4
ref $data eq "HASH" and defined $data->{"id"} and not ref $data->{"id"} and $data->{"id"} =~ /\A\d{1,20}\z/u
ref $data eq "HASH" defined $data->{"id"} not ref $data->{"id"} $data->{"id"} =~ /\A\d{1,20}\z/u
Truth table40%2/5
A and B and not(C) and D
A= ref $data eq "HASH"B= defined $data->{"id"}C= not ref $data->{"id"}D= $data->{"id"} =~ /\A\d{1,20}\z/u
ABCDresult
0XXX0
10XX0
110X0
11100
11111
188 17 $self->put( $type, $data, %options );
189 }
190  
191 22 ▶sub apply {
Subroutine apply: called CC=21 SCAR=31.8
Pod documented
192 22 my ( $self, $event, $data ) = @_;
193 22 ▶ return unless ref($data) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 0 22 22
194  
195 # Apply Gateway snapshots and deletions without fetching missing resources.
196 22 ▶ if ( $event eq 'READY' ) {
Branch: 9 branches
BranchTrueFalseTotal
if ($event eq 'READY') { } 5 17 22
elsif ($event eq 'GUILD_CREATE' or $event eq 'GUILD_UPDATE') { } 3 14 17
elsif ($event eq 'GUILD_DELETE' and defined $data->{'id'}) { } 2 12 14
elsif ($event =~ /\A(?:CHANNEL|THREAD)_(CREATE|UPDATE)\z/u) { } 1 11 12
elsif ($event =~ /\A(?:CHANNEL|THREAD)_DELETE\z/u and defined $data->{'id'}) { } 1 10 11
elsif ($event eq 'MESSAGE_CREATE' or $event eq 'MESSAGE_UPDATE') { } 6 4 10
elsif ($event eq 'MESSAGE_DELETE' and defined $data->{'id'}) { } 0 4 4
elsif ($event eq 'MESSAGE_DELETE_BULK' and ref $data->{'ids'} eq 'ARRAY') { } 1 3 4
elsif ($event eq 'USER_UPDATE') { } 0 3 3
197 5 $self->_store_observed( user => $data->{user} );
198 5 ▶ my $guilds = ref( $data->{guilds} ) eq 'ARRAY' ? $data->{guilds} : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $data->{'guilds'} eq 'ARRAY' ? : 0 5 5
199 5 $self->_store_observed( guild => $_, merge => 1 ) for @$guilds;
200 }
201 ▶ elsif ( $event eq 'GUILD_CREATE' || $event eq 'GUILD_UPDATE' ) {
Condition66%2/3
$event eq "GUILD_CREATE" or $event eq "GUILD_UPDATE"
l!l&&r!l&&!r
3014
MC/DC50%1/2
$event eq "GUILD_CREATE" or $event eq "GUILD_UPDATE"
$event eq "GUILD_CREATE" $event eq "GUILD_UPDATE"
Truth table66%2/3
A or B
A= $event eq "GUILD_CREATE"B= $event eq "GUILD_UPDATE"
ABresult
1X1
011
000
202 3 $self->_store_guild_event( $event, $data );
203 }
204 ▶ elsif ( $event eq 'GUILD_DELETE' && defined( $data->{id} ) ) {
Condition66%2/3
$event eq "GUILD_DELETE" and defined $data->{"id"}
!ll&&!rl&&r
1202
MC/DC50%1/2
$event eq "GUILD_DELETE" and defined $data->{"id"}
$event eq "GUILD_DELETE" defined $data->{"id"}
Truth table66%2/3
A and B
A= $event eq "GUILD_DELETE"B= defined $data->{"id"}
ABresult
0X0
100
111
205  
206 # A temporary guild outage retains snapshots; a true departure removes dependants.
207 2 ▶ if ( $data->{unavailable} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{'unavailable'}) { } 1 1 2
208 1 $self->_store_observed( guild => $data, merge => 1 );
209 }
210 else {
211 1 $self->_remove_related( guild_id => $data->{id} );
212 1 $self->remove( guild => $data->{id} );
213 }
214 }
215 elsif ( $event =~ /\A(?:CHANNEL|THREAD)_(CREATE|UPDATE)\z/ ) {
216 1 $self->_store_observed( channel => $data, merge => $1 eq 'UPDATE' );
217 }
218 ▶ elsif ( $event =~ /\A(?:CHANNEL|THREAD)_DELETE\z/ && defined( $data->{id} ) ) {
Condition66%2/3
$event =~ /\A(?:CHANNEL|THREAD)_DELETE\z/u and defined $data->{"id"}
!ll&&!rl&&r
1001
MC/DC50%1/2
$event =~ /\A(?:CHANNEL|THREAD)_DELETE\z/u and defined $data->{"id"}
$event =~ /\A(?:CHANNEL|THREAD)_DELETE\z/u defined $data->{"id"}
Truth table66%2/3
A and B
A= $event =~ /\A(?:CHANNEL|THREAD)_DELETE\z/uB= defined $data->{"id"}
ABresult
0X0
100
111
219 1 $self->_remove_related( channel_id => $data->{id} );
220 1 $self->remove( channel => $data->{id} );
221 }
222 ▶ elsif ( $event eq 'MESSAGE_CREATE' || $event eq 'MESSAGE_UPDATE' ) {
Condition100%3/3
$event eq "MESSAGE_CREATE" or $event eq "MESSAGE_UPDATE"
l!l&&r!l&&!r
514
MC/DC100%2/2
$event eq "MESSAGE_CREATE" or $event eq "MESSAGE_UPDATE"
$event eq "MESSAGE_CREATE" $event eq "MESSAGE_UPDATE"
Truth table100%3/3
A or B
A= $event eq "MESSAGE_CREATE"B= $event eq "MESSAGE_UPDATE"
ABresult
1X1
011
000
223 6 $self->_store_observed( message => $data, merge => $event eq 'MESSAGE_UPDATE' );
224 6 $self->_store_observed( user => $data->{author}, merge => 1 );
225 }
226 ▶ elsif ( $event eq 'MESSAGE_DELETE' && defined( $data->{id} ) ) {
Condition33%1/3
$event eq "MESSAGE_DELETE" and defined $data->{"id"}
!ll&&!rl&&r
400
MC/DC0%0/2
$event eq "MESSAGE_DELETE" and defined $data->{"id"}
$event eq "MESSAGE_DELETE" defined $data->{"id"}
Truth table33%1/3
A and B
A= $event eq "MESSAGE_DELETE"B= defined $data->{"id"}
ABresult
0X0
100
111
227 0 $self->remove( message => $data->{id} );
228 }
229 ▶ elsif ( $event eq 'MESSAGE_DELETE_BULK' && ref( $data->{ids} ) eq 'ARRAY' ) {
Condition66%2/3
$event eq "MESSAGE_DELETE_BULK" and ref $data->{"ids"} eq "ARRAY"
!ll&&!rl&&r
301
MC/DC50%1/2
$event eq "MESSAGE_DELETE_BULK" and ref $data->{"ids"} eq "ARRAY"
$event eq "MESSAGE_DELETE_BULK" ref $data->{"ids"} eq "ARRAY"
Truth table66%2/3
A and B
A= $event eq "MESSAGE_DELETE_BULK"B= ref $data->{"ids"} eq "ARRAY"
ABresult
0X0
100
111
230 1 $self->remove( message => $_ ) for @{ $data->{ids} };
231 }
232 elsif ( $event eq 'USER_UPDATE' ) {
233 0 $self->_store_observed( user => $data, merge => 1 );
234 }
235 22 return;
236 }
237  
238 3 ▶sub _store_guild_event {
Subroutine _store_guild_event: called CC=8 SCAR=21.2
239 3 my ( $self, $event, $data ) = @_;
240  
241 # Keep large member/presence collections out of the lightweight guild snapshot.
242 3 my %guild = %$data;
243 3 delete @guild{qw(members presences voice_states channels threads)};
244 3 ▶ $guild{unavailable} //= JSON::PP::false if $event eq 'GUILD_CREATE';
Branch: 1 branch
BranchTrueFalseTotal
if $event eq "GUILD_CREATE" 3 0 3
Condition66%2/3
$guild{"unavailable"} //= JSON::PP::false()
l!l&&r!l&&!r
120
MC/DC0%0/2
$guild{"unavailable"} //= JSON::PP::false()
$guild{"unavailable"} JSON::PP::false()
Truth table66%2/3
A //= B
A= $guild{"unavailable"}B= JSON::PP::false()
ABresult
1X1
011
000
245 3 $self->_store_observed( guild => \%guild, merge => 1 );
246 3 ▶ return unless $event eq 'GUILD_CREATE';
Branch: 1 branch
BranchTrueFalseTotal
unless $event eq "GUILD_CREATE" 0 3 3
247  
248 # Channels and threads are independent entries with an explicit guild reference.
249 3 for my $field (qw(channels threads)) {
250 6 ▶ next unless ref( $data->{$field} ) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data->{$field} eq "ARRAY" 5 1 6
251 1 for my $channel ( @{ $data->{$field} } ) {
252 1 ▶ next unless ref($channel) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $channel eq "HASH" 0 1 1
253 1 $self->_store_observed( channel => { %$channel, guild_id => $data->{id} } );
254 }
255 }
256 }
257  
258 3 1;
259  
260 __END__
« blib/lib/Discord/Client/UI.pm ↑ Summary blib/lib/Discord/Client/Interaction/Verifier.pm »