line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use strict; |
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
5
|
|
|
|
|
|
|
our $VERSION = 0.41; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use overload ( |
9
|
|
|
|
|
|
|
bool => \&isSuccess, |
10
|
1
|
|
|
|
|
7
|
'!' => \&isFailure, |
11
|
|
|
|
|
|
|
fallback => 0, |
12
|
|
|
|
|
|
|
); |
13
|
1
|
|
|
1
|
|
5
|
|
|
1
|
|
|
|
|
2
|
|
14
|
|
|
|
|
|
|
use Scalar::Util 'blessed'; |
15
|
1
|
|
|
1
|
|
67
|
use Carp qw{ carp croak }; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
16
|
1
|
|
|
1
|
|
6
|
use JSON (); |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
54
|
|
17
|
1
|
|
|
1
|
|
18
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
381
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
21
|
|
|
|
|
|
|
# Class variables |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $Json = JSON->new->allow_nonref; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# End - Class variables |
26
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
31
|
|
|
|
|
|
|
# Class methods |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
my ($class, %params) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
0
|
0
|
|
unless ($params{'response'}) |
37
|
|
|
|
|
|
|
{ |
38
|
0
|
0
|
|
|
|
|
croak 'Missing parameter: response'; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
unless (blessed $params{'response'} and $params{'response'}->isa('HTTP::Response')) |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
0
|
0
|
|
|
|
croak 'Invalid parameter: reponse'; |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
bless { response => $params{'response'} }, $class; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# End - Class methods |
50
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
55
|
|
|
|
|
|
|
# Instance methods |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
{ |
58
|
|
|
|
|
|
|
my ($self) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return $self->{'response'}->is_success; |
61
|
0
|
|
|
0
|
1
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
{ |
64
|
|
|
|
|
|
|
my ($self) = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return not $self->isSuccess; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
0
|
1
|
|
|
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
my ($self) = @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
if ($self->isFailure) |
74
|
|
|
|
|
|
|
{ |
75
|
|
|
|
|
|
|
carp 'Fetching content from a failed OvhApi::Response Object'; |
76
|
0
|
|
|
0
|
1
|
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
0
|
0
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return $self->_generateContent; |
80
|
0
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
{ |
83
|
|
|
|
|
|
|
my ($self) = @_; |
84
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return $self ? '' : $self->_generateContent->{'message'}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
89
|
0
|
|
|
0
|
1
|
|
# private part |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
{ |
92
|
|
|
|
|
|
|
my ($self) = @_; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $content; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
if ($self->{'response'}->header('Client-Warning') and $self->{'response'}->header('Client-Warning') eq 'Internal response') |
97
|
|
|
|
|
|
|
{ |
98
|
|
|
|
|
|
|
return { message => 'Internal LWP::UserAgent error : ' . $self->{'response'}->content }; |
99
|
0
|
|
|
0
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
eval { $content = $Json->decode($self->{'response'}->content); 1; } or do { |
102
|
|
|
|
|
|
|
carp 'Failed to parse JSON content from the answer: ', $self->{'response'}->content; |
103
|
0
|
0
|
0
|
|
|
|
return; |
104
|
|
|
|
|
|
|
}; |
105
|
0
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
return $content; |
107
|
|
|
|
|
|
|
} |
108
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
# End - Instance methods |
110
|
0
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return 42; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 NAME |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
OvhApi::Answer - Response to a request run with C<OvhApi>. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 SYNOPSIS |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
my $Answer = $Api->get(path => '/me'); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
if ($Answer) |
125
|
|
|
|
|
|
|
{ |
126
|
|
|
|
|
|
|
# Success: can fetch content and process |
127
|
|
|
|
|
|
|
my $content = $Answer->content; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
else |
130
|
|
|
|
|
|
|
{ |
131
|
|
|
|
|
|
|
# Request failed: stop here and retrieve the error |
132
|
|
|
|
|
|
|
my $error = $Answer->error; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 DESCRIPTION |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This module represents a response to a query run with C<OvhApi>. It is build upon a C<HTTP::Request> object. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 CLASS METHODS |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 Constructor |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
There is only one constructor: C<new>. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Its parameters are: |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Parameter Mandatory Default Usage |
148
|
|
|
|
|
|
|
------------ ------------ ---------- -------- |
149
|
|
|
|
|
|
|
response Yes - An HTTP::Response object return by LWP::UserAgent |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 INSTANCE METHODS |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 content |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Returns the content of the answer. This method will C<carp> if the answer is an error. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
It takes no parameter. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 error |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Returns the error message of the answer, or an empty string if the answer is a success. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
It takes no parameter. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 isSuccess |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Forwards a call to C<HTTP::Response::is_error> in the inner C<HTTP::Response> of the answer. Returns true is the request was a success, false otherwise. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
It takes no parameter. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This method is used for the C<bool> L<overload|overload>. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 isFailure |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Helper method which returns the boolean negation of L<isSuccess|/isSuccess>. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
It takes no parameter. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 SEE ALSO |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
The guts of module are using: C<JSON>. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 COPYRIGHT |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Copyright (c) 2013, OVH SAS. |
186
|
|
|
|
|
|
|
All rights reserved. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This library is distributed under the terms of C<license.txt>. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|