blib/lib/Langertha/Knarr/Role/UpstreamHTTP.pm

filter: Statementstmt 82.5% 33 / 40 Branchbran 28.5% 4 / 14 Conditioncond 11.1% 1 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 66.6% 6 / 9 Podpod 100% 1 / 1 totaltotal 57.6% 45 / 78 CC 11 SCAR 22.5
CC
11
Cov
60%
is_upstream_timeout
20.0
__ANON__
12.0
_upstream_request_f
9.7
CRAP 9.5
« blib/lib/Langertha/Knarr/Protocol.pm ↑ Summary blib/lib/Langertha/Knarr/Protocol/Ollama.pm »
1 package Langertha::Knarr::Role::UpstreamHTTP;
2 # ABSTRACT: Timed Net::Async::HTTP client for handlers that call an upstream
3 34 our $VERSION = '1.103';
4 34 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 34 ▶use Net::Async::HTTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 34 ▶use IO::Async::Loop;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 34 has timeout => ( is => 'ro', isa => 'Num', default => 300 );
11  
12 34 has stall_timeout => ( is => 'ro', isa => 'Num', default => 120 );
13  
14 has loop => (
15 is => 'ro',
16 lazy => 1,
17 0 ▶ default => sub { IO::Async::Loop->new },
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 34 );
19  
20 34 has _http => ( is => 'ro', lazy => 1, builder => '_build_http' );
21 9 ▶sub _build_http {
Subroutine _build_http: called CC=1 SCAR=0.0
22 9 my ($self) = @_;
23 9 my $h = Net::Async::HTTP->new;
24 9 $self->loop->add($h);
25 9 return $h;
26 }
27  
28 0 ▶sub is_upstream_timeout {
Subroutine is_upstream_timeout: not called CC=4 SCAR=30.0
Pod documented
29 0 my ($class, $category) = @_;
30 0 ▶ return defined $category && ( $category eq 'timeout' || $category eq 'stall_timeout' ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $category && ($category eq 'timeout' || $category eq 'stall_timeout') ? : 0 0 0
Condition0%0/6
defined $category and $category eq "timeout" || $category eq "stall_timeout"
!ll&&!rl&&r
000
$category eq "timeout" or $category eq "stall_timeout"
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $category and $category eq "timeout" || $category eq "stall_timeout"
defined $category $category eq "timeout" $category eq "stall_timeout"
Truth table0%0/4
A and B or C
A= defined $categoryB= $category eq "timeout"C= $category eq "stall_timeout"
ABCresult
0XX0
1000
11X1
1011
31 }
32  
33 # Net::Async::HTTP treats a timeout of 0 as "expire now", so a disabled
34 # timeout is left out rather than passed. The URL in the failure drops its
35 # query and userinfo, where a key could sit.
36 9 ▶sub _upstream_request_f {
Subroutine _upstream_request_f: called CC=6 SCAR=22.7
37 9 my ($self, %args) = @_;
38 9 my $stream = delete $args{stream};
39 9 ▶ $stream = 1 if $args{on_header};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"on_header"} 9 0 9
40 9 ▶ my ($option, $secs) = $stream
Branch: 1 branch
BranchTrueFalseTotal
$stream ? : 9 0 9
41 ? ( stall_timeout => $self->stall_timeout )
42 : ( timeout => $self->timeout );
43 9 ▶ return $self->_http->do_request(%args) unless $secs && $secs > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $secs and $secs > 0 0 9 9
Condition33%1/3
$secs and $secs > 0
!ll&&!rl&&r
009
MC/DC0%0/2
$secs and $secs > 0
$secs $secs > 0
Truth table33%1/3
A and B
A= $secsB= $secs > 0
ABresult
0X0
100
111
44  
45 9 my $uri = $args{request}->uri->clone;
46 9 $uri->query(undef);
47 9 $uri->fragment(undef);
48 9 ▶ $uri->userinfo(undef) if $uri->can('userinfo');
Branch: 1 branch
BranchTrueFalseTotal
if $uri->can("userinfo") 9 0 9
49 9 my $what = ref($self) . ": upstream $uri";
50  
51 0 ▶ return $self->_http->do_request( %args, $option => $secs )->else( sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
52 0 my ($message, $category, @details) = @_;
53 0 ▶ return Future->fail(@_) unless __PACKAGE__->is_upstream_timeout($category);
Branch: 1 branch
BranchTrueFalseTotal
unless __PACKAGE__->is_upstream_timeout($category) 0 0 0
54 0 ▶ my $text = $category eq 'timeout'
Branch: 1 branch
BranchTrueFalseTotal
$category eq 'timeout' ? : 0 0 0
55 ? "$what timed out after ${secs}s"
56 : "$what timed out after ${secs}s without data";
57 0 return Future->fail( "$text\n", $category, @details );
58 9 });
59 }
60  
61 34 1;
62  
63 __END__
« blib/lib/Langertha/Knarr/Protocol.pm ↑ Summary blib/lib/Langertha/Knarr/Protocol/Ollama.pm »