blib/lib/Discord/Client/Intents.pm

filter: Statementstmt 95.4% 21 / 22 Branchbran 75.0% 3 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 82.0% 32 / 39 CC 5 SCAR 11.7
CC
5
Cov
86%
bits
5.2
names
2.0
BEGIN
1.0
CRAP 3.2
« blib/lib/Discord/Client/Gateway/WebSocket.pm ↑ Summary blib/lib/Discord/Client/Model.pm »
1 package Discord::Client::Intents;
2  
3 15 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 15 our $VERSION = '0.003';
9  
10 # Keep Discord bit positions explicit, including gaps reserved by the protocol.
11 15 my %BITS = (
12 GUILDS => 1 << 0,
13 GUILD_MEMBERS => 1 << 1,
14 GUILD_MODERATION => 1 << 2,
15 GUILD_EXPRESSIONS => 1 << 3,
16 GUILD_INTEGRATIONS => 1 << 4,
17 GUILD_WEBHOOKS => 1 << 5,
18 GUILD_INVITES => 1 << 6,
19 GUILD_VOICE_STATES => 1 << 7,
20 GUILD_PRESENCES => 1 << 8,
21 GUILD_MESSAGES => 1 << 9,
22 GUILD_MESSAGE_REACTIONS => 1 << 10,
23 GUILD_MESSAGE_TYPING => 1 << 11,
24 DIRECT_MESSAGES => 1 << 12,
25 DIRECT_MESSAGE_REACTIONS => 1 << 13,
26 DIRECT_MESSAGE_TYPING => 1 << 14,
27 MESSAGE_CONTENT => 1 << 15,
28 GUILD_SCHEDULED_EVENTS => 1 << 16,
29 AUTO_MODERATION_CONFIGURATION => 1 << 20,
30 AUTO_MODERATION_EXECUTION => 1 << 21,
31 GUILD_MESSAGE_POLLS => 1 << 24,
32 DIRECT_MESSAGE_POLLS => 1 << 25,
33 );
34  
35 59 ▶sub bits {
Subroutine bits: called CC=5 SCAR=16.6
Pod documented
36 59 my ( $class, @names ) = @_;
37  
38 # Validate names before combining their bits; repeated names remain idempotent.
39 59 my $value = 0;
40 59 for my $name (@names) {
41 67 ▶ croak 'intent name must be a string' if !defined($name) || ref($name);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name or ref $name 0 67 67
Condition33%1/3
not defined $name or ref $name
l!l&&r!l&&!r
0067
MC/DC0%0/2
not defined $name or ref $name
not defined $name ref $name
Truth table33%1/3
not(A) or B
A= not defined $nameB= ref $name
ABresult
1X1
011
000
42 67 ▶ croak "unknown Discord intent: $name" if !exists $BITS{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $BITS{$name} 2 65 67
43 65 $value |= $BITS{$name};
44 }
45 57 return $value;
46 }
47  
48 0 ▶sub names { return sort keys %BITS }
Subroutine names: not called CC=1 SCAR=6.9
Pod documented
49  
50 15 1;
51  
52 __END__
« blib/lib/Discord/Client/Gateway/WebSocket.pm ↑ Summary blib/lib/Discord/Client/Model.pm »