| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::OpenStack::Client::Response; |
|
2
|
|
|
|
|
|
|
$Net::OpenStack::Client::Response::VERSION = '0.1.4'; |
|
3
|
8
|
|
|
8
|
|
1785
|
use strict; |
|
|
8
|
|
|
|
|
19
|
|
|
|
8
|
|
|
|
|
208
|
|
|
4
|
8
|
|
|
8
|
|
36
|
use warnings; |
|
|
8
|
|
|
|
|
14
|
|
|
|
8
|
|
|
|
|
189
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
46
|
use base qw(Exporter); |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
617
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
3141
|
use Net::OpenStack::Client::Error; |
|
|
8
|
|
|
|
|
18
|
|
|
|
8
|
|
|
|
|
441
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw(mkresponse); |
|
11
|
|
|
|
|
|
|
|
|
12
|
8
|
|
|
8
|
|
51
|
use overload bool => '_boolean'; |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
30
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
8
|
|
|
8
|
|
441
|
use Readonly; |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
3443
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Readonly my $RESULT_PATH => '/'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Net::OpenStack::Client::Response is an response class for Net::OpenStack. |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Boolean logic is overloaded using C<_boolean> method (as inverse of C). |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head2 Public methods |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=over |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=item mkresponse |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
A C factory |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub mkresponse |
|
35
|
|
|
|
|
|
|
{ |
|
36
|
58
|
|
|
58
|
1
|
625
|
return Net::OpenStack::Client::Response->new(@_); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item new |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Create new response instance. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Options |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=over |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item data: (first) response content, possibly decoded |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item headers: hashref with reponse headers |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item error: an error (passed to C). |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=item result_path: passed to C to set the result attribute. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=back |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub new |
|
61
|
|
|
|
|
|
|
{ |
|
62
|
59
|
|
|
59
|
1
|
213
|
my ($this, %opts) = @_; |
|
63
|
59
|
|
33
|
|
|
182
|
my $class = ref($this) || $this; |
|
64
|
|
|
|
|
|
|
my $self = { |
|
65
|
|
|
|
|
|
|
data => $opts{data} || {}, |
|
66
|
|
|
|
|
|
|
headers => $opts{headers} || {}, |
|
67
|
59
|
|
100
|
|
|
238
|
}; |
|
|
|
|
100
|
|
|
|
|
|
68
|
59
|
|
|
|
|
107
|
bless $self, $class; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# First error |
|
71
|
59
|
|
|
|
|
142
|
$self->set_error($opts{error}); |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Then result |
|
74
|
59
|
|
|
|
|
172
|
$self->set_result($opts{result_path}); |
|
75
|
|
|
|
|
|
|
|
|
76
|
59
|
|
|
|
|
613
|
return $self; |
|
77
|
|
|
|
|
|
|
}; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item set_error |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Set and return the error attribute using C. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub set_error |
|
86
|
|
|
|
|
|
|
{ |
|
87
|
61
|
|
|
61
|
1
|
84
|
my $self = shift; |
|
88
|
61
|
|
|
|
|
164
|
$self->{error} = mkerror(@_); |
|
89
|
61
|
|
|
|
|
127
|
return $self->{error}; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item set_result |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Set and return the result attribute based on the C. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The C is either |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=over |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item (absolute, starting with C>) path-like string, indicating which subtree of the answer |
|
101
|
|
|
|
|
|
|
should be set as result attribute (default C>). |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item anything else is considered a header (from the response headers). |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=back |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub set_result |
|
110
|
|
|
|
|
|
|
{ |
|
111
|
74
|
|
|
74
|
1
|
144
|
my ($self, $result_path) = @_; |
|
112
|
|
|
|
|
|
|
|
|
113
|
74
|
|
|
|
|
105
|
my $res; |
|
114
|
|
|
|
|
|
|
|
|
115
|
74
|
100
|
|
|
|
127
|
if (! $self->is_error()) { |
|
116
|
70
|
100
|
|
|
|
193
|
$result_path = $RESULT_PATH if ! defined($result_path); |
|
117
|
|
|
|
|
|
|
|
|
118
|
70
|
|
|
|
|
201
|
$res = $self->{data}; |
|
119
|
|
|
|
|
|
|
|
|
120
|
70
|
100
|
|
|
|
285
|
if ($result_path =~ m#^/#) { |
|
121
|
|
|
|
|
|
|
# remove any "empty" paths |
|
122
|
65
|
|
|
|
|
205
|
foreach my $subpath (grep {$_} split('/', $result_path)) { |
|
|
72
|
|
|
|
|
175
|
|
|
123
|
38
|
50
|
|
|
|
104
|
$res = $res->{$subpath} if (defined($res)); |
|
124
|
|
|
|
|
|
|
}; |
|
125
|
|
|
|
|
|
|
} else { |
|
126
|
|
|
|
|
|
|
# a header |
|
127
|
5
|
|
|
|
|
16
|
$res = $self->{headers}->{$result_path}; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
}; |
|
130
|
|
|
|
|
|
|
|
|
131
|
74
|
|
|
|
|
151
|
$self->{result} = $res; |
|
132
|
|
|
|
|
|
|
|
|
133
|
74
|
|
|
|
|
117
|
return $self->{result}; |
|
134
|
|
|
|
|
|
|
}; |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item result |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Return the result attribute. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
If C is passed (and defined), |
|
141
|
|
|
|
|
|
|
(re)set the result attribute first. |
|
142
|
|
|
|
|
|
|
(The default result path cannot be (re)set this way. |
|
143
|
|
|
|
|
|
|
Use C method for that). |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub result |
|
148
|
|
|
|
|
|
|
{ |
|
149
|
37
|
|
|
37
|
1
|
2620
|
my ($self, $result_path) = @_; |
|
150
|
|
|
|
|
|
|
|
|
151
|
37
|
100
|
|
|
|
92
|
$self->set_result($result_path) if defined($result_path); |
|
152
|
|
|
|
|
|
|
|
|
153
|
37
|
|
|
|
|
129
|
return $self->{result}; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item is_error |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Test if this is an error or not (based on error attribute). |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub is_error |
|
163
|
|
|
|
|
|
|
{ |
|
164
|
181
|
|
|
181
|
1
|
794
|
my $self = shift; |
|
165
|
181
|
100
|
|
|
|
419
|
return $self->{error} ? 1 : 0; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# Overloaded boolean, inverse of is_error |
|
169
|
|
|
|
|
|
|
sub _boolean |
|
170
|
|
|
|
|
|
|
{ |
|
171
|
102
|
|
|
102
|
|
379
|
my $self = shift; |
|
172
|
102
|
|
|
|
|
186
|
return ! $self->is_error(); |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=pod |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=back |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
1; |