blib/lib/HTTP/API/Core/Error.pm

filter: Statementstmt 100% 50 / 50 Branchbran 91.1% 31 / 34 Conditioncond 58.3% 21 / 36 MC/DCmcdc 35.2% 6 / 17 Subroutinesub 100% 23 / 23 Podpod 100% 19 / 19 totaltotal 83.8% 150 / 179 CC 31 SCAR 21.6
CC
31
Cov
85%
new
22.3
log_summary
10.0
as_string
2.1
CRAP 8.6
« examples/HTTP/API/Core/Example/Jira.pm ↑ Summary blib/lib/HTTP/API/Core/Auth.pm »
1 package HTTP::API::Core::Error;
2  
3 41 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 41 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 41 ▶use overload '""' => 'as_string', fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 41 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 125 ▶sub new {
Subroutine new: called CC=14 SCAR=31.1
Pod documented
9 125 my $class = shift;
10 125 ▶ die "error constructor options must be key/value pairs\n" if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 1 124 125
11 die "constructor option names must be scalars\n"
12 124 ▶ if grep { ref($_) ne '' } @_[ grep { $_ % 2 == 0 } 0 .. $#_ ];
Branch: 1 branch
BranchTrueFalseTotal
if grep {ref $_ ne "";} @_[grep {$_ % 2 == 0;} 0 .. $#_] 1 123 124
13 123 my %args = @_;
14  
15 123 for my $name (qw(message category status method url retryable retry_after elapsed request_id)) {
16 die "error $name must be a scalar or undef\n"
17 1107 ▶ if defined($args{$name}) && ref($args{$name}) ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{$name} and ref $args{$name} ne "" 0 1107 1107
Condition66%2/3
defined $args{$name} and ref $args{$name} ne ""
!ll&&!rl&&r
3267810
MC/DC0%0/2
defined $args{$name} and ref $args{$name} ne ""
defined $args{$name} ref $args{$name} ne ""
Truth table66%2/3
A and B
A= defined $args{$name}B= ref $args{$name} ne ""
ABresult
0X0
100
111
18 }
19  
20 123 ▶ if (defined $args{response}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"response"}) 79 44 123
21 79 my $response_class = blessed($args{response});
22 die "error response must be an object with response accessors\n"
23 if !defined($response_class)
24 || !$args{response}->can('content')
25 || !$args{response}->can('text')
26 || !$args{response}->can('headers')
27 || !$args{response}->can('header')
28 || !$args{response}->can('json')
29 79 ▶ || !$args{response}->can('rate_limit');
Branch: 1 branch
BranchTrueFalseTotal
unless defined $response_class and $args{"response"}->can("content") and $args{"response"}->can("text") and $args{"response"}->can("headers") and $args{"response"}->can("header") and $args{"response"}->can("json") and $args{"response"}->can("rate_limit") 0 79 79
Condition33%6/18
defined $response_class and $args{"response"}->can("content") and $args{"response"}->can("text") and $args{"response"}->can("headers") and $args{"response"}->can("header") and $args{"response"}->can("json") and $args{"response"}->can("rate_limit")
!ll&&!rl&&r
0079
defined $response_class and $args{"response"}->can("content") and $args{"response"}->can("text") and $args{"response"}->can("headers") and $args{"response"}->can("header") and $args{"response"}->can("json")
!ll&&!rl&&r
0079
defined $response_class and $args{"response"}->can("content") and $args{"response"}->can("text") and $args{"response"}->can("headers") and $args{"response"}->can("header")
!ll&&!rl&&r
0079
defined $response_class and $args{"response"}->can("content") and $args{"response"}->can("text") and $args{"response"}->can("headers")
!ll&&!rl&&r
0079
defined $response_class and $args{"response"}->can("content") and $args{"response"}->can("text")
!ll&&!rl&&r
0079
defined $response_class and $args{"response"}->can("content")
!ll&&!rl&&r
0079
MC/DC0%0/7
defined $response_class and $args{"response"}->can("content") and $args{"response"}->can("text") and $args{"response"}->can("headers") and $args{"response"}->can("header") and $args{"response"}->can("json") and $args{"response"}->can("rate_limit")
defined $response_class $args{"response"}->can("content") $args{"response"}->can("text") $args{"response"}->can("headers") $args{"response"}->can("header") $args{"response"}->can("json") $args{"response"}->can("rate_limit")
Truth table12%1/8
A and B and C and D and E and F and G
A= defined $response_classB= $args{"response"}->can("content")C= $args{"response"}->can("text")D= $args{"response"}->can("headers")E= $args{"response"}->can("header")F= $args{"response"}->can("json")G= $args{"response"}->can("rate_limit")
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
30 }
31  
32 123 return bless \%args, $class;
33 }
34  
35 4 ▶sub message { $_[0]->{message} }
Subroutine message: called CC=1 SCAR=0.0
Pod documented
36 49 ▶sub category { $_[0]->{category} }
Subroutine category: called CC=1 SCAR=0.0
Pod documented
37 9 ▶sub status { $_[0]->{status} }
Subroutine status: called CC=1 SCAR=0.0
Pod documented
38 5 ▶sub method { $_[0]->{method} }
Subroutine method: called CC=1 SCAR=0.0
Pod documented
39 2 ▶sub url { $_[0]->{url} }
Subroutine url: called CC=1 SCAR=0.0
Pod documented
40 77 ▶sub retryable { $_[0]->{retryable} ? 1 : 0 }
Subroutine retryable: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'retryable'} ? : 63 14 77
41 51 ▶sub retry_after { $_[0]->{retry_after} }
Subroutine retry_after: called CC=1 SCAR=0.0
Pod documented
42 4 ▶sub elapsed { $_[0]->{elapsed} }
Subroutine elapsed: called CC=1 SCAR=0.0
Pod documented
43 106 ▶sub request_id { $_[0]->{request_id} }
Subroutine request_id: called CC=1 SCAR=0.0
Pod documented
44 12 ▶sub response { $_[0]->{response} }
Subroutine response: called CC=1 SCAR=0.0
Pod documented
45 4 ▶sub body { defined($_[0]->{response}) ? $_[0]->{response}->content : undef }
Subroutine body: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'response'} ? : 3 1 4
46 2 ▶sub text { defined($_[0]->{response}) ? $_[0]->{response}->text : undef }
Subroutine text: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'response'} ? : 1 1 2
47 3 ▶sub headers { defined($_[0]->{response}) ? $_[0]->{response}->headers : {} }
Subroutine headers: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'response'} ? : 2 1 3
48 3 ▶sub header { defined($_[0]->{response}) ? $_[0]->{response}->header($_[1]) : undef }
Subroutine header: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'response'} ? : 2 1 3
49 2 ▶sub json { defined($_[0]->{response}) ? $_[0]->{response}->json : undef }
Subroutine json: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'response'} ? : 1 1 2
50 48 ▶sub rate_limit { defined($_[0]->{response}) ? $_[0]->{response}->rate_limit : undef }
Subroutine rate_limit: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'response'} ? : 39 9 48
51 10 ▶sub as_string { defined($_[0]->{message}) ? $_[0]->{message} : 'HTTP API core error' }
Subroutine as_string: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{'message'} ? : 10 0 10
52  
53 # Use only fixed labels and allowlisted scalar metadata. Diagnostic strings,
54 # URLs, request IDs, headers and bodies may contain credentials or user data.
55 8 ▶sub log_summary {
Subroutine log_summary: called CC=10 SCAR=23.1
Pod documented
56 8 my ($self) = @_;
57  
58 my $category = defined($self->{category})
59 && $self->{category} =~ /\A(?:encode|decode|transport|http|hook)\z/
60 8 ▶ ? $self->{category} : 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'category'} && $self->{'category'} =~ /\A(?:encode|decode|transport|http|hook)\z/ ? : 5 3 8
Condition100%3/3
defined $self->{"category"} and $self->{"category"} =~ /\A(?:encode|decode|transport|http|hook)\z/
!ll&&!rl&&r
125
MC/DC100%2/2
defined $self->{"category"} and $self->{"category"} =~ /\A(?:encode|decode|transport|http|hook)\z/
defined $self->{"category"} $self->{"category"} =~ /\A(?:encode|decode|transport|http|hook)\z/
Truth table100%3/3
A and B
A= defined $self->{"category"}B= $self->{"category"} =~ /\A(?:encode|decode|transport|http|hook)\z/
ABresult
0X0
100
111
61 my $method = defined($self->{method})
62 && $self->{method} =~ /\A(?:GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|TRACE|CONNECT)\z/
63 8 ▶ ? $self->{method} : 'OTHER';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'method'} && $self->{'method'} =~ /\A(?:GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|TRACE|CONNECT)\z/ ? : 5 3 8
Condition100%3/3
defined $self->{"method"} and $self->{"method"} =~ /\A(?:GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|TRACE|CONNECT)\z/
!ll&&!rl&&r
125
MC/DC100%2/2
defined $self->{"method"} and $self->{"method"} =~ /\A(?:GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|TRACE|CONNECT)\z/
defined $self->{"method"} $self->{"method"} =~ /\A(?:GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|TRACE|CONNECT)\z/
Truth table100%3/3
A and B
A= defined $self->{"method"}B= $self->{"method"} =~ /\A(?:GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|TRACE|CONNECT)\z/
ABresult
0X0
100
111
64  
65 8 my @parts = ('HTTP API error', "category=$category", "method=$method");
66 8 my $status = $self->{status};
67 8 ▶ push @parts, "status=$status" if defined($status)
Branch: 1 branch
BranchTrueFalseTotal
if defined $status and $status =~ /\A[0-9]{3}\z/ and $status >= 100 and $status <= 599 1 7 8
Condition77%7/9
defined $status and $status =~ /\A[0-9]{3}\z/ and $status >= 100 and $status <= 599
!ll&&!rl&&r
701
defined $status and $status =~ /\A[0-9]{3}\z/ and $status >= 100
!ll&&!rl&&r
701
defined $status and $status =~ /\A[0-9]{3}\z/
!ll&&!rl&&r
521
MC/DC50%2/4
defined $status and $status =~ /\A[0-9]{3}\z/ and $status >= 100 and $status <= 599
defined $status $status =~ /\A[0-9]{3}\z/ $status >= 100 $status <= 599
Truth table60%3/5
A and B and C and D
A= defined $statusB= $status =~ /\A[0-9]{3}\z/C= $status >= 100D= $status <= 599
ABCDresult
0XXX0
10XX0
110X0
11100
11111
68 && $status =~ /\A[0-9]{3}\z/
69 && $status >= 100 && $status <= 599;
70 8 ▶ push @parts, 'retryable=' . ($self->{retryable} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$self->{'retryable'} ? : 6 2 8
71  
72 8 return join(' ', @parts);
73 }
74  
75 41 1;
76  
77 __END__
« examples/HTTP/API/Core/Example/Jira.pm ↑ Summary blib/lib/HTTP/API/Core/Auth.pm »