line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OvhApi::Answer; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
13
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
58
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.2; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use overload ( |
10
|
1
|
|
|
|
|
7
|
bool => \&isSuccess, |
11
|
|
|
|
|
|
|
'!' => \&isFailure, |
12
|
|
|
|
|
|
|
fallback => 0, |
13
|
1
|
|
|
1
|
|
3
|
); |
|
1
|
|
|
|
|
1
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
48
|
use Scalar::Util 'blessed'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
61
|
|
16
|
1
|
|
|
1
|
|
3
|
use Carp qw{ carp croak }; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
17
|
1
|
|
|
1
|
|
3
|
use JSON (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
255
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
22
|
|
|
|
|
|
|
# Class variables |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $Json = JSON->new->allow_nonref; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# End - Class variables |
27
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
32
|
|
|
|
|
|
|
# Class methods |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
0
|
0
|
|
my ($class, %params) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
unless ($params{'response'}) |
39
|
|
|
|
|
|
|
{ |
40
|
0
|
|
|
|
|
|
croak 'Missing parameter: response'; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
0
|
|
|
|
unless (blessed $params{'response'} and $params{'response'}->isa('HTTP::Response')) |
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
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return $self->{'response'}->is_success; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub isFailure |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return not $self->isSuccess; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub content |
75
|
|
|
|
|
|
|
{ |
76
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
if ($self->isFailure) |
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
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
return $self ? '' : $self->_generateContent->{'message'}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
95
|
|
|
|
|
|
|
# private part |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub _generateContent |
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $content; |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
0
|
|
|
|
if ($self->{'response'}->header('Client-Warning') and $self->{'response'}->header('Client-Warning') eq 'Internal response') |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
|
|
|
return { message => 'Internal LWP::UserAgent error : ' . $self->{'response'}->content }; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
eval { $content = $Json->decode($self->{'response'}->content); 1; } or do { |
|
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
|
|
|
|
|
|
|
return 42; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__END__ |