lib/At/UserAgent.pm

filter: Statementstmt 16.8% 51 / 302 Branchbran 0.0% 0 / 220 Conditioncond 0.0% 0 / 135 MC/DCmcdc 0.0% 0 / 72 Subroutinesub 36.1% 13 / 36 Podpod 42.8% 3 / 7 totaltotal 8.6% 67 / 772 CC 176 SCAR 71.3
CC
176
Cov
8%
post
2070.0
get
1892.0
post
1332.0
CRAP 1248.7
↑ Summary lib/At/Protocol/Session.pm »
1 4 ▶use v5.42;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 4 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use JSON::PP qw[decode_json encode_json];
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Digest::SHA;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Crypt::JWT;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Crypt::PRNG;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use experimental 'try';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use feature 'class';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶no warnings 'experimental::class';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 class At::UserAgent v1.8.0 {
14 4 field $accessJwt : reader : param = undef;
15 4 field $refreshJwt : reader : param = undef;
16 4 field $token_type : reader : param = 'Bearer';
17 4 field $dpop_key : reader : param = undef;
18 4 field $dpop_nonce;
19 4 field $auth;
20 4 field $at_protocol_proxy : param = undef;
21  
22 0 ▶ method at_protocol_proxy ( $new_val = undef ) {
Subroutine at_protocol_proxy: not called CC=3 SCAR=24.8
Pod undocumented
23 0 ▶ $at_protocol_proxy = $new_val if defined $new_val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_val 0 0 0
24 0 return $at_protocol_proxy;
25 }
26  
27 0 ▶ method dpop_nonce ( $new_val = undef ) {
Subroutine dpop_nonce: not called CC=3 SCAR=24.8
Pod undocumented
28 0 ▶ $dpop_nonce = $new_val if defined $new_val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_val 0 0 0
29 0 return $dpop_nonce;
30 }
31  
32 0 ▶ method auth ( $new_val = undef ) {
Subroutine auth: not called CC=3 SCAR=24.8
Pod undocumented
33 0 ▶ $auth = $new_val if defined $new_val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $new_val 0 0 0
34 0 return $auth;
35 }
36  
37 0 ▶ method set_tokens ( $access, $refresh, $type, $key ) {
Subroutine set_tokens: not called CC=3 SCAR=24.8
Pod documented
38 0 $accessJwt = $access;
39 0 $refreshJwt = $refresh;
40 0 ▶ $token_type = $type // 'Bearer';
Condition0%0/2
$type // "Bearer"
l!l
00
MC/DC0%0/1
$type // "Bearer"
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
41 0 $dpop_key = $key;
42 0 ▶ if ( defined $accessJwt ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $accessJwt) { } 0 0 0
43 0 $self->_set_auth_header( $token_type . ' ' . $accessJwt );
44 }
45 else {
46 0 $self->_set_auth_header(undef);
47 }
48 0 $self;
49 }
50  
51 0 ▶ method _generate_dpop_proof( $url, $method, $skip_ath = 0 ) {
Subroutine _generate_dpop_proof: not called CC=6 SCAR=37.4
52 0 ▶ return unless $dpop_key;
Branch: 1 branch
BranchTrueFalseTotal
unless $dpop_key 0 0 0
53 0 my $jwk_json = $dpop_key->export_key_jwk('public');
54 0 my $jwk = JSON::PP::decode_json($jwk_json);
55 0 my $now = time;
56 0 my $htu = URI->new($url);
57 0 $htu->query(undef);
58 0 $htu->fragment(undef);
59 0 my $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~';
60 0 my $payload
61 = { jti => Crypt::PRNG::random_string_from( $chars, 32 ), htm => $method, htu => $htu->as_string, iat => $now, exp => $now + 60, };
62 0 ▶ $payload->{nonce} = $dpop_nonce if defined $dpop_nonce;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dpop_nonce 0 0 0
63  
64 0 ▶ if ( $accessJwt && !$skip_ath ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($accessJwt and not $skip_ath) 0 0 0
Condition0%0/3
$accessJwt and not $skip_ath
!ll&&!rl&&r
000
MC/DC0%0/2
$accessJwt and not $skip_ath
$accessJwt not $skip_ath
Truth table0%0/3
A and not(B)
A= $accessJwtB= not $skip_ath
ABresult
0X0
100
111
65 0 $payload->{ath} = MIME::Base64::encode_base64url( Digest::SHA::sha256($accessJwt) );
66 0 $payload->{ath} =~ s/=+$//;
67 }
68 0 return Crypt::JWT::encode_jwt( payload => $payload, key => $dpop_key, alg => 'ES256', extra_headers => { typ => 'dpop+jwt', jwk => $jwk } );
69 }
70 0 ▶ method _set_auth_header ($token) { die "Abstract" }
Subroutine _set_auth_header: not called CC=1 SCAR=6.9
71 0 ▶ method get ( $url, $req = undef ) { die "Abstract" }
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
72 0 ▶ method post ( $url, $req = undef ) { die "Abstract" }
Subroutine post: not called CC=2 SCAR=17.9
Pod documented
73 0 ▶ method websocket ( $url, $cb ) { die "Abstract" }
Subroutine websocket: not called CC=1 SCAR=6.9
Pod undocumented
74 } class #
75 4 At::UserAgent::Tiny : isa(At::UserAgent) {
76 4 ▶ use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 field $agent : param
78 4 = HTTP::Tiny->new( agent => 'At.pm/Tiny', default_headers => { 'Content-Type' => 'application/json', Accept => 'application/json' } );
79  
80 0 ▶ method get( $url, $req = {} ) {
Subroutine get: not called CC=43 SCAR=75.5
81 0 ▶ $req //= {};
Condition0%0/2
$req //= {}
l!l
00
MC/DC0%0/1
$req //= {}
$req
Truth table0%0/2
A
A= $req
Aresult
11
00
82 0 ▶ $req->{headers}{DPoP} = $self->_generate_dpop_proof( $url, 'GET', $req->{skip_ath} ) if $self->token_type eq 'DPoP';
Branch: 1 branch
BranchTrueFalseTotal
if $self->token_type eq "DPoP" 0 0 0
83 my $res
84 0 ▶ = $agent->get( $url . ( defined $req->{content} && keys %{ $req->{content} } ? '?' . $agent->www_form_urlencode( $req->{content} ) : '' ),
Branch: 1 branch
BranchTrueFalseTotal
defined $req->{'headers'} ? : 0 0 0
85 0 ▶ { defined $req->{headers} ? ( headers => $req->{headers} ) : () } );
Branch: 1 branch
BranchTrueFalseTotal
defined $req->{'content'} && keys %{$$req{'content'};} ? : 0 0 0
Condition0%0/3
defined $req->{"content"} and keys %{$$req{"content"};}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $req->{"content"} and keys %{$$req{"content"};}
defined $req->{"content"} keys %{$$req{"content"};}
Truth table0%0/3
A and B
A= defined $req->{"content"}B= keys %{$$req{"content"};}
ABresult
0X0
100
111
86 0 ▶ if ( $res->{headers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"headers"}) 0 0 0
87 0 my $nonce;
88 0 foreach my $k ( keys %{ $res->{headers} } ) {
89 0 ▶ if ( lc($k) eq 'dpop-nonce' ) { $nonce = $res->{headers}{$k}; last; }
Branch: 1 branch
BranchTrueFalseTotal
if (lc $k eq "dpop-nonce") 0 0 0
90 }
91 0 ▶ $self->dpop_nonce($nonce) if defined $nonce && $nonce ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $nonce and $nonce ne "" 0 0 0
Condition0%0/3
defined $nonce and $nonce ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $nonce and $nonce ne ""
defined $nonce $nonce ne ""
Truth table0%0/3
A and B
A= defined $nonceB= $nonce ne ""
ABresult
0X0
100
111
92 }
93 0 ▶ $res->{content} = JSON::PP::decode_json( $res->{content} ) if $res->{content} && ( $res->{headers}{'content-type'} // '' ) =~ m[json];
Branch: 1 branch
BranchTrueFalseTotal
if $res->{"content"} and ($res->{"headers"}{"content-type"} // "") =~ /json/u 0 0 0
Condition0%0/5
$res->{"content"} and ($res->{"headers"}{"content-type"} // "") =~ /json/u
!ll&&!rl&&r
000
$res->{"headers"}{"content-type"} // ""
l!l
00
MC/DC0%0/2
$res->{"content"} and ($res->{"headers"}{"content-type"} // "") =~ /json/u
$res->{"content"} $res->{"headers"}{"content-type"}
Truth table0%0/3
A and B
A= $res->{"content"}B= $res->{"headers"}{"content-type"}
ABresult
0X0
100
111
94 0 ▶ unless ( $res->{success} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->{"success"}) 0 0 0
95 0 my $body = $res->{content};
96 0 ▶ if ( ( $res->{status} == 401 || $res->{status} == 400 ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"status"} == 401 || $res->{"status"} == 400 and not ref $body and $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/iu) 0 0 0
Condition0%0/9
$res->{"status"} == 401 || $res->{"status"} == 400 and not ref $body and $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/iu
!ll&&!rl&&r
000
$res->{"status"} == 401 || $res->{"status"} == 400 and not ref $body
!ll&&!rl&&r
000
$res->{"status"} == 401 or $res->{"status"} == 400
l!l&&r!l&&!r
000
MC/DC0%0/4
$res->{"status"} == 401 || $res->{"status"} == 400 and not ref $body and $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/iu
$res->{"status"} == 401 $res->{"status"} == 400 not ref $body $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/iu
Truth table0%0/7
A or B and not(C) and D
A= $res->{"status"} == 401B= $res->{"status"} == 400C= not ref $bodyD= $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/iu
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
97 !ref $body &&
98 $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/i ) {
99 0 ▶ my $retry_headers = { %{ $req->{headers} // {} } };
Condition0%0/2
$req->{"headers"} // {}
l!l
00
MC/DC0%0/1
$req->{"headers"} // {}
$req->{"headers"}
Truth table0%0/2
A
A= $req->{"headers"}
Aresult
11
00
100 0 ▶ $retry_headers->{DPoP} = $self->_generate_dpop_proof( $url, 'GET', $req->{skip_ath} ) if $self->token_type eq 'DPoP';
Branch: 1 branch
BranchTrueFalseTotal
if $self->token_type eq "DPoP" 0 0 0
101 $res
102 = $agent->get(
103 0 ▶ $url . ( defined $req->{content} && keys %{ $req->{content} } ? '?' . $agent->www_form_urlencode( $req->{content} ) : '' ),
Branch: 1 branch
BranchTrueFalseTotal
defined $req->{'content'} && keys %{$$req{'content'};} ? : 0 0 0
Condition0%0/3
defined $req->{"content"} and keys %{$$req{"content"};}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $req->{"content"} and keys %{$$req{"content"};}
defined $req->{"content"} keys %{$$req{"content"};}
Truth table0%0/3
A and B
A= defined $req->{"content"}B= keys %{$$req{"content"};}
ABresult
0X0
100
111
104 { headers => $retry_headers } );
105 0 ▶ if ( $res->{headers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"headers"}) 0 0 0
106 0 ▶ my $nonce = $res->{headers}{'dpop-nonce'} || $res->{headers}{'DPoP-Nonce'} || $res->{headers}{'dpop_nonce'};
Condition0%0/6
$res->{'headers'}{'dpop-nonce'} || $res->{'headers'}{'DPoP-Nonce'} || $res->{'headers'}{'dpop_nonce'}
l!l&&r!l&&!r
000
$res->{"headers"}{"dpop-nonce"} or $res->{"headers"}{"DPoP-Nonce"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$res->{'headers'}{'dpop-nonce'} || $res->{'headers'}{'DPoP-Nonce'} || $res->{'headers'}{'dpop_nonce'}
$res->{"headers"}{"dpop-nonce"} $res->{"headers"}{"DPoP-Nonce"} $res->{'headers'}{'dpop_nonce'}
Truth table0%0/4
A or B || C
A= $res->{"headers"}{"dpop-nonce"}B= $res->{"headers"}{"DPoP-Nonce"}C= $res->{'headers'}{'dpop_nonce'}
ABCresult
1XX1
01X1
0011
0000
107 0 ▶ $self->dpop_nonce($nonce) if defined $nonce && $nonce ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $nonce and $nonce ne "" 0 0 0
Condition0%0/3
defined $nonce and $nonce ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $nonce and $nonce ne ""
defined $nonce $nonce ne ""
Truth table0%0/3
A and B
A= defined $nonceB= $nonce ne ""
ABresult
0X0
100
111
108 }
109 0 ▶ $res->{content} = JSON::PP::decode_json( $res->{content} ) if $res->{content} && ( $res->{headers}{'content-type'} // '' ) =~ m[json];
Branch: 1 branch
BranchTrueFalseTotal
if $res->{"content"} and ($res->{"headers"}{"content-type"} // "") =~ /json/u 0 0 0
Condition0%0/5
$res->{"content"} and ($res->{"headers"}{"content-type"} // "") =~ /json/u
!ll&&!rl&&r
000
$res->{"headers"}{"content-type"} // ""
l!l
00
MC/DC0%0/2
$res->{"content"} and ($res->{"headers"}{"content-type"} // "") =~ /json/u
$res->{"content"} $res->{"headers"}{"content-type"}
Truth table0%0/3
A and B
A= $res->{"content"}B= $res->{"headers"}{"content-type"}
ABresult
0X0
100
111
110 }
111 }
112 0 ▶ unless ( $res->{success} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->{"success"}) 0 0 0
113 0 ▶ my $msg = $res->{reason} // 'Unknown error';
Condition0%0/2
$res->{"reason"} // "Unknown error"
l!l
00
MC/DC0%0/1
$res->{"reason"} // "Unknown error"
$res->{"reason"}
Truth table0%0/2
A
A= $res->{"reason"}
Aresult
11
00
114 0 ▶ if ( ref $res->{content} eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $res->{'content'} eq 'HASH') { } 0 0 0
elsif ($res->{'content'}) { } 0 0 0
115 0 my $json = $res->{content};
116 0 ▶ my $details = $json->{error} // '';
Condition0%0/2
$json->{"error"} // ""
l!l
00
MC/DC0%0/1
$json->{"error"} // ""
$json->{"error"}
Truth table0%0/2
A
A= $json->{"error"}
Aresult
11
00
117 0 ▶ if ( $json->{message} && $json->{message} ne $details ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{"message"} and $json->{"message"} ne $details) 0 0 0
Condition0%0/3
$json->{"message"} and $json->{"message"} ne $details
!ll&&!rl&&r
000
MC/DC0%0/2
$json->{"message"} and $json->{"message"} ne $details
$json->{"message"} $json->{"message"} ne $details
Truth table0%0/3
A and B
A= $json->{"message"}B= $json->{"message"} ne $details
ABresult
0X0
100
111
118 0 ▶ $details .= ( $details ? ': ' : '' ) . $json->{message};
Branch: 1 branch
BranchTrueFalseTotal
$details ? : 0 0 0
119 }
120 0 ▶ $msg .= ": " . $details if $details;
Branch: 1 branch
BranchTrueFalseTotal
if $details 0 0 0
121 0 ▶ $msg .= " - " . $json->{error_description} if $json->{error_description};
Branch: 1 branch
BranchTrueFalseTotal
if $json->{"error_description"} 0 0 0
122 }
123 elsif ( $res->{content} ) {
124 0 $msg .= " (" . $res->{content} . ")";
125 }
126 0 $res->{content} = At::Error->new( message => $msg, fatal => 1 );
127 }
128 0 ▶ wantarray ? ( $res->{content}, $res->{headers} ) : $res->{content};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
129 }
130  
131 0 ▶ method post( $url, $req = {} ) {
Subroutine post: not called CC=45 SCAR=76.4
132 0 ▶ $req //= {};
Condition0%0/2
$req //= {}
l!l
00
MC/DC0%0/1
$req //= {}
$req
Truth table0%0/2
A
A= $req
Aresult
11
00
133 0 ▶ $req->{headers}{DPoP} = $self->_generate_dpop_proof( $url, 'POST', $req->{skip_ath} ) if $self->token_type eq 'DPoP';
Branch: 1 branch
BranchTrueFalseTotal
if $self->token_type eq "DPoP" 0 0 0
134 0 my $content;
135 0 ▶ if ( defined $req->{content} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $req->{"content"}) 0 0 0
136 0 ▶ if ( $req->{encoding} && $req->{encoding} eq 'form' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($req->{'encoding'} and $req->{'encoding'} eq 'form') { } 0 0 0
elsif (ref $req->{'content'}) { } 0 0 0
Condition0%0/3
$req->{"encoding"} and $req->{"encoding"} eq "form"
!ll&&!rl&&r
000
MC/DC0%0/2
$req->{"encoding"} and $req->{"encoding"} eq "form"
$req->{"encoding"} $req->{"encoding"} eq "form"
Truth table0%0/3
A and B
A= $req->{"encoding"}B= $req->{"encoding"} eq "form"
ABresult
0X0
100
111
137 0 $content = $agent->www_form_urlencode( $req->{content} );
138 0 $req->{headers}{'Content-Type'} = 'application/x-www-form-urlencoded';
139 }
140 elsif ( ref $req->{content} ) {
141 0 $content = JSON::PP::encode_json( $req->{content} );
142 0 $req->{headers}{'Content-Type'} = 'application/json';
143 }
144 else {
145 0 $content = $req->{content};
146 }
147 }
148 my $res = $agent->post( $url,
149 0 ▶ { defined $req->{headers} ? ( headers => $req->{headers} ) : (), defined $content ? ( content => $content ) : () } );
Branch: 2 branches
BranchTrueFalseTotal
defined $req->{'headers'} ? : 0 0 0
defined $content ? : 0 0 0
150 0 ▶ if ( $res->{headers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"headers"}) 0 0 0
151 0 my $nonce;
152 0 foreach my $k ( keys %{ $res->{headers} } ) {
153 0 ▶ if ( lc($k) eq 'dpop-nonce' ) { $nonce = $res->{headers}{$k}; last; }
Branch: 1 branch
BranchTrueFalseTotal
if (lc $k eq "dpop-nonce") 0 0 0
154 }
155 0 ▶ $self->dpop_nonce($nonce) if defined $nonce && $nonce ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $nonce and $nonce ne "" 0 0 0
Condition0%0/3
defined $nonce and $nonce ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $nonce and $nonce ne ""
defined $nonce $nonce ne ""
Truth table0%0/3
A and B
A= defined $nonceB= $nonce ne ""
ABresult
0X0
100
111
156 }
157 0 ▶ $res->{content} = JSON::PP::decode_json( $res->{content} ) if $res->{content} && ( $res->{headers}{'content-type'} // '' ) =~ m[json];
Branch: 1 branch
BranchTrueFalseTotal
if $res->{"content"} and ($res->{"headers"}{"content-type"} // "") =~ /json/u 0 0 0
Condition0%0/5
$res->{"content"} and ($res->{"headers"}{"content-type"} // "") =~ /json/u
!ll&&!rl&&r
000
$res->{"headers"}{"content-type"} // ""
l!l
00
MC/DC0%0/2
$res->{"content"} and ($res->{"headers"}{"content-type"} // "") =~ /json/u
$res->{"content"} $res->{"headers"}{"content-type"}
Truth table0%0/3
A and B
A= $res->{"content"}B= $res->{"headers"}{"content-type"}
ABresult
0X0
100
111
158 0 ▶ unless ( $res->{success} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->{"success"}) 0 0 0
159 0 my $body = $res->{content};
160 0 ▶ if ( ( $res->{status} == 401 || $res->{status} == 400 ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"status"} == 401 || $res->{"status"} == 400 and not ref $body and $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/iu) 0 0 0
Condition0%0/9
$res->{"status"} == 401 || $res->{"status"} == 400 and not ref $body and $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/iu
!ll&&!rl&&r
000
$res->{"status"} == 401 || $res->{"status"} == 400 and not ref $body
!ll&&!rl&&r
000
$res->{"status"} == 401 or $res->{"status"} == 400
l!l&&r!l&&!r
000
MC/DC0%0/4
$res->{"status"} == 401 || $res->{"status"} == 400 and not ref $body and $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/iu
$res->{"status"} == 401 $res->{"status"} == 400 not ref $body $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/iu
Truth table0%0/7
A or B and not(C) and D
A= $res->{"status"} == 401B= $res->{"status"} == 400C= not ref $bodyD= $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/iu
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
161 !ref $body &&
162 $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop|DPoP.*nonce/i ) {
163 0 ▶ my $retry_headers = { %{ $req->{headers} // {} } };
Condition0%0/2
$req->{"headers"} // {}
l!l
00
MC/DC0%0/1
$req->{"headers"} // {}
$req->{"headers"}
Truth table0%0/2
A
A= $req->{"headers"}
Aresult
11
00
164 0 ▶ $retry_headers->{DPoP} = $self->_generate_dpop_proof( $url, 'POST', $req->{skip_ath} ) if $self->token_type eq 'DPoP';
Branch: 1 branch
BranchTrueFalseTotal
if $self->token_type eq "DPoP" 0 0 0
165 0 my $retry_content = $content;
166 0 ▶ $res = $agent->post( $url, { headers => $retry_headers, defined $retry_content ? ( content => $retry_content ) : () } );
Branch: 1 branch
BranchTrueFalseTotal
defined $retry_content ? : 0 0 0
167 0 ▶ if ( $res->{headers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"headers"}) 0 0 0
168 0 ▶ my $nonce = $res->{headers}{'dpop-nonce'} || $res->{headers}{'DPoP-Nonce'} || $res->{headers}{'dpop_nonce'};
Condition0%0/6
$res->{'headers'}{'dpop-nonce'} || $res->{'headers'}{'DPoP-Nonce'} || $res->{'headers'}{'dpop_nonce'}
l!l&&r!l&&!r
000
$res->{"headers"}{"dpop-nonce"} or $res->{"headers"}{"DPoP-Nonce"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$res->{'headers'}{'dpop-nonce'} || $res->{'headers'}{'DPoP-Nonce'} || $res->{'headers'}{'dpop_nonce'}
$res->{"headers"}{"dpop-nonce"} $res->{"headers"}{"DPoP-Nonce"} $res->{'headers'}{'dpop_nonce'}
Truth table0%0/4
A or B || C
A= $res->{"headers"}{"dpop-nonce"}B= $res->{"headers"}{"DPoP-Nonce"}C= $res->{'headers'}{'dpop_nonce'}
ABCresult
1XX1
01X1
0011
0000
169 0 ▶ $self->dpop_nonce($nonce) if defined $nonce && $nonce ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $nonce and $nonce ne "" 0 0 0
Condition0%0/3
defined $nonce and $nonce ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $nonce and $nonce ne ""
defined $nonce $nonce ne ""
Truth table0%0/3
A and B
A= defined $nonceB= $nonce ne ""
ABresult
0X0
100
111
170 }
171 0 ▶ $res->{content} = JSON::PP::decode_json( $res->{content} ) if $res->{content} && ( $res->{headers}{'content-type'} // '' ) =~ m[json];
Branch: 1 branch
BranchTrueFalseTotal
if $res->{"content"} and ($res->{"headers"}{"content-type"} // "") =~ /json/u 0 0 0
Condition0%0/5
$res->{"content"} and ($res->{"headers"}{"content-type"} // "") =~ /json/u
!ll&&!rl&&r
000
$res->{"headers"}{"content-type"} // ""
l!l
00
MC/DC0%0/2
$res->{"content"} and ($res->{"headers"}{"content-type"} // "") =~ /json/u
$res->{"content"} $res->{"headers"}{"content-type"}
Truth table0%0/3
A and B
A= $res->{"content"}B= $res->{"headers"}{"content-type"}
ABresult
0X0
100
111
172 }
173 }
174 0 ▶ unless ( $res->{success} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->{"success"}) 0 0 0
175 0 ▶ my $msg = $res->{reason} // 'Unknown error';
Condition0%0/2
$res->{"reason"} // "Unknown error"
l!l
00
MC/DC0%0/1
$res->{"reason"} // "Unknown error"
$res->{"reason"}
Truth table0%0/2
A
A= $res->{"reason"}
Aresult
11
00
176 0 ▶ if ( ref $res->{content} eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $res->{'content'} eq 'HASH') { } 0 0 0
elsif ($res->{'content'}) { } 0 0 0
177 0 my $json = $res->{content};
178 0 ▶ my $details = $json->{error} // '';
Condition0%0/2
$json->{"error"} // ""
l!l
00
MC/DC0%0/1
$json->{"error"} // ""
$json->{"error"}
Truth table0%0/2
A
A= $json->{"error"}
Aresult
11
00
179 0 ▶ if ( $json->{message} && $json->{message} ne $details ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{"message"} and $json->{"message"} ne $details) 0 0 0
Condition0%0/3
$json->{"message"} and $json->{"message"} ne $details
!ll&&!rl&&r
000
MC/DC0%0/2
$json->{"message"} and $json->{"message"} ne $details
$json->{"message"} $json->{"message"} ne $details
Truth table0%0/3
A and B
A= $json->{"message"}B= $json->{"message"} ne $details
ABresult
0X0
100
111
180 0 ▶ $details .= ( $details ? ': ' : '' ) . $json->{message};
Branch: 1 branch
BranchTrueFalseTotal
$details ? : 0 0 0
181 }
182 0 ▶ $msg .= ": " . $details if $details;
Branch: 1 branch
BranchTrueFalseTotal
if $details 0 0 0
183 0 ▶ $msg .= " - " . $json->{error_description} if $json->{error_description};
Branch: 1 branch
BranchTrueFalseTotal
if $json->{"error_description"} 0 0 0
184 }
185 elsif ( $res->{content} ) {
186 0 $msg .= " (" . $res->{content} . ")";
187 }
188 0 $res->{content} = At::Error->new( message => $msg, fatal => 1 );
189 }
190 0 ▶ wantarray ? ( $res->{content}, $res->{headers} ) : $res->{content};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
191 }
192  
193 0 ▶ method websocket ( $url, $cb ) {
Subroutine websocket: not called CC=1 SCAR=6.9
194 0 die "At::UserAgent::Tiny does not support WebSockets. Please install Mojo::UserAgent.";
195 }
196  
197 0 ▶ method _set_auth_header($token) {
Subroutine _set_auth_header: not called CC=1 SCAR=6.9
198 0 $self->auth($token);
199 0 $agent->{default_headers}{Authorization} = $token;
200 }
201 } class #
202 4 At::UserAgent::Mojo : isa(At::UserAgent) {
203 4 field $agent : param = do { require Mojo::UserAgent; Mojo::UserAgent->new };
204  
205 0 ▶ method get( $url, $req = {} ) {
Subroutine get: not called CC=34 SCAR=70.8
206 0 ▶ $req //= {};
Condition0%0/2
$req //= {}
l!l
00
MC/DC0%0/1
$req //= {}
$req
Truth table0%0/2
A
A= $req
Aresult
11
00
207 0 ▶ my $headers = { %{ $req->{headers} // {} } };
Condition0%0/2
$req->{"headers"} // {}
l!l
00
MC/DC0%0/1
$req->{"headers"} // {}
$req->{"headers"}
Truth table0%0/2
A
A= $req->{"headers"}
Aresult
11
00
208 0 ▶ if ( $self->at_protocol_proxy ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->at_protocol_proxy) 0 0 0
209 0 $headers->{'atproto-proxy'} = $self->at_protocol_proxy;
210 }
211 0 ▶ $headers->{Authorization} = $self->auth if defined $self->auth;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->auth 0 0 0
212 0 ▶ $headers->{DPoP} = $self->_generate_dpop_proof( $url, 'GET', $req->{skip_ath} ) if $self->token_type eq 'DPoP';
Branch: 1 branch
BranchTrueFalseTotal
if $self->token_type eq "DPoP" 0 0 0
213 0 ▶ if ( $ENV{DEBUG} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DEBUG"}) 0 0 0
214 0 say "[DEBUG] [At] GET $url";
215 0 say "[DEBUG] [At] Headers: " . JSON::PP::encode_json($headers);
216 }
217 0 ▶ my $tx = $agent->get( $url, $headers, defined $req->{content} ? ( form => $req->{content} ) : () );
Branch: 1 branch
BranchTrueFalseTotal
defined $req->{'content'} ? : 0 0 0
218 0 my $res = $tx->result;
219 0 ▶ if ( my $nonce = $res->headers->header('DPoP-Nonce') ) { $self->dpop_nonce($nonce); }
Branch: 1 branch
BranchTrueFalseTotal
if (my $nonce = $res->headers->header("DPoP-Nonce")) 0 0 0
220 0 ▶ if ( $ENV{DEBUG} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DEBUG"}) 0 0 0
221 0 say "[DEBUG] [At] Response Code: " . $res->code;
222 0 say "[DEBUG] [At] Response Headers: " . JSON::PP::encode_json( $res->headers->to_hash );
223 }
224 0 ▶ if ( $res->code == 401 || $res->code == 400 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->code == 401 or $res->code == 400) 0 0 0
Condition0%0/3
$res->code == 401 or $res->code == 400
l!l&&r!l&&!r
000
MC/DC0%0/2
$res->code == 401 or $res->code == 400
$res->code == 401 $res->code == 400
Truth table0%0/3
A or B
A= $res->code == 401B= $res->code == 400
ABresult
1X1
011
000
225 0 ▶ my $body = $res->body // '';
Condition0%0/2
$res->body // ""
l!l
00
MC/DC0%0/1
$res->body // ""
$res->body
Truth table0%0/2
A
A= $res->body
Aresult
11
00
226 0 ▶ if ( $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop/iu) 0 0 0
227 0 ▶ say "[DEBUG] [At] Retrying with fresh DPoP nonce..." if $ENV{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG"} 0 0 0
228 0 ▶ $headers->{DPoP} = $self->_generate_dpop_proof( $url, 'GET', $req->{skip_ath} ) if $self->token_type eq 'DPoP';
Branch: 1 branch
BranchTrueFalseTotal
if $self->token_type eq "DPoP" 0 0 0
229 0 ▶ if ( $ENV{DEBUG} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DEBUG"}) 0 0 0
230 0 say "[DEBUG] [At] GET (Retry) $url";
231 0 say "[DEBUG] [At] Headers (Retry): " . JSON::PP::encode_json($headers);
232 }
233 0 ▶ $tx = $agent->get( $url, $headers, defined $req->{content} ? ( form => $req->{content} ) : () );
Branch: 1 branch
BranchTrueFalseTotal
defined $req->{'content'} ? : 0 0 0
234 0 $res = $tx->result;
235 0 ▶ if ( my $nonce = $res->headers->header('DPoP-Nonce') ) { $self->dpop_nonce($nonce); }
Branch: 1 branch
BranchTrueFalseTotal
if (my $nonce = $res->headers->header("DPoP-Nonce")) 0 0 0
236 0 ▶ if ( $ENV{DEBUG} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DEBUG"}) 0 0 0
237 0 say "[DEBUG] [At] Response Code (Retry): " . $res->code;
238 0 say "[DEBUG] [At] Response Headers (Retry): " . JSON::PP::encode_json( $res->headers->to_hash );
239 }
240 }
241 }
242 0 ▶ if ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) 0 0 0
243 0 ▶ my $content = $res->body ? ( $res->headers->content_type // '' ) =~ m[json] ? $res->json : $res->body : ();
Branch: 2 branches
BranchTrueFalseTotal
$res->body ? : 0 0 0
($res->headers->content_type // '') =~ /json/u ? : 0 0 0
Condition0%0/2
$res->headers->content_type // ""
l!l
00
MC/DC0%0/1
$res->headers->content_type // ""
$res->headers->content_type
Truth table0%0/2
A
A= $res->headers->content_type
Aresult
11
00
244 0 ▶ return wantarray ? ( $content, $res->headers->to_hash ) : $content;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
245 }
246 0 my $msg = $res->message;
247 0 ▶ if ( my $body = $res->body ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $res->body) 0 0 0
248 0 my $json;
249 0 try { $json = JSON::PP::decode_json($body) }
250 catch ($e) { }
251 0 ▶ if ($json) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json) { } 0 0 0
252 0 ▶ my $details = $json->{error} // '';
Condition0%0/2
$json->{"error"} // ""
l!l
00
MC/DC0%0/1
$json->{"error"} // ""
$json->{"error"}
Truth table0%0/2
A
A= $json->{"error"}
Aresult
11
00
253 0 ▶ if ( $json->{message} && $json->{message} ne $details ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{"message"} and $json->{"message"} ne $details) 0 0 0
Condition0%0/3
$json->{"message"} and $json->{"message"} ne $details
!ll&&!rl&&r
000
MC/DC0%0/2
$json->{"message"} and $json->{"message"} ne $details
$json->{"message"} $json->{"message"} ne $details
Truth table0%0/3
A and B
A= $json->{"message"}B= $json->{"message"} ne $details
ABresult
0X0
100
111
254 0 ▶ $details .= ( $details ? ': ' : '' ) . $json->{message};
Branch: 1 branch
BranchTrueFalseTotal
$details ? : 0 0 0
255 }
256 0 ▶ $msg .= ": " . $details if $details;
Branch: 1 branch
BranchTrueFalseTotal
if $details 0 0 0
257 0 ▶ $msg .= " - " . $json->{error_description} if $json->{error_description};
Branch: 1 branch
BranchTrueFalseTotal
if $json->{"error_description"} 0 0 0
258 }
259 else {
260 0 $msg .= " (" . $body . ")";
261 }
262 }
263 0 return At::Error->new( message => $msg, fatal => 1 );
264 }
265  
266 0 ▶ method post( $url, $req = {} ) {
Subroutine post: not called CC=36 SCAR=71.9
267 0 ▶ $req //= {};
Condition0%0/2
$req //= {}
l!l
00
MC/DC0%0/1
$req //= {}
$req
Truth table0%0/2
A
A= $req
Aresult
11
00
268 0 ▶ my $headers = { %{ $req->{headers} // {} } };
Condition0%0/2
$req->{"headers"} // {}
l!l
00
MC/DC0%0/1
$req->{"headers"} // {}
$req->{"headers"}
Truth table0%0/2
A
A= $req->{"headers"}
Aresult
11
00
269 0 ▶ if ( $self->at_protocol_proxy ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->at_protocol_proxy) 0 0 0
270 0 $headers->{'atproto-proxy'} = $self->at_protocol_proxy;
271 }
272 0 ▶ $headers->{Authorization} = $self->auth if defined $self->auth;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->auth 0 0 0
273 0 ▶ $headers->{DPoP} = $self->_generate_dpop_proof( $url, 'POST', $req->{skip_ath} ) if $self->token_type eq 'DPoP';
Branch: 1 branch
BranchTrueFalseTotal
if $self->token_type eq "DPoP" 0 0 0
274 0 ▶ if ( $ENV{DEBUG} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DEBUG"}) 0 0 0
275 0 say "[DEBUG] [At] POST $url";
276 0 say "[DEBUG] [At] Headers: " . JSON::PP::encode_json($headers);
277 }
278 0 my %args;
279 0 ▶ if ( defined $req->{content} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $req->{"content"}) 0 0 0
280 0 ▶ if ( $req->{encoding} && $req->{encoding} eq 'form' ) { $args{form} = $req->{content}; }
Branch: 2 branches
BranchTrueFalseTotal
if ($req->{'encoding'} and $req->{'encoding'} eq 'form') { } 0 0 0
elsif (ref $req->{'content'}) { } 0 0 0
Condition0%0/3
$req->{"encoding"} and $req->{"encoding"} eq "form"
!ll&&!rl&&r
000
MC/DC0%0/2
$req->{"encoding"} and $req->{"encoding"} eq "form"
$req->{"encoding"} $req->{"encoding"} eq "form"
Truth table0%0/3
A and B
A= $req->{"encoding"}B= $req->{"encoding"} eq "form"
ABresult
0X0
100
111
281 0 elsif ( ref $req->{content} ) { $args{json} = $req->{content}; }
282 0 else { $args{content} = $req->{content}; }
283 }
284 0 my $tx = $agent->post( $url, $headers, %args );
285 0 my $res = $tx->result;
286 0 ▶ if ( my $nonce = $res->headers->header('DPoP-Nonce') ) { $self->dpop_nonce($nonce); }
Branch: 1 branch
BranchTrueFalseTotal
if (my $nonce = $res->headers->header("DPoP-Nonce")) 0 0 0
287 0 ▶ if ( $ENV{DEBUG} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DEBUG"}) 0 0 0
288 0 say "[DEBUG] [At] Response Code: " . $res->code;
289 0 say "[DEBUG] [At] Response Headers: " . JSON::PP::encode_json( $res->headers->to_hash );
290 }
291 0 ▶ if ( $res->code == 401 || $res->code == 400 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->code == 401 or $res->code == 400) 0 0 0
Condition0%0/3
$res->code == 401 or $res->code == 400
l!l&&r!l&&!r
000
MC/DC0%0/2
$res->code == 401 or $res->code == 400
$res->code == 401 $res->code == 400
Truth table0%0/3
A or B
A= $res->code == 401B= $res->code == 400
ABresult
1X1
011
000
292 0 ▶ my $body = $res->body // '';
Condition0%0/2
$res->body // ""
l!l
00
MC/DC0%0/1
$res->body // ""
$res->body
Truth table0%0/2
A
A= $res->body
Aresult
11
00
293 0 ▶ if ( $body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($body =~ /use_dpop_nonce|dpop_nonce|required nonce|nonce in dpop/iu) 0 0 0
294 0 ▶ say "[DEBUG] [At] Retrying with fresh DPoP nonce..." if $ENV{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG"} 0 0 0
295 0 ▶ $headers->{DPoP} = $self->_generate_dpop_proof( $url, 'POST', $req->{skip_ath} ) if $self->token_type eq 'DPoP';
Branch: 1 branch
BranchTrueFalseTotal
if $self->token_type eq "DPoP" 0 0 0
296 0 ▶ if ( $ENV{DEBUG} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DEBUG"}) 0 0 0
297 0 say "[DEBUG] [At] POST (Retry) $url";
298 0 say "[DEBUG] [At] Headers (Retry): " . JSON::PP::encode_json($headers);
299 }
300 0 $tx = $agent->post( $url, $headers, %args );
301 0 $res = $tx->result;
302 0 ▶ if ( my $nonce = $res->headers->header('DPoP-Nonce') ) { $self->dpop_nonce($nonce); }
Branch: 1 branch
BranchTrueFalseTotal
if (my $nonce = $res->headers->header("DPoP-Nonce")) 0 0 0
303 0 ▶ if ( $ENV{DEBUG} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DEBUG"}) 0 0 0
304 0 say "[DEBUG] [At] Response Code (Retry): " . $res->code;
305 0 say "[DEBUG] [At] Response Headers (Retry): " . JSON::PP::encode_json( $res->headers->to_hash );
306 }
307 }
308 }
309 0 ▶ if ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) 0 0 0
310 0 ▶ my $content = $res->body ? ( $res->headers->content_type // '' ) =~ m[json] ? $res->json : $res->body : ();
Branch: 2 branches
BranchTrueFalseTotal
$res->body ? : 0 0 0
($res->headers->content_type // '') =~ /json/u ? : 0 0 0
Condition0%0/2
$res->headers->content_type // ""
l!l
00
MC/DC0%0/1
$res->headers->content_type // ""
$res->headers->content_type
Truth table0%0/2
A
A= $res->headers->content_type
Aresult
11
00
311 0 ▶ return wantarray ? ( $content, $res->headers->to_hash ) : $content;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
312 }
313 0 my $msg = $res->message;
314 0 ▶ if ( my $body = $res->body ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $res->body) 0 0 0
315 0 my $json;
316 0 try { $json = JSON::PP::decode_json($body) }
317 catch ($e) { }
318 0 ▶ if ($json) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json) { } 0 0 0
319 0 ▶ my $details = $json->{error} // '';
Condition0%0/2
$json->{"error"} // ""
l!l
00
MC/DC0%0/1
$json->{"error"} // ""
$json->{"error"}
Truth table0%0/2
A
A= $json->{"error"}
Aresult
11
00
320 0 ▶ if ( $json->{message} && $json->{message} ne $details ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{"message"} and $json->{"message"} ne $details) 0 0 0
Condition0%0/3
$json->{"message"} and $json->{"message"} ne $details
!ll&&!rl&&r
000
MC/DC0%0/2
$json->{"message"} and $json->{"message"} ne $details
$json->{"message"} $json->{"message"} ne $details
Truth table0%0/3
A and B
A= $json->{"message"}B= $json->{"message"} ne $details
ABresult
0X0
100
111
321 0 ▶ $details .= ( $details ? ': ' : '' ) . $json->{message};
Branch: 1 branch
BranchTrueFalseTotal
$details ? : 0 0 0
322 }
323 0 ▶ $msg .= ": " . $details if $details;
Branch: 1 branch
BranchTrueFalseTotal
if $details 0 0 0
324 0 ▶ $msg .= " - " . $json->{error_description} if $json->{error_description};
Branch: 1 branch
BranchTrueFalseTotal
if $json->{"error_description"} 0 0 0
325 }
326 else {
327 0 $msg .= " (" . $body . ")";
328 }
329 }
330 0 return At::Error->new( message => $msg, fatal => 1 );
331 }
332  
333 0 ▶ method websocket( $url, $cb ) {
Subroutine websocket: not called CC=1 SCAR=6.9
334 0 $agent->inactivity_timeout(0); # Disable inactivity timeout for firehose
335 $agent->websocket(
336 0 ▶ $url => sub ( $ua, $tx ) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
337 0 ▶ if ( !$tx->is_websocket ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tx->is_websocket) 0 0 0
338 0 $cb->( undef, At::Error->new( message => "WebSocket handshake failed", fatal => 0 ) );
339 0 return;
340 }
341  
342 # Keep-alive heartbeat every 20 seconds
343 my $id = Mojo::IOLoop->recurring(
344 0 ▶ 20 => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
345 0 ▶ return unless $tx;
Branch: 1 branch
BranchTrueFalseTotal
unless $tx 0 0 0
346 0 $tx->send( [ 1, 0, 0, 0, 9, '' ] ); # Raw Ping frame
347 }
348 0 );
349  
350 # Activity watchdog: if we don't get a message for 10 seconds, close and reconnect
351 0 my $watchdog;
352 0 ▶ my $reset_watchdog = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
353 0 ▶ Mojo::IOLoop->remove($watchdog) if defined $watchdog;
Branch: 1 branch
BranchTrueFalseTotal
if defined $watchdog 0 0 0
354 $watchdog = Mojo::IOLoop->timer(
355 0 ▶ 10 => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
356 0 $tx->finish( 4000, "Watchdog timeout" );
357 }
358 0 );
359 0 };
360 0 $reset_watchdog->();
361 $tx->on(
362 0 ▶ message => sub ( $tx, $msg ) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
363 0 $reset_watchdog->();
364 0 $cb->( $msg, undef );
365 }
366 0 );
367 $tx->on(
368 0 ▶ finish => sub ( $tx, $code, $reason ) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
369 0 ▶ Mojo::IOLoop->remove($id) if defined $id;
Branch: 1 branch
BranchTrueFalseTotal
if defined $id 0 0 0
370 0 ▶ Mojo::IOLoop->remove($watchdog) if defined $watchdog;
Branch: 1 branch
BranchTrueFalseTotal
if defined $watchdog 0 0 0
371 0 ▶ $cb->( undef, At::Error->new( message => "WebSocket finished: $code " . ( $reason // '' ), fatal => 0 ) );
Condition0%0/2
$reason // ""
l!l
00
MC/DC0%0/1
$reason // ""
$reason
Truth table0%0/2
A
A= $reason
Aresult
11
00
372 0 $tx = undef;
373 }
374 0 );
375 }
376 0 );
377 }
378 0 ▶ method _set_auth_header($token) { $self->auth($token); }
Subroutine _set_auth_header: not called CC=1 SCAR=6.9
379 4 } 1;
380 __END__
↑ Summary lib/At/Protocol/Session.pm »