OVH/OvhApi/Answer.pm

filter: Statementstmt 43.7% 21 / 48 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 6 / 12 Podpod 80.0% 4 / 5 totaltotal 35.6% 31 / 87 CC 9 SCAR 22.7
CC
9
Cov
32%
new
20.0
_generateContent
20.0
content
6.0
CRAP 9.7
« Webservice/OVH/Order/Hosting/Web.pm ↑ Summary Webservice/OVH/Cloud/Project/IP/Failover.pm »
1 package OVH::OvhApi::Answer;
2  
3 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 36 our $VERSION = 0.48;
7  
8  
9 36 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
10 36 bool => \&isSuccess,
11 '!' => \&isFailure,
12 fallback => 0,
13 36 );
14  
15 36 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 36 ▶use Carp qw{ carp croak };
Subroutine BEGIN: called CC=1 SCAR=0.0
17 36 ▶use JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19  
20  
21 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
22 # Class variables
23  
24 36 my $Json = JSON->new->allow_nonref;
25  
26 # End - Class variables
27 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
28  
29  
30  
31 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
32 # Class methods
33  
34 sub new
35 0 ▶{
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
36 0 my ($class, %params) = @_;
37  
38 0 ▶ unless ($params{'response'})
Branch: 1 branch
BranchTrueFalseTotal
unless ($params{"response"}) 0 0 0
39 {
40 0 croak 'Missing parameter: response';
41 }
42  
43 0 ▶ unless (blessed $params{'response'} and $params{'response'}->isa('HTTP::Response'))
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($params{"response"}) and $params{"response"}->isa("HTTP::Response")) 0 0 0
Condition0%0/3
builtin::blessed($params{"response"}) and $params{"response"}->isa("HTTP::Response")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($params{"response"}) and $params{"response"}->isa("HTTP::Response")
builtin::blessed($params{"response"}) $params{"response"}->isa("HTTP::Response")
Truth table0%0/3
A and B
A= builtin::blessed($params{"response"})B= $params{"response"}->isa("HTTP::Response")
ABresult
0X0
100
111
44 {
45 0 croak 'Invalid parameter: reponse';
46 }
47  
48 0 bless { response => $params{'response'} }, $class;
49 }
50  
51 # End - Class methods
52 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
53  
54  
55  
56 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
57 # Instance methods
58  
59 sub isSuccess
60 0 ▶{
Subroutine isSuccess: not called CC=1 SCAR=6.9
Pod documented
61 0 my ($self) = @_;
62  
63 0 return $self->{'response'}->is_success;
64 }
65  
66 sub isFailure
67 0 ▶{
Subroutine isFailure: not called CC=1 SCAR=6.9
Pod documented
68 0 my ($self) = @_;
69  
70 0 return not $self->isSuccess;
71 }
72  
73  
74 sub content
75 0 ▶{
Subroutine content: not called CC=2 SCAR=17.9
Pod documented
76 0 my ($self) = @_;
77  
78 0 ▶ if ($self->isFailure)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isFailure) 0 0 0
79 {
80 0 carp 'Fetching content from a failed OvhApi::Response Object';
81 0 return;
82 }
83  
84 0 return $self->_generateContent;
85 }
86  
87 sub error
88 0 ▶{
Subroutine error: not called CC=2 SCAR=17.9
Pod documented
89 0 my ($self) = @_;
90  
91 0 ▶ return $self ? '' : $self->_generateContent->{'message'};
Branch: 1 branch
BranchTrueFalseTotal
$self ? : 0 0 0
92 }
93  
94 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95 # private part
96  
97 sub _generateContent
98 0 ▶{
Subroutine _generateContent: not called CC=4 SCAR=30.0
99 0 my ($self) = @_;
100  
101 0 my $content;
102  
103 0 ▶ if ($self->{'response'}->header('Client-Warning') and $self->{'response'}->header('Client-Warning') eq 'Internal response')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"response"}->header("Client-Warning") and $self->{"response"}->header("Client-Warning") eq "Internal response") 0 0 0
Condition0%0/3
$self->{"response"}->header("Client-Warning") and $self->{"response"}->header("Client-Warning") eq "Internal response"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"response"}->header("Client-Warning") and $self->{"response"}->header("Client-Warning") eq "Internal response"
$self->{"response"}->header("Client-Warning") $self->{"response"}->header("Client-Warning") eq "Internal response"
Truth table0%0/3
A and B
A= $self->{"response"}->header("Client-Warning")B= $self->{"response"}->header("Client-Warning") eq "Internal response"
ABresult
0X0
100
111
104 {
105 0 return { message => 'Internal LWP::UserAgent error : ' . $self->{'response'}->content };
106 }
107  
108 0 ▶ eval { $content = $Json->decode($self->{'response'}->content); 1; } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $content = $Json->decode($self->{"response"}->content); 1 } } or do { carp("Failed to parse JSON content from the answer: ", $self->{"response"}->content); return } 0 0 0
109 0 carp 'Failed to parse JSON content from the answer: ', $self->{'response'}->content;
110 0 return;
111 };
112  
113 0 return $content;
114 }
115  
116 # End - Instance methods
117 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
118  
119  
120 36 return 42;
121  
122 __END__
« Webservice/OVH/Order/Hosting/Web.pm ↑ Summary Webservice/OVH/Cloud/Project/IP/Failover.pm »