HTTP/Client/Operation.pm

filter: Statementstmt 91.5% 76 / 83 Branchbran 51.8% 28 / 54 Conditioncond 45.4% 15 / 33 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 79.3% 23 / 29 Podpod 100% 19 / 19 totaltotal 67.9% 161 / 237 CC 40 SCAR 21.9
CC
40
Cov
70%
_new
22.4
_append_transaction
17.1
url
6.0
CRAP 8.9
« HTTP/_HTTP2/ServerConnection.pm ↑ Summary HTTP/Transaction.pm »
1 package Linux::Event::HTTP::Client::Operation;
2 14 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 14 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 14 our $VERSION = '0.003';
9  
10 14 my %TERMINAL = map { $_ => 1 } qw(complete cancelled error);
11  
12 44 ▶sub _new ($class, %option) {
Subroutine _new: called CC=11 SCAR=31.1
13 44 my $initial_url = delete $option{initial_url};
14 44 my $max_redirects = delete $option{max_redirects};
15 my $max_auth_retries = exists($option{max_auth_retries})
16 ? delete($option{max_auth_retries})
17 44 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $option{'max_auth_retries'} ? : 44 0 44
18  
19 44 ▶ die 'Client::Operation initial_url is required'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $initial_url or ref $initial_url 0 44 44
Condition33%1/3
not defined $initial_url or ref $initial_url
l!l&&r!l&&!r
0044
MC/DC0%0/2
not defined $initial_url or ref $initial_url
not defined $initial_url ref $initial_url
Truth table33%1/3
not(A) or B
A= not defined $initial_urlB= ref $initial_url
ABresult
1X1
011
000
20 if !defined($initial_url) || ref($initial_url);
21 44 ▶ die 'Client::Operation max_redirects must be a non-negative integer'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $max_redirects or ref $max_redirects or not "$max_redirects" =~ /\A[0-9]+\z/u 0 44 44
Condition33%2/6
not defined $max_redirects or ref $max_redirects or not "$max_redirects" =~ /\A[0-9]+\z/u
l!l&&r!l&&!r
0044
not defined $max_redirects or ref $max_redirects
l!l&&r!l&&!r
0044
MC/DC0%0/3
not defined $max_redirects or ref $max_redirects or not "$max_redirects" =~ /\A[0-9]+\z/u
not defined $max_redirects ref $max_redirects not "$max_redirects" =~ /\A[0-9]+\z/u
Truth table25%1/4
not(A) or B or not(C)
A= not defined $max_redirectsB= ref $max_redirectsC= not "$max_redirects" =~ /\A[0-9]+\z/u
ABCresult
1XX1
01X1
0011
0000
22 if !defined($max_redirects) || ref($max_redirects)
23 || "$max_redirects" !~ /\A[0-9]+\z/;
24 44 ▶ die 'Client::Operation max_auth_retries must be a non-negative integer'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $max_auth_retries or ref $max_auth_retries or not "$max_auth_retries" =~ /\A[0-9]+\z/u 0 44 44
Condition33%2/6
not defined $max_auth_retries or ref $max_auth_retries or not "$max_auth_retries" =~ /\A[0-9]+\z/u
l!l&&r!l&&!r
0044
not defined $max_auth_retries or ref $max_auth_retries
l!l&&r!l&&!r
0044
MC/DC0%0/3
not defined $max_auth_retries or ref $max_auth_retries or not "$max_auth_retries" =~ /\A[0-9]+\z/u
not defined $max_auth_retries ref $max_auth_retries not "$max_auth_retries" =~ /\A[0-9]+\z/u
Truth table25%1/4
not(A) or B or not(C)
A= not defined $max_auth_retriesB= ref $max_auth_retriesC= not "$max_auth_retries" =~ /\A[0-9]+\z/u
ABCresult
1XX1
01X1
0011
0000
25 if !defined($max_auth_retries) || ref($max_auth_retries)
26 || "$max_auth_retries" !~ /\A[0-9]+\z/;
27 44 ▶ die 'unknown Client::Operation option: ' . join(', ', sort keys %option)
Branch: 1 branch
BranchTrueFalseTotal
if %option 0 44 44
28 if %option;
29  
30 44 return bless {
31 initial_url => "$initial_url",
32 max_redirects => 0 + $max_redirects,
33 max_auth_retries => 0 + $max_auth_retries,
34 redirect_count => 0,
35 auth_retry_count => 0,
36 urls => [],
37 transactions => [],
38 state => 'pending',
39 error => undef,
40 }, $class;
41 }
42  
43 1 ▶sub initial_url ($self) { $self->{initial_url} }
Subroutine initial_url: called CC=1 SCAR=0.0
Pod documented
44 0 ▶sub max_redirects ($self) { $self->{max_redirects} }
Subroutine max_redirects: not called CC=1 SCAR=6.9
Pod documented
45 0 ▶sub max_auth_retries ($self) { $self->{max_auth_retries} }
Subroutine max_auth_retries: not called CC=1 SCAR=6.9
Pod documented
46 18 ▶sub redirect_count ($self) { $self->{redirect_count} }
Subroutine redirect_count: called CC=1 SCAR=0.0
Pod documented
47 56 ▶sub auth_retry_count ($self) { $self->{auth_retry_count} }
Subroutine auth_retry_count: called CC=1 SCAR=0.0
Pod documented
48 3 ▶sub state ($self) { $self->{state} }
Subroutine state: called CC=1 SCAR=0.0
Pod documented
49 0 ▶sub error ($self) { $self->{error} }
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
50  
51 79 ▶sub transaction ($self) {
Subroutine transaction: called CC=1 SCAR=0.0
Pod documented
52 79 return $self->{transactions}[-1];
53 }
54  
55 5 ▶sub transactions ($self) {
Subroutine transactions: called CC=1 SCAR=0.0
Pod documented
56 5 return @{$self->{transactions}};
57 }
58  
59 11 ▶sub transaction_count ($self) {
Subroutine transaction_count: called CC=1 SCAR=0.0
Pod documented
60 11 return scalar @{$self->{transactions}};
61 }
62  
63 0 ▶sub url ($self) {
Subroutine url: not called CC=2 SCAR=17.9
Pod documented
64 0 ▶ return @{$self->{urls}} ? $self->{urls}[-1] : $self->{initial_url};
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{'urls'};} ? : 0 0 0
65 }
66  
67 1 ▶sub urls ($self) {
Subroutine urls: called CC=1 SCAR=0.0
Pod documented
68 1 return @{$self->{urls}};
69 }
70  
71 32 ▶sub request ($self) {
Subroutine request: called CC=2 SCAR=7.2
Pod documented
72 32 ▶ my $transaction = $self->transaction or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->transaction or return undef 32 0 32
73 32 return $transaction->request;
74 }
75  
76 1 ▶sub response ($self) {
Subroutine response: called CC=2 SCAR=7.2
Pod documented
77 1 ▶ my $transaction = $self->transaction or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->transaction or return undef 1 0 1
78 1 return $transaction->response;
79 }
80  
81 8 ▶sub request_body ($self, @args) {
Subroutine request_body: called CC=2 SCAR=7.2
Pod documented
82 8 ▶ my $transaction = $self->transaction
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->transaction or die "request_body(): Client operation has no active Transaction" 8 0 8
83 or die 'request_body(): Client operation has no active Transaction';
84 8 return $transaction->request_body(@args);
85 }
86  
87 21 ▶sub is_complete ($self) { $self->{state} eq 'complete' }
Subroutine is_complete: called CC=1 SCAR=0.0
Pod documented
88 0 ▶sub is_cancelled ($self) { $self->{state} eq 'cancelled' }
Subroutine is_cancelled: not called CC=1 SCAR=6.9
Pod documented
89 205 ▶sub is_terminal ($self) { !!$TERMINAL{$self->{state}} }
Subroutine is_terminal: called CC=1 SCAR=0.0
Pod documented
90  
91 2 ▶sub cancel ($self) {
Subroutine cancel: called CC=4 SCAR=14.9
Pod documented
92 2 ▶ return $self if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 2 2
93  
94 2 ▶ if (my $transaction = $self->transaction) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $transaction = $self->transaction) 2 0 2
95 2 ▶ $transaction->cancel if !$transaction->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->is_terminal 2 0 2
96 }
97  
98 2 return $self->_mark_cancelled;
99 }
100  
101 57 ▶sub _append_transaction ($self, $transaction, $url, $kind = 'initial') {
Subroutine _append_transaction: called CC=14 SCAR=28.4
102 57 ▶ die 'cannot append a Transaction to a terminal Client operation'
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 57 57
103 if $self->is_terminal;
104 57 ▶ die 'Client operation requires a Linux::Event::HTTP::Transaction'
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($transaction) and $transaction->isa("Linux::Event::HTTP::Transaction") 0 57 57
Condition33%1/3
builtin::blessed($transaction) and $transaction->isa("Linux::Event::HTTP::Transaction")
!ll&&!rl&&r
0057
MC/DC0%0/2
builtin::blessed($transaction) and $transaction->isa("Linux::Event::HTTP::Transaction")
builtin::blessed($transaction) $transaction->isa("Linux::Event::HTTP::Transaction")
Truth table33%1/3
A and B
A= builtin::blessed($transaction)B= $transaction->isa("Linux::Event::HTTP::Transaction")
ABresult
0X0
100
111
105 if !blessed($transaction)
106 || !$transaction->isa('Linux::Event::HTTP::Transaction');
107 57 ▶ die 'Client operation hop URL must be a scalar'
Branch: 1 branch
BranchTrueFalseTotal
if not defined $url or ref $url 0 57 57
Condition33%1/3
not defined $url or ref $url
l!l&&r!l&&!r
0057
MC/DC0%0/2
not defined $url or ref $url
not defined $url ref $url
Truth table33%1/3
not(A) or B
A= not defined $urlB= ref $url
ABresult
1X1
011
000
108 if !defined($url) || ref($url);
109 57 ▶ die "unknown Client operation Transaction kind '$kind'"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "initial" and $kind ne "redirect" and $kind ne "auth" 0 57 57
Condition83%5/6
$kind ne "initial" and $kind ne "redirect" and $kind ne "auth"
!ll&&!rl&&r
5340
$kind ne "initial" and $kind ne "redirect"
!ll&&!rl&&r
43104
MC/DC0%0/3
$kind ne "initial" and $kind ne "redirect" and $kind ne "auth"
$kind ne "initial" $kind ne "redirect" $kind ne "auth"
Truth table75%3/4
A and B and C
A= $kind ne "initial"B= $kind ne "redirect"C= $kind ne "auth"
ABCresult
0XX0
10X0
1100
1111
110 if $kind ne 'initial' && $kind ne 'redirect' && $kind ne 'auth';
111 die 'initial Client operation Transaction must be first'
112 57 ▶ if $kind eq 'initial' && @{$self->{transactions}};
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "initial" and @{$self->{"transactions"};} 0 57 57
Condition66%2/3
$kind eq "initial" and @{$self->{"transactions"};}
!ll&&!rl&&r
14430
MC/DC0%0/2
$kind eq "initial" and @{$self->{"transactions"};}
$kind eq "initial" @{$self->{"transactions"};}
Truth table66%2/3
A and B
A= $kind eq "initial"B= @{$self->{"transactions"};}
ABresult
0X0
100
111
113  
114 57 ▶ $self->{redirect_count}++ if $kind eq 'redirect';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "redirect" 10 47 57
115 57 ▶ $self->{auth_retry_count}++ if $kind eq 'auth';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "auth" 4 53 57
116  
117 57 push @{$self->{transactions}}, $transaction;
118 57 push @{$self->{urls}}, "$url";
119 57 $self->{state} = 'active';
120 57 return $transaction;
121 }
122  
123 36 ▶sub _mark_complete ($self) {
Subroutine _mark_complete: called CC=4 SCAR=14.6
124 36 ▶ die 'cannot complete a terminal Client operation' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 36 36
125 36 ▶ my $transaction = $self->transaction
Branch: 1 branch
BranchTrueFalseTotal
my $transaction = $self->transaction or die "cannot complete Client operation without a Transaction" 36 0 36
126 or die 'cannot complete Client operation without a Transaction';
127 36 ▶ die 'cannot complete Client operation before final Transaction completes'
Branch: 1 branch
BranchTrueFalseTotal
unless $transaction->is_complete 0 36 36
128 if !$transaction->is_complete;
129  
130 36 $self->{state} = 'complete';
131 36 return $self;
132 }
133  
134 2 ▶sub _mark_cancelled ($self) {
Subroutine _mark_cancelled: called CC=3 SCAR=11.4
135 2 ▶ return $self if $self->{state} eq 'cancelled';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} eq "cancelled" 0 2 2
136 2 ▶ die 'cannot cancel a terminal Client operation' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 2 2
137 2 $self->{state} = 'cancelled';
138 2 return $self;
139 }
140  
141 5 ▶sub _fail ($self, $error) {
Subroutine _fail: called CC=5 SCAR=17.8
142 5 ▶ return $self if $self->{state} eq 'error' && defined $self->{error};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"state"} eq "error" and defined $self->{"error"} 0 5 5
Condition33%1/3
$self->{"state"} eq "error" and defined $self->{"error"}
!ll&&!rl&&r
500
MC/DC0%0/2
$self->{"state"} eq "error" and defined $self->{"error"}
$self->{"state"} eq "error" defined $self->{"error"}
Truth table33%1/3
A and B
A= $self->{"state"} eq "error"B= defined $self->{"error"}
ABresult
0X0
100
111
143 5 ▶ die 'cannot fail a terminal Client operation' if $self->is_terminal;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_terminal 0 5 5
144 5 ▶ die 'Client operation error must be defined' if !defined $error;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $error 0 5 5
145  
146 5 $self->{error} = $error;
147 5 $self->{state} = 'error';
148 5 return $self;
149 }
150  
151 0 ▶sub CLONE_SKIP { 1 }
Subroutine CLONE_SKIP: not called CC=1 SCAR=6.9
152  
153 14 1;
154  
155 __END__
« HTTP/_HTTP2/ServerConnection.pm ↑ Summary HTTP/Transaction.pm »