| 1 | package Discord::Client::REST; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 22 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 22 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 22 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 22 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 22 | ▶ | use Digest::SHA qw(sha256_hex); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 22 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 22 | ▶ | use IO::Async::Loop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 22 | ▶ | use JSON::PP (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 22 | ▶ | use Net::Async::HTTP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 22 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 22 | ▶ | use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 22 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 22 | ▶ | use URI::Escape qw(uri_unescape); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 22 | ▶ | use Discord::Client (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 22 | ▶ | use Discord::Client::REST::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 22 | ▶ | use Discord::Client::REST::RateLimiter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 22 | our $VERSION = '0.004'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 148 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=34 SCAR=45.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 148 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Validate authentication and capacity before creating a transport. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 148 | ▶ | my $auth = $args{auth} // 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"auth"} // 1
MC/DC100%1/1
$args{"auth"} // 1
$args{"auth"}
Truth table100%2/2
A
A= $args{"auth"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 148 | ▶ | croak 'auth must be zero or one' unless !ref($auth) && $auth =~ /\A[01]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not ref $auth and $auth =~ /\A[01]\z/u
MC/DC0%0/2
not ref $auth and $auth =~ /\A[01]\z/u
not ref $auth
$auth =~ /\A[01]\z/u
Truth table33%1/3
not(A) and B
A= not ref $authB= $auth =~ /\A[01]\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 148 | ▶ | croak 'token is required' if $auth && ( !defined( $args{token} ) || !length( $args{token} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$auth and not defined $args{"token"} && length $args{"token"}
defined $args{'token'} && length $args{'token'}
MC/DC0%0/3
$auth and not defined $args{"token"} && length $args{"token"}
$auth
defined $args{'token'}
length $args{'token'}
Truth table50%2/4
A and not(B && C)
A= $authB= defined $args{'token'}C= length $args{'token'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | croak 'token must be a scalar without whitespace' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | if defined( $args{token} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 148 | ▶ | && ( ref( $args{token} ) || $args{token} =~ /[\s\x00-\x1f\x7f]/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $args{"token"} and ref $args{"token"} || $args{"token"} =~ /[\s\x00-\x1f\x7f]/u
ref $args{"token"} or $args{"token"} =~ /[\s\x00-\x1f\x7f]/u
MC/DC0%0/3
defined $args{"token"} and ref $args{"token"} || $args{"token"} =~ /[\s\x00-\x1f\x7f]/u
defined $args{"token"}
ref $args{"token"}
$args{"token"} =~ /[\s\x00-\x1f\x7f]/u
Truth table50%2/4
A and B or C
A= defined $args{"token"}B= ref $args{"token"}C= $args{"token"} =~ /[\s\x00-\x1f\x7f]/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 148 | ▶ | my $loop = $args{loop} // IO::Async::Loop->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{"loop"} // "IO::Async::Loop"->new
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 148 | my %limits = _scheduler_limits( \%args ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 148 | ▶ | my $timeout = $args{timeout} // 30; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"timeout"} // 30
MC/DC100%1/1
$args{"timeout"} // 30
$args{"timeout"}
Truth table100%2/2
A
A= $args{"timeout"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 148 | ▶ | croak 'timeout must be positive' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $timeout or not $timeout =~ /\A\d+(?:\.\d+)?\z/u or $timeout <= 0
ref $timeout or not $timeout =~ /\A\d+(?:\.\d+)?\z/u
MC/DC0%0/3
ref $timeout or not $timeout =~ /\A\d+(?:\.\d+)?\z/u or $timeout <= 0
ref $timeout
not $timeout =~ /\A\d+(?:\.\d+)?\z/u
$timeout <= 0
Truth table25%1/4
A or not(B) or C
A= ref $timeoutB= not $timeout =~ /\A\d+(?:\.\d+)?\z/uC= $timeout <= 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | if ref($timeout) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | || $timeout !~ /\A\d+(?:\.\d+)?\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | || $timeout <= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # Build an explicit API origin; credentials, query strings and fragments are invalid. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 148 | ▶ | my $base = $args{base_url} // 'https://discord.com/api/v10'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{"base_url"} // "https://discord.com/api/v10"
MC/DC100%1/1
$args{"base_url"} // "https://discord.com/api/v10"
$args{"base_url"}
Truth table100%2/2
A
A= $args{"base_url"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 148 | my $uri = URI->new($base); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 148 | ▶ | croak 'base_url must be an absolute HTTP(S) URL without credentials, query or fragment' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition35%5/14
($uri->scheme // "") =~ /\Ahttps?\z/u and $uri->host and not defined $uri->userinfo and not defined $uri->query and not defined $uri->fragment
($uri->scheme // "") =~ /\Ahttps?\z/u and $uri->host and not defined $uri->userinfo and not defined $uri->query
($uri->scheme // "") =~ /\Ahttps?\z/u and $uri->host and not defined $uri->userinfo
($uri->scheme // "") =~ /\Ahttps?\z/u and $uri->host
$uri->scheme // ""
MC/DC0%0/5
($uri->scheme // "") =~ /\Ahttps?\z/u and $uri->host and not defined $uri->userinfo and not defined $uri->query and not defined $uri->fragment
$uri->scheme
$uri->host
not defined $uri->userinfo
not defined $uri->query
not defined $uri->fragment
Truth table16%1/6
A and B and not(C) and not(D) and not(E)
A= $uri->schemeB= $uri->hostC= not defined $uri->userinfoD= not defined $uri->queryE= not defined $uri->fragment
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | unless ( $uri->scheme // '' ) =~ /\Ahttps?\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | && $uri->host | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | && !defined( $uri->userinfo ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | && !defined( $uri->query ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | && !defined( $uri->fragment ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 148 | $base =~ s{/\z}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 148 | ▶ | my $url = $args{user_agent_url} // 'https://github.com/viasnake/Discord-Client'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"user_agent_url"} // "https://github.com/viasnake/Discord-Client"
MC/DC0%0/1
$args{"user_agent_url"} // "https://github.com/viasnake/Discord-Client"
$args{"user_agent_url"}
Truth table50%1/2
A
A= $args{"user_agent_url"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 148 | ▶ | croak 'user_agent_url must be an HTTP(S) URL without whitespace or parentheses' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $url or not $url =~ m[\Ahttps?://[^\s()]+\z]u
MC/DC0%0/2
ref $url or not $url =~ m[\Ahttps?://[^\s()]+\z]u
ref $url
not $url =~ m[\Ahttps?://[^\s()]+\z]u
Truth table33%1/3
A or not(B)
A= ref $urlB= not $url =~ m[\Ahttps?://[^\s()]+\z]u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | if ref($url) || $url !~ m{\Ahttps?://[^\s()]+\z}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 148 | for my $key (qw(clock wall_clock delay on_diagnostic)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 592 | ▶ | croak "$key must be a code reference" if exists( $args{$key} ) && ref( $args{$key} ) ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $args{$key} and ref $args{$key} ne "CODE"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # A supplied transport stays caller-owned; an owned transport verifies TLS. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 148 | my $http = $args{http}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 148 | my $owns_http = !$http; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 148 | ▶ | if ($owns_http) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | $http = Net::Async::HTTP->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | fail_on_error => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | max_redirects => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | pipeline => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | SSL_verify_mode => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | SSL_verifycn_scheme => 'http', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | max_connections_per_host => $limits{max_in_flight}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 23 | timeout => $timeout, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 23 | $loop->add($http); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 148 | ▶ | croak 'http must provide do_request' unless blessed($http) && $http->can('do_request'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($http) and $http->can("do_request")
MC/DC0%0/2
builtin::blessed($http) and $http->can("do_request")
builtin::blessed($http)
$http->can("do_request")
Truth table33%1/3
A and B
A= builtin::blessed($http)B= $http->can("do_request")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | token => $args{token}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 148 | auth => 0 + $auth, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | loop => $loop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | http => $http, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | owns_http => $owns_http, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | base_url => $base, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | timeout => $timeout, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | user_agent => "DiscordBot ($url, $Discord::Client::VERSION)", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | json => JSON::PP->new->utf8->allow_nonref, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # Inject clocks and delays so scheduling is deterministic without network I/O. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | $self->{limiter} = Discord::Client::REST::RateLimiter->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | %limits, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | loop => $loop, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | on_diagnostic => $args{on_diagnostic}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 37 | ▶ | clock => $args{clock} // sub { clock_gettime(CLOCK_MONOTONIC) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | wall_clock => $args{wall_clock} // sub { time() }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | delay => $args{delay} // sub { $loop->delay_future( after => $_[0] ) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 148 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%6/9
$args{"clock"} // sub {
&clock_gettime(scalar CLOCK_MONOTONIC());
}
$args{"wall_clock"} // sub {
&Discord::Client::REST::time();
}
$args{"delay"} // sub {
$loop->delay_future("after", $_[0]);
}
MC/DC0%0/2
$args{"clock"} // sub {
&clock_gettime(scalar CLOCK_MONOTONIC());
}
$args{"clock"}
sub {
&clock_gettime(scalar CLOCK_MONOTONIC());
}
MC/DC0%0/2
$args{"wall_clock"} // sub {
&Discord::Client::REST::time();
}
$args{"wall_clock"}
sub {
&Discord::Client::REST::time();
}
MC/DC0%0/2
$args{"delay"} // sub {
$loop->delay_future("after", $_[0]);
}
$args{"delay"}
sub {
$loop->delay_future("after", $_[0]);
}
Truth table66%2/3
A // B
A= $args{"clock"}B= sub {
&clock_gettime(scalar CLOCK_MONOTONIC());
}
Truth table66%2/3
A // B
A= $args{"wall_clock"}B= sub {
&Discord::Client::REST::time();
}
Truth table66%2/3
A // B
A= $args{"delay"}B= sub {
$loop->delay_future("after", $_[0]);
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 148 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 148 | ▶ | sub _scheduler_limits { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scheduler_limits: called CC=9 SCAR=24.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 148 | my ($options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # Retries may be disabled; queue and concurrency capacities must remain positive. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 148 | my %limits = ( max_pending => 1000, max_buckets => 1024, max_in_flight => 8, max_retries => 3 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 148 | for my $key ( keys %limits ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 592 | ▶ | $limits{$key} = $options->{$key} if exists $options->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 592 | ▶ | my $requirement = $key eq 'max_retries' ? 'a nonnegative integer' : 'a positive integer'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | croak "$key must be $requirement" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | if !defined( $limits{$key} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | || ref( $limits{$key} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | || $limits{$key} !~ /\A\d+\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 592 | ▶ | || ( $limits{$key} == 0 && $key ne 'max_retries' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition41%5/12
not defined $limits{$key} or ref $limits{$key} or not $limits{$key} =~ /\A\d+\z/u or $limits{$key} == 0 and $key ne "max_retries"
not defined $limits{$key} or ref $limits{$key} or not $limits{$key} =~ /\A\d+\z/u
not defined $limits{$key} or ref $limits{$key}
$limits{$key} == 0 and $key ne "max_retries"
MC/DC0%0/5
not defined $limits{$key} or ref $limits{$key} or not $limits{$key} =~ /\A\d+\z/u or $limits{$key} == 0 and $key ne "max_retries"
not defined $limits{$key}
ref $limits{$key}
not $limits{$key} =~ /\A\d+\z/u
$limits{$key} == 0
$key ne "max_retries"
Truth table33%2/6
not(A) or B or not(C) or D and E
A= not defined $limits{$key}B= ref $limits{$key}C= not $limits{$key} =~ /\A\d+\z/uD= $limits{$key} == 0E= $key ne "max_retries"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 148 | return %limits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 78 | ▶ | sub loop { $_[0]->{loop} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
loop: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 11 | ▶ | sub stats { $_[0]->{limiter}->stats } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stats: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 23 | ▶ | sub _endpoint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_endpoint: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 23 | my ( $self, $method, $pattern, $ids, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # Validate each resource segment before inserting it into a fixed endpoint. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 23 | for my $id (@$ids) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 30 | ▶ | return $self->_fail( $self->{loop}->new_future, 'Invalid resource ID', 'request' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $id and not ref $id and $id =~ /\A\d{1,20}\z/u
defined $id and not ref $id
MC/DC33%1/3
defined $id and not ref $id and $id =~ /\A\d{1,20}\z/u
defined $id
not ref $id
$id =~ /\A\d{1,20}\z/u
Truth table50%2/4
A and not(B) and C
A= defined $idB= not ref $idC= $id =~ /\A\d{1,20}\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | unless defined($id) && !ref($id) && $id =~ /\A\d{1,20}\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 29 | $pattern =~ s/\{id\}/$id/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 22 | return $self->request( $method, $pattern, %args ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | ▶ | sub get_current_user { $_[0]->request( 'GET', '/users/@me' ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_current_user: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | ▶ | sub get_user { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_user: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | my ( $self, $user_id ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | return $self->_endpoint( 'GET', '/users/{id}', [$user_id] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | sub get_channel { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_channel: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | my ( $self, $channel_id ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | return $self->_endpoint( 'GET', '/channels/{id}', [$channel_id] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | ▶ | sub get_guild { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_guild: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | my ( $self, $guild_id, %query ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | return $self->_endpoint( 'GET', '/guilds/{id}', [$guild_id], query => \%query ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | ▶ | sub get_guild_channels { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_guild_channels: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 3 | my ( $self, $guild_id ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | return $self->_endpoint( 'GET', '/guilds/{id}/channels', [$guild_id] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | sub get_guild_member { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_guild_member: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | my ( $self, $guild_id, $user_id ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | return $self->_endpoint( 'GET', '/guilds/{id}/members/{id}', [ $guild_id, $user_id ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | ▶ | sub get_message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | my ( $self, $channel_id, $message_id ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | return $self->_endpoint( 'GET', '/channels/{id}/messages/{id}', [ $channel_id, $message_id ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 4 | ▶ | sub get_messages { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_messages: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | my ( $self, $channel_id, %query ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 4 | ▶ | return $self->_fail( $self->{loop}->new_future, 'Invalid message pagination', 'request' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | unless _valid_message_query( \%query ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | return $self->_endpoint( 'GET', '/channels/{id}/messages', [$channel_id], query => \%query ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 4 | ▶ | sub _valid_message_query { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_valid_message_query: called CC=14 SCAR=29.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | my ($query) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # Pagination selects at most one position and a bounded page size. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 4 | ▶ | return 0 if grep { $_ !~ /\A(?:before|after|around|limit)\z/ } keys %$query; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 4 | ▶ | return 0 if ( grep { exists $query->{$_} } qw(before after around) ) > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 3 | for my $key (qw(before after around)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 9 | ▶ | next unless exists $query->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 2 | my $id = $query->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | ▶ | return 0 unless defined($id) && !ref($id) && $id =~ /\A\d{1,20}\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $id and not ref $id and $id =~ /\A\d{1,20}\z/u
defined $id and not ref $id
MC/DC33%1/3
defined $id and not ref $id and $id =~ /\A\d{1,20}\z/u
defined $id
not ref $id
$id =~ /\A\d{1,20}\z/u
Truth table50%2/4
A and not(B) and C
A= defined $idB= not ref $idC= $id =~ /\A\d{1,20}\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 2 | ▶ | if ( exists $query->{limit} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 2 | my $limit = $query->{limit}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 2 | ▶ | return 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition41%5/12
defined $limit and not ref $limit and $limit =~ /\A\d+\z/u and $limit >= 1 and $limit <= 100
defined $limit and not ref $limit and $limit =~ /\A\d+\z/u and $limit >= 1
defined $limit and not ref $limit and $limit =~ /\A\d+\z/u
defined $limit and not ref $limit
MC/DC20%1/5
defined $limit and not ref $limit and $limit =~ /\A\d+\z/u and $limit >= 1 and $limit <= 100
defined $limit
not ref $limit
$limit =~ /\A\d+\z/u
$limit >= 1
$limit <= 100
Truth table33%2/6
A and not(B) and C and D and E
A= defined $limitB= not ref $limitC= $limit =~ /\A\d+\z/uD= $limit >= 1E= $limit <= 100
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | unless defined($limit) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | && !ref($limit) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | && $limit =~ /\A\d+\z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | && $limit >= 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | && $limit <= 100; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 9 | ▶ | sub _message_body { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_message_body: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 9 | my ( $self, $method, $path, $ids, $body ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # Accept text as a convenience while preserving native Discord message fields. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 9 | ▶ | $body = { content => "$body" } if defined($body) && !ref($body); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $body and not ref $body
MC/DC50%1/2
defined $body and not ref $body
defined $body
not ref $body
Truth table66%2/3
A and not(B)
A= defined $bodyB= not ref $body
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 9 | ▶ | return $self->_fail( $self->{loop}->new_future, 'Message body must be text or a hash reference', 'request' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | unless ref($body) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 9 | return $self->_endpoint( $method, $path, $ids, json => $body ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 7 | ▶ | sub create_message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 7 | my ( $self, $channel_id, $body ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 7 | return $self->_message_body( 'POST', '/channels/{id}/messages', [$channel_id], $body ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | ▶ | sub edit_message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
edit_message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 2 | my ( $self, $channel_id, $message_id, $body ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 2 | return $self->_message_body( 'PATCH', '/channels/{id}/messages/{id}', [ $channel_id, $message_id ], $body ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 2 | ▶ | sub delete_message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_message: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 2 | my ( $self, $channel_id, $message_id ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | return $self->_endpoint( 'DELETE', '/channels/{id}/messages/{id}', [ $channel_id, $message_id ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 2 | ▶ | sub create_dm { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_dm: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | my ( $self, $id ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 2 | ▶ | return $self->_fail( $self->{loop}->new_future, 'Invalid resource ID', 'request' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $id and not ref $id and $id =~ /\A\d{1,20}\z/u
defined $id and not ref $id
MC/DC33%1/3
defined $id and not ref $id and $id =~ /\A\d{1,20}\z/u
defined $id
not ref $id
$id =~ /\A\d{1,20}\z/u
Truth table50%2/4
A and not(B) and C
A= defined $idB= not ref $idC= $id =~ /\A\d{1,20}\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | unless defined($id) && !ref($id) && $id =~ /\A\d{1,20}\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | return $self->request( 'POST', '/users/@me/channels', json => { recipient_id => "$id" } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | ▶ | sub trigger_typing { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trigger_typing: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | my ( $self, $channel_id ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | return $self->_endpoint( 'POST', '/channels/{id}/typing', [$channel_id] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 158 | ▶ | sub request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request: called CC=19 SCAR=31.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 158 | my ( $self, $method, $path, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # Reject invalid arguments before admitting the request to the scheduler. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 158 | my $future = $self->{loop}->new_future; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 158 | ▶ | my $auth = exists( $args{auth} ) ? $args{auth} : $self->{auth}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 158 | ▶ | return $self->_fail( $future, 'auth must be zero or one', 'request' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $auth and not ref $auth and $auth =~ /\A[01]\z/u
defined $auth and not ref $auth
MC/DC0%0/3
defined $auth and not ref $auth and $auth =~ /\A[01]\z/u
defined $auth
not ref $auth
$auth =~ /\A[01]\z/u
Truth table25%1/4
A and not(B) and C
A= defined $authB= not ref $authC= $auth =~ /\A[01]\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | unless defined($auth) && !ref($auth) && $auth =~ /\A[01]\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | return $self->_fail( $future, 'Bot authorization requires a token', 'request' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 158 | ▶ | if $auth && ( !defined( $self->{token} ) || !length( $self->{token} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$auth and not defined $self->{"token"} && length $self->{"token"}
defined $self->{'token'} && length $self->{'token'}
MC/DC66%2/3
$auth and not defined $self->{"token"} && length $self->{"token"}
$auth
defined $self->{'token'}
length $self->{'token'}
Truth table75%3/4
A and not(B && C)
A= $authB= defined $self->{'token'}C= length $self->{'token'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 157 | ▶ | return $self->_fail( $future, 'Invalid HTTP method', 'request' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $method and not ref $method and $method =~ /\A(?:GET|POST|PUT|PATCH|DELETE|HEAD)\z/u
defined $method and not ref $method
MC/DC0%0/3
defined $method and not ref $method and $method =~ /\A(?:GET|POST|PUT|PATCH|DELETE|HEAD)\z/u
defined $method
not ref $method
$method =~ /\A(?:GET|POST|PUT|PATCH|DELETE|HEAD)\z/u
Truth table25%1/4
A and not(B) and C
A= defined $methodB= not ref $methodC= $method =~ /\A(?:GET|POST|PUT|PATCH|DELETE|HEAD)\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | unless defined($method) && !ref($method) && $method =~ /\A(?:GET|POST|PUT|PATCH|DELETE|HEAD)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 157 | ▶ | return $self->_fail( $future, 'Path must be relative to the Discord API', 'request' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%9/12
defined $path and not ref $path and $path =~ m[\A/[^/]]u and not $path =~ /[\s\x00-\x1f\x7f#]/u and not $path =~ m[(?:\A|/)\.\.?(?:/|\?|\z)]u
defined $path and not ref $path and $path =~ m[\A/[^/]]u and not $path =~ /[\s\x00-\x1f\x7f#]/u
defined $path and not ref $path and $path =~ m[\A/[^/]]u
defined $path and not ref $path
MC/DC60%3/5
defined $path and not ref $path and $path =~ m[\A/[^/]]u and not $path =~ /[\s\x00-\x1f\x7f#]/u and not $path =~ m[(?:\A|/)\.\.?(?:/|\?|\z)]u
defined $path
not ref $path
$path =~ m[\A/[^/]]u
not $path =~ /[\s\x00-\x1f\x7f#]/u
not $path =~ m[(?:\A|/)\.\.?(?:/|\?|\z)]u
Truth table66%4/6
A and not(B) and C and not(D) and not(E)
A= defined $pathB= not ref $pathC= $path =~ m[\A/[^/]]uD= not $path =~ /[\s\x00-\x1f\x7f#]/uE= not $path =~ m[(?:\A|/)\.\.?(?:/|\?|\z)]u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | unless defined($path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | && !ref($path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | && $path =~ m{\A/[^/]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | && $path !~ /[\s\x00-\x1f\x7f#]/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | && $path !~ m{(?:\A|/)\.\.?(?:/|\?|\z)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # Prepare the complete wire request before reserving any scheduler capacity. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 152 | my ( $request, $error ) = $self->_build_request( $method, $path, $auth, \%args ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 152 | ▶ | return $self->_fail( $future, $error, 'request' ) if defined $error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 151 | my $uri = $request->uri; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # Separate route scheduling from secret values retained only for error redaction. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 151 | my ( $route, $major, $secrets ) = _route( $method, URI->new($path)->path ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 151 | ▶ | push @$secrets, $self->{token} if defined $self->{token}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | my $source = $self->{limiter}->submit( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | route => $route, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | major => $major, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | auth => 0 + $auth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | global_scope => $auth ? 'bot' : 'unauthenticated', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 150 | ▶ | send => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | $self->{http}->do_request( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | request => $request, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | host => $uri->host, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | port => $uri->port, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | SSL => $uri->scheme eq 'https', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | timeout => $self->{timeout}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 150 | max_redirects => 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 151 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # Propagate cancellation inward and sanitize transport results on the way out. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 151 | ▶ | $future->on_cancel( sub { $source->cancel unless $source->is_ready } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | $source->on_ready( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 151 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 151 | $self->_complete_request( $future, $source, $method, $secrets, $args{raw_response} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 151 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 151 | return $future; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 152 | ▶ | sub _build_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_request: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 152 | my ( $self, $method, $path, $auth, $options ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # Resolve the API-relative path and encode repeated query parameters explicitly. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 152 | my $uri = URI->new( $self->{base_url} . $path ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 152 | ▶ | if ( exists $options->{query} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | return ( undef, 'query must be a hash reference' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 6 | ▶ | unless ref( $options->{query} ) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 6 | my @query; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 6 | for my $key ( sort keys %{ $options->{query} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 8 | my $value = $options->{query}{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 8 | ▶ | push @query, $key, $_ for ref($value) eq 'ARRAY' ? @$value : ($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 6 | $uri->query_form(@query); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # Construct the wire request without allowing caller-supplied authorization headers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 152 | my $request = HTTP::Request->new( $method => $uri ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 152 | $request->protocol('HTTP/1.1'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 152 | $request->header( 'Host' => $uri->authority ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 152 | ▶ | $request->header( 'Authorization' => 'Bot ' . $self->{token} ) if $auth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 152 | $request->header( 'User-Agent' => $self->{user_agent} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 152 | $request->header( 'Content-Type' => 'application/json' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 152 | $request->header( 'Accept' => 'application/json' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # Serialize once so any rate-limit retry sends identical request bytes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 152 | ▶ | if ( exists $options->{json} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 70 | my $body = eval { $self->{json}->encode( $options->{json} ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 70 | ▶ | return ( undef, 'Request body is not JSON encodable' ) if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 69 | $request->content($body); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 151 | return ( $request, undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 151 | ▶ | sub _complete_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_complete_request: called CC=16 SCAR=28.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 151 | my ( $self, $future, $source, $method, $secrets, $raw_response ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # Cancellation callbacks run before readiness; do not re-enter cancellation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # when the scheduler reports the cancellation we just propagated inward. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 151 | ▶ | return if $future->is_ready || $future->is_cancelled; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$future->is_ready or $future->is_cancelled
MC/DC50%1/2
$future->is_ready or $future->is_cancelled
$future->is_ready
$future->is_cancelled
Truth table66%2/3
A or B
A= $future->is_readyB= $future->is_cancelled
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 141 | ▶ | if ( $source->is_cancelled ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $future->cancel; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # Scheduler failures may carry an HTTP response with useful status information. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 141 | my ( $message, $category, $response ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 141 | ▶ | if ( $source->is_failed ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 20 | ( $message, $category, $response ) = $source->failure; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 20 | ▶ | return $self->_fail( $future, $message, $category ) unless $response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 121 | ($response) = $source->result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | # HEAD and 204 responses have no JSON body to decode. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 125 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 125 | my $valid_json = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 125 | ▶ | if ( $response->code != 204 && $method ne 'HEAD' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$response->code != 204 and $method ne "HEAD"
MC/DC100%2/2
$response->code != 204 and $method ne "HEAD"
$response->code != 204
$method ne "HEAD"
Truth table100%3/3
A and B
A= $response->code != 204B= $method ne "HEAD"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 91 | $data = eval { $self->{json}->decode( $response->content ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 91 | $valid_json = !$@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # Expose structured diagnostics only after removing known credentials. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 125 | ▶ | if ( !$response->is_success || defined $category ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $response->is_success or defined $category
MC/DC50%1/2
not $response->is_success or defined $category
not $response->is_success
defined $category
Truth table66%2/3
not(A) or B
A= not $response->is_successB= defined $category
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 17 | ▶ | $category //= _http_error_category( $response->code ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$category //= _http_error_category($response->code)
MC/DC0%0/2
$category //= _http_error_category($response->code)
$category
_http_error_category($response->code)
Truth table66%2/3
A //= B
A= $categoryB= _http_error_category($response->code)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 17 | ▶ | $message //= 'Discord REST request failed (HTTP ' . $response->code . ')'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$message //= 'Discord REST request failed (HTTP ' . $response->code . ')'
MC/DC100%1/1
$message //= 'Discord REST request failed (HTTP ' . $response->code . ')'
$message
Truth table100%2/2
A
A= $message
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 17 | ▶ | my $request_id = $response->header('X-Request-ID') // $response->header('CF-Ray'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$response->header("X-Request-ID") // $response->header("CF-Ray")
MC/DC50%1/2
$response->header("X-Request-ID") // $response->header("CF-Ray")
$response->header("X-Request-ID")
$response->header("CF-Ray")
Truth table66%2/3
A // B
A= $response->header("X-Request-ID")B= $response->header("CF-Ray")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 17 | ▶ | return $self->_fail( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | $future, $message, $category, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | status => $response->code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | discord_code => _discord_error_code($data), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | request_id => _sanitize( $request_id, $secrets ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | details => $valid_json ? _sanitize( $data, $secrets ) : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 108 | ▶ | return $self->_fail( $future, 'Discord returned invalid JSON', 'json', status => $response->code ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | unless $valid_json; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | # A raw response must not retain the authenticated originating request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 107 | ▶ | if ($raw_response) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | my $copy = $response->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | $copy->request(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 1 | $future->done($copy); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 106 | $future->done($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 13 | ▶ | sub _http_error_category { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_http_error_category: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 13 | my ($status) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 13 | ▶ | return 'authentication' if $status == 401; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 9 | ▶ | return 'permission' if $status == 403; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 8 | ▶ | return 'not_found' if $status == 404; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 7 | ▶ | return 'server' if $status >= 500; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 4 | return 'http'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 17 | ▶ | sub _discord_error_code { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_discord_error_code: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 17 | my ($data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # Only expose a scalar numeric Discord code from the decoded response. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | return undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | unless ref($data) eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | && defined( $data->{code} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | && !ref( $data->{code} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 17 | ▶ | && $data->{code} =~ /\A\d+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
ref $data eq "HASH" and defined $data->{"code"} and not ref $data->{"code"} and $data->{"code"} =~ /\A\d+\z/u
ref $data eq "HASH" and defined $data->{"code"} and not ref $data->{"code"}
ref $data eq "HASH" and defined $data->{"code"}
MC/DC50%2/4
ref $data eq "HASH" and defined $data->{"code"} and not ref $data->{"code"} and $data->{"code"} =~ /\A\d+\z/u
ref $data eq "HASH"
defined $data->{"code"}
not ref $data->{"code"}
$data->{"code"} =~ /\A\d+\z/u
Truth table60%3/5
A and B and not(C) and D
A= ref $data eq "HASH"B= defined $data->{"code"}C= not ref $data->{"code"}D= $data->{"code"} =~ /\A\d+\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 10 | return $data->{code}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 151 | ▶ | sub _route { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_route: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 151 | my ( $method, $path ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # Keep major resource IDs distinct while normalizing ordinary resource IDs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 151 | my @segments = split m{/}, $path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 151 | my ( @major, @secrets ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 151 | ▶ | for ( my $segment_index = 1 ; $segment_index < @segments ; ++$segment_index ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 350 | my $segment = $segments[$segment_index]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # Major resource IDs partition buckets even when the remaining route shape matches. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 350 | ▶ | if ( $segment =~ /\A(?:channels|guilds|webhooks)\z/ && defined( $segments[ $segment_index + 1 ] ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$segment =~ /\A(?:channels|guilds|webhooks)\z/u and defined $segments[$segment_index + 1]
MC/DC100%2/2
$segment =~ /\A(?:channels|guilds|webhooks)\z/u and defined $segments[$segment_index + 1]
$segment =~ /\A(?:channels|guilds|webhooks)\z/u
defined $segments[$segment_index + 1]
Truth table100%3/3
A and B
A= $segment =~ /\A(?:channels|guilds|webhooks)\z/uB= defined $segments[$segment_index + 1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 92 | push @major, $segment, $segments[ $segment_index + 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 92 | ++$segment_index; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 92 | $segments[$segment_index] = ':major'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # Reserved subresource names are not treated as webhook token segments. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 92 | my $token = $segments[ $segment_index + 1 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 92 | ▶ | if ( $segment eq 'webhooks' && defined($token) && $token !~ /\A(?:messages|github|slack)\z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$segment eq "webhooks" and defined $token and not $token =~ /\A(?:messages|github|slack)\z/u
$segment eq "webhooks" and defined $token
MC/DC33%1/3
$segment eq "webhooks" and defined $token and not $token =~ /\A(?:messages|github|slack)\z/u
$segment eq "webhooks"
defined $token
not $token =~ /\A(?:messages|github|slack)\z/u
Truth table50%2/4
A and B and not(C)
A= $segment eq "webhooks"B= defined $tokenC= not $token =~ /\A(?:messages|github|slack)\z/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # Hash the token for bucket identity, but retain both spellings for redaction. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 16 | push @major, sha256_hex($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 16 | push @secrets, $token, uri_unescape($token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 16 | ++$segment_index; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 16 | $segments[$segment_index] = ':token'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 92 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # Callback tokens are opaque, including tokens consisting only of digits. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 258 | ▶ | if ( $segments[1] eq 'interactions' && $segment_index == 3 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$segments[1] eq "interactions" and $segment_index == 3
MC/DC100%2/2
$segments[1] eq "interactions" and $segment_index == 3
$segments[1] eq "interactions"
$segment_index == 3
Truth table100%3/3
A and B
A= $segments[1] eq "interactions"B= $segment_index == 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 34 | push @secrets, $segment, uri_unescape($segment); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 34 | $segments[$segment_index] = ':token'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 34 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 224 | ▶ | $segments[$segment_index] = ':id' if $segment =~ /\A\d+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # Only token hashes participate in bucket keys; plaintext is used for redaction. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 151 | my $major = join( ':', @major ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 151 | return ( $method . ' ' . join( '/', @segments ) . ' ' . $major, $major, \@secrets ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 68 | ▶ | sub _sanitize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sanitize: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 68 | my ( $value, $secrets ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # Redact both sensitive field names and known secrets nested in response data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 68 | ▶ | if ( ref($value) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 22 | ▶ | map { $_ => /(?:token|authorization|secret)/i ? '[REDACTED]' : _sanitize( $value->{$_}, $secrets ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | keys %$value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 46 | ▶ | if ( ref($value) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 1 | return [ map { _sanitize( $_, $secrets ) } @$value ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 45 | ▶ | return $value if !defined($value) || ref($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $value or ref $value
MC/DC50%1/2
not defined $value or ref $value
not defined $value
ref $value
Truth table66%2/3
not(A) or B
A= not defined $valueB= ref $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 33 | for my $secret (@$secrets) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 41 | ▶ | $value =~ s/\Q$secret\E/[REDACTED]/g if length $secret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 33 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 46 | ▶ | sub _fail { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fail: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 46 | my ( $self, $future, $message, $category, %details ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | # Use the same sanitized details in the Future tuple and structured REST error. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 46 | my $error = Discord::Client::REST::Error->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | message => $message, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | category => $category, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | %details, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 46 | return $future->fail( $message, $category, $error ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 148 | ▶ | sub close { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 148 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # Stop scheduled requests before detaching an owned HTTP transport. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 148 | my $future = $self->{limiter}->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 148 | ▶ | if ( $self->{owns_http} && $self->{http}->loop ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"owns_http"} and $self->{"http"}->loop
MC/DC50%1/2
$self->{"owns_http"} and $self->{"http"}->loop
$self->{"owns_http"}
$self->{"http"}->loop
Truth table66%2/3
A and B
A= $self->{"owns_http"}B= $self->{"http"}->loop
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 22 | $self->{loop}->remove( $self->{http} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 148 | return $future; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 22 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||