line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ArangoDB2::Document; |
2
|
|
|
|
|
|
|
|
3
|
20
|
|
|
20
|
|
73
|
use strict; |
|
20
|
|
|
|
|
25
|
|
|
20
|
|
|
|
|
586
|
|
4
|
20
|
|
|
20
|
|
68
|
use warnings; |
|
20
|
|
|
|
|
26
|
|
|
20
|
|
|
|
|
460
|
|
5
|
|
|
|
|
|
|
|
6
|
20
|
|
|
|
|
1208
|
use base qw( |
7
|
|
|
|
|
|
|
ArangoDB2::Base |
8
|
20
|
|
|
20
|
|
67
|
); |
|
20
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
|
10
|
20
|
|
|
20
|
|
94
|
use Data::Dumper; |
|
20
|
|
|
|
|
32
|
|
|
20
|
|
|
|
|
827
|
|
11
|
20
|
|
|
20
|
|
119
|
use JSON::XS; |
|
20
|
|
|
|
|
38
|
|
|
20
|
|
|
|
|
19213
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $JSON = JSON::XS->new->utf8; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# create |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# POST /_api/document |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
# Query Parameters |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# collection: The collection name. |
24
|
|
|
|
|
|
|
# createCollection: If this parameter has a value of true or yes, then the collection is created if it does not yet exist. Other values will be ignored so the collection must be present for the operation to succeed. |
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# return self on success, undef on failure |
27
|
|
|
|
|
|
|
sub create |
28
|
|
|
|
|
|
|
{ |
29
|
0
|
|
|
0
|
1
|
|
my($self, $data, $args) = @_; |
30
|
|
|
|
|
|
|
# require data |
31
|
0
|
0
|
|
|
|
|
die "Invlalid args" |
32
|
|
|
|
|
|
|
unless ref $data eq 'HASH'; |
33
|
|
|
|
|
|
|
# process args |
34
|
0
|
|
|
|
|
|
$args = $self->_build_args($args, ['createCollection','waitForSync']); |
35
|
|
|
|
|
|
|
# set collection name as query param |
36
|
0
|
|
|
|
|
|
$args->{collection} = $self->collection->name; |
37
|
|
|
|
|
|
|
# make request |
38
|
0
|
0
|
|
|
|
|
my $res = $self->arango->http->post( |
39
|
|
|
|
|
|
|
$self->api_path($self->_class), |
40
|
|
|
|
|
|
|
$args, |
41
|
|
|
|
|
|
|
$JSON->encode($data), |
42
|
|
|
|
|
|
|
) or return; |
43
|
|
|
|
|
|
|
# copy response data to instance |
44
|
0
|
|
|
|
|
|
$self->_build_self($res, []); |
45
|
|
|
|
|
|
|
# set data pointer to passed in doc, which will |
46
|
|
|
|
|
|
|
# be updated by future object ops |
47
|
0
|
|
|
|
|
|
$self->{data} = $data; |
48
|
|
|
|
|
|
|
# register |
49
|
0
|
|
|
|
|
|
my $register = $self->_register; |
50
|
0
|
|
|
|
|
|
$self->collection->$register->{$self->name} = $self; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# createCollection |
56
|
|
|
|
|
|
|
# |
57
|
|
|
|
|
|
|
# get/set createCollection |
58
|
0
|
|
|
0
|
1
|
|
sub createCollection { shift->_get_set_bool('createCollection', @_) } |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# delete |
61
|
|
|
|
|
|
|
# |
62
|
|
|
|
|
|
|
# DELETE /_api/document/{document-handle} |
63
|
|
|
|
|
|
|
sub delete |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
0
|
1
|
|
my($self, $args) = @_; |
66
|
|
|
|
|
|
|
# process args |
67
|
0
|
|
|
|
|
|
$args = $self->_build_args($args, ['policy', 'rev', 'waitForSync']); |
68
|
|
|
|
|
|
|
# make request |
69
|
0
|
0
|
|
|
|
|
my $res = $self->arango->http->delete( |
70
|
|
|
|
|
|
|
$self->api_path($self->_class, $self->collection->name, $self->name), |
71
|
|
|
|
|
|
|
$args, |
72
|
|
|
|
|
|
|
) or return; |
73
|
|
|
|
|
|
|
# empty data |
74
|
0
|
0
|
|
|
|
|
if (my $data = $self->data) { |
75
|
0
|
|
|
|
|
|
%$data = (); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
# unregister |
78
|
0
|
|
|
|
|
|
my $register = $self->_register; |
79
|
0
|
|
|
|
|
|
delete $self->collection->$register->{$self->name}; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return $res; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# edges |
85
|
|
|
|
|
|
|
# |
86
|
|
|
|
|
|
|
# GET /_api/edges/{collection-id} |
87
|
|
|
|
|
|
|
# |
88
|
|
|
|
|
|
|
# even though this is under the edge API it is the edges for a document |
89
|
|
|
|
|
|
|
# so it makes more since for this to be a method on the document that the |
90
|
|
|
|
|
|
|
# edges are being retrieved for. |
91
|
|
|
|
|
|
|
# |
92
|
|
|
|
|
|
|
# the edges method must be called with the edge collection that the edges |
93
|
|
|
|
|
|
|
# are being retrieved from. |
94
|
|
|
|
|
|
|
sub edges |
95
|
|
|
|
|
|
|
{ |
96
|
0
|
|
|
0
|
1
|
|
my($self, $collection, $args) = @_; |
97
|
|
|
|
|
|
|
# set default args |
98
|
0
|
|
0
|
|
|
|
$args ||= {}; |
99
|
|
|
|
|
|
|
# require valid args |
100
|
0
|
0
|
|
|
|
|
die 'Invalid Args' |
101
|
|
|
|
|
|
|
unless ref $args eq 'HASH'; |
102
|
|
|
|
|
|
|
# get the edges from this document |
103
|
0
|
|
|
|
|
|
$args->{vertex} = join('/', $self->collection->name, $self->name); |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
return $self->arango->http->get( |
106
|
|
|
|
|
|
|
$self->api_path('edges', $collection->name), |
107
|
|
|
|
|
|
|
$args, |
108
|
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# get |
112
|
|
|
|
|
|
|
# |
113
|
|
|
|
|
|
|
# GET /_api/document/{document-handle} |
114
|
|
|
|
|
|
|
sub get |
115
|
|
|
|
|
|
|
{ |
116
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
117
|
|
|
|
|
|
|
# make request |
118
|
0
|
0
|
|
|
|
|
my $res = $self->arango->http->get( |
119
|
|
|
|
|
|
|
$self->api_path($self->_class, $self->collection->name, $self->name), |
120
|
|
|
|
|
|
|
) or return; |
121
|
|
|
|
|
|
|
# copy response data to instance |
122
|
0
|
|
|
|
|
|
$self->_build_self($res, []); |
123
|
|
|
|
|
|
|
# if data is defined already then empty and copy data from response |
124
|
0
|
0
|
|
|
|
|
if (my $data = $self->data) { |
125
|
0
|
|
|
|
|
|
%$data = (); |
126
|
0
|
|
|
|
|
|
$data->{$_} = $res->{$_} for keys %$res; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
# otherwise use res for data |
129
|
|
|
|
|
|
|
else { |
130
|
0
|
|
|
|
|
|
$self->data($res); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
# register object |
133
|
0
|
|
|
|
|
|
my $register = $self->_register; |
134
|
0
|
|
|
|
|
|
$self->collection->$register->{$self->name} = $self; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
return $res; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# head |
140
|
|
|
|
|
|
|
# |
141
|
|
|
|
|
|
|
# HEAD /_api/document/{document-handle} |
142
|
|
|
|
|
|
|
sub head |
143
|
|
|
|
|
|
|
{ |
144
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my $res = $self->arango->http->head( |
147
|
|
|
|
|
|
|
$self->api_path($self->_class, $self->collection->name, $self->name), |
148
|
|
|
|
|
|
|
); |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
return $res; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# keepNull |
154
|
|
|
|
|
|
|
# |
155
|
|
|
|
|
|
|
# get/set keepNull |
156
|
0
|
|
|
0
|
1
|
|
sub keepNull { shift->_get_set_bool('keepNull', @_) } |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# list |
159
|
|
|
|
|
|
|
# |
160
|
|
|
|
|
|
|
# GET /_api/document |
161
|
|
|
|
|
|
|
sub list |
162
|
|
|
|
|
|
|
{ |
163
|
0
|
|
|
0
|
1
|
|
my($self, $args) = @_; |
164
|
|
|
|
|
|
|
# process args |
165
|
0
|
|
|
|
|
|
$args = $self->_build_args($args, ['type']); |
166
|
0
|
|
|
|
|
|
$args->{collection} = $self->collection->name; |
167
|
|
|
|
|
|
|
# make request |
168
|
0
|
|
|
|
|
|
return $self->arango->http->get( |
169
|
|
|
|
|
|
|
$self->api_path($self->_class), |
170
|
|
|
|
|
|
|
$args |
171
|
|
|
|
|
|
|
); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
# patch |
175
|
|
|
|
|
|
|
# |
176
|
|
|
|
|
|
|
# PATCH /_api/document/{document-handle} |
177
|
|
|
|
|
|
|
sub patch |
178
|
|
|
|
|
|
|
{ |
179
|
0
|
|
|
0
|
1
|
|
my($self, $data, $args) = @_; |
180
|
|
|
|
|
|
|
# process args |
181
|
0
|
|
|
|
|
|
$args = $self->_build_args($args, ['keepNull', 'policy', 'waitForSync']); |
182
|
|
|
|
|
|
|
# make request |
183
|
0
|
0
|
|
|
|
|
my $res = $self->arango->http->patch( |
184
|
|
|
|
|
|
|
$self->api_path($self->_class, $self->collection->name, $self->name), |
185
|
|
|
|
|
|
|
$args, |
186
|
|
|
|
|
|
|
$JSON->encode($data), |
187
|
|
|
|
|
|
|
) or return; |
188
|
|
|
|
|
|
|
# copy response data to instance |
189
|
0
|
|
|
|
|
|
$self->_build_self($res, []); |
190
|
|
|
|
|
|
|
# if data is defined then copy patched data |
191
|
0
|
0
|
|
|
|
|
if (my $orig_data = $self->data) { |
192
|
0
|
|
|
|
|
|
$orig_data->{$_} = $data->{$_} for keys %$data; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
# otherwise use passed data |
195
|
|
|
|
|
|
|
else { |
196
|
0
|
|
|
|
|
|
$self->data($data); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
# register object |
199
|
0
|
|
|
|
|
|
my $register = $self->_register; |
200
|
0
|
|
|
|
|
|
$self->collection->$register->{$self->name} = $self; |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
return $self; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# policy |
206
|
|
|
|
|
|
|
# |
207
|
|
|
|
|
|
|
# get/set policy |
208
|
0
|
|
|
0
|
1
|
|
sub policy { shift->_get_set('policy', @_) } |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
# replace |
211
|
|
|
|
|
|
|
# |
212
|
|
|
|
|
|
|
# PUT /_api/document/{document-handle} |
213
|
|
|
|
|
|
|
sub replace |
214
|
|
|
|
|
|
|
{ |
215
|
0
|
|
|
0
|
1
|
|
my($self, $data, $args) = @_; |
216
|
|
|
|
|
|
|
# process args |
217
|
0
|
|
|
|
|
|
$args = $self->_build_args($args, ['policy', 'waitForSync']); |
218
|
|
|
|
|
|
|
# make request |
219
|
0
|
0
|
|
|
|
|
my $res = $self->arango->http->put( |
220
|
|
|
|
|
|
|
$self->api_path($self->_class, $self->collection->name, $self->name), |
221
|
|
|
|
|
|
|
$args, |
222
|
|
|
|
|
|
|
$JSON->encode($data), |
223
|
|
|
|
|
|
|
) or return; |
224
|
|
|
|
|
|
|
# copy response data to instance |
225
|
0
|
|
|
|
|
|
$self->_build_self($res, []); |
226
|
|
|
|
|
|
|
# if data is defined then replace data |
227
|
0
|
0
|
|
|
|
|
if (my $orig_data = $self->data) { |
228
|
0
|
|
|
|
|
|
%$orig_data = (); |
229
|
0
|
|
|
|
|
|
$orig_data->{$_} = $data->{$_} for keys %$data; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
# otherwise use passed data |
232
|
|
|
|
|
|
|
else { |
233
|
0
|
|
|
|
|
|
$self->data($data); |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
# register object |
236
|
0
|
|
|
|
|
|
my $register = $self->_register; |
237
|
0
|
|
|
|
|
|
$self->collection->$register->{$self->name} = $self; |
238
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
return $self; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
# type |
243
|
|
|
|
|
|
|
# |
244
|
|
|
|
|
|
|
# get/set type |
245
|
0
|
|
|
0
|
1
|
|
sub type { shift->_get_set('type', @_) } |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
# waitForSync |
248
|
|
|
|
|
|
|
# |
249
|
|
|
|
|
|
|
# get/set waitForSync |
250
|
0
|
|
|
0
|
1
|
|
sub waitForSync { shift->_get_set_bool('waitForSync', @_) } |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
# _class |
253
|
|
|
|
|
|
|
# |
254
|
|
|
|
|
|
|
# internal name for class |
255
|
0
|
|
|
0
|
|
|
sub _class { 'document' } |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
# _register |
258
|
|
|
|
|
|
|
# |
259
|
|
|
|
|
|
|
# internal name for object index |
260
|
0
|
|
|
0
|
|
|
sub _register { 'documents' } |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
1; |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
__END__ |