| 1 | package PawsX::Waiter::Client; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use v5.20; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use feature qw(postderef say); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | no warnings qw(experimental::postderef); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Jmespath; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Data::Structure::Util qw(unbless); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use PawsX::Waiter::Exception; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | has client => ( | |||||||||||||||||||||||||||||||||||||||||
| 16 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | weak_ref => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | has delay => ( | |||||||||||||||||||||||||||||||||||||||||
| 22 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 23 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||
| 24 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | has maxAttempts => ( | |||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||
| 30 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | has operation => ( | |||||||||||||||||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||
| 36 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | has acceptors => ( | |||||||||||||||||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 41 | isa => 'ArrayRef[HashRef]', | ||||||||||||||||||||||||||||||||||||||||||
| 42 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | has 'beforeWait' => ( | |||||||||||||||||||||||||||||||||||||||||
| 46 | traits => ['Code'], | ||||||||||||||||||||||||||||||||||||||||||
| 47 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 48 | isa => 'CodeRef', | ||||||||||||||||||||||||||||||||||||||||||
| 49 | predicate => 'has_beforeWait', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | _beforeWait => 'execute_method', | ||||||||||||||||||||||||||||||||||||||||||
| 52 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub operation_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
operation_request: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my ( $self, $options ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $func = $self->operation; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $response = {}; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $response = $self->client->$func( $options->%* ); | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $error = $_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ( blessed($error) and $error->isa('Paws::Exception') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($error) and $error->isa("Paws::Exception")
MC/DC0%0/2
builtin::blessed($error) and $error->isa("Paws::Exception")
builtin::blessed($error)
$error->isa("Paws::Exception")
Truth table0%0/3
A and B
A= builtin::blessed($error)B= $error->isa("Paws::Exception")
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $response = { | |||||||||||||||||||||||||||||||||||||||||
| 68 | code => $error->code, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | request_id => $error->request_id, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | http_status => $error->http_status, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | message => $error->message, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | PawsX::Waiter::Exception->throw( | |||||||||||||||||||||||||||||||||||||||||
| 76 | name => $self->operation, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | reason => $error, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | last_response => $response, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | return blessed($response) ? unbless($response) : $response; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub wait { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wait: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my ( $self, $options ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $current_state = 'waiting'; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $num_attempts = 0; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $response = $self->operation_request($options); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $num_attempts++; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | ACCEPTOR: | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | foreach my $acceptor ( $self->acceptors->@* ) { | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ( my $status = $self->matcher( $acceptor, $response ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $current_state = $acceptor->{'state'}; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | last ACCEPTOR; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ( $current_state eq 'success' ) { return; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ( $current_state eq 'failure' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | PawsX::Waiter::Exception->throw( | |||||||||||||||||||||||||||||||||||||||||
| 107 | message => 'Waiter encountered a terminal failure state', | ||||||||||||||||||||||||||||||||||||||||||
| 108 | last_response => $response, | ||||||||||||||||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ( $num_attempts >= $self->maxAttempts ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | PawsX::Waiter::Exception::TimeOut->throw( | |||||||||||||||||||||||||||||||||||||||||
| 113 | message => 'Max attempts exceeded', | ||||||||||||||||||||||||||||||||||||||||||
| 114 | last_response => $response, | ||||||||||||||||||||||||||||||||||||||||||
| 115 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | $self->_beforeWait($num_attempts, $response) if $self->has_beforeWait; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | sleep( $self->delay ); | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub matcher { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
matcher: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my ( $self, $acceptor, $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $func = "match_" . $acceptor->{'matcher'}; | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | return $self->$func( $acceptor, $response ); | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub match_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_path: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my ( $self, $acceptor, $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ( 'HASH' eq ref $response ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | my $ret = | ||||||||||||||||||||||||||||||||||||||||||
| 137 | ( Jmespath->search( $acceptor->{'argument'}, $response ) eq | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | $acceptor->{'expected'} ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub match_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_error: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my ( $self, $acceptor, $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if ( 'HASH' eq ref $response && exists $response->{'code'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
"HASH" eq ref $response and exists $response->{"code"}
MC/DC0%0/2
"HASH" eq ref $response and exists $response->{"code"}
"HASH" eq ref $response
exists $response->{"code"}
Truth table0%0/3
A and B
A= "HASH" eq ref $responseB= exists $response->{"code"}
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | my $ret = | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | ( $response->{'code'} eq $acceptor->{'expected'} ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub match_pathAll { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_pathAll: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my ( $self, $acceptor, $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $expression = Jmespath->compile( $acceptor->{'argument'} ); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my $result = $expression->search($response); | |||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | unless ( ref $result && 'ARRAY' eq ref $result | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $result and "ARRAY" eq ref $result and length $result >= 1
ref $result and "ARRAY" eq ref $result
MC/DC0%0/3
ref $result and "ARRAY" eq ref $result and length $result >= 1
ref $result
"ARRAY" eq ref $result
length $result >= 1
Truth table0%0/4
A and B and C
A= ref $resultB= "ARRAY" eq ref $resultC= length $result >= 1
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | and length $result >= 1 ) | ||||||||||||||||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | for my $element ( $result->@* ) { | |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | return 0 unless $element eq $acceptor->{'expected'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub match_pathAny { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_pathAny: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my ( $self, $acceptor, $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | my $expression = Jmespath->compile( $acceptor->{'argument'} ); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $result = $expression->search($response); | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | unless ( ref $result && 'ARRAY' eq ref $result | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
ref $result and "ARRAY" eq ref $result and length $result >= 1
ref $result and "ARRAY" eq ref $result
MC/DC0%0/3
ref $result and "ARRAY" eq ref $result and length $result >= 1
ref $result
"ARRAY" eq ref $result
length $result >= 1
Truth table0%0/4
A and B and C
A= ref $resultB= "ARRAY" eq ref $resultC= length $result >= 1
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | and length $result >= 1 ) | ||||||||||||||||||||||||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | for my $element ( $result->@* ) { | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | return 1 if $element eq $acceptor->{'expected'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | sub match_status { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match_status: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my ( $self, $acceptor, $response ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | return $response->{'http_status'} == $acceptor->{'expected'}; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||