| 1 | package ArangoDB2::Document; | ||||||||||||
| 2 | |||||||||||||
| 3 | 22 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 22 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 22 | ▶ | use base qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | ArangoDB2::Base | ||||||||||||
| 8 | 22 | ); | |||||||||||
| 9 | |||||||||||||
| 10 | 22 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 22 | ▶ | use JSON::XS; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 22 | 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 | 0 | ▶ | { | ||||||||||
|
Subroutine
create: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 29 | 0 | my($self, $data, $args) = @_; | |||||||||||
| 30 | # require data | ||||||||||||
| 31 | 0 | ▶ | die "Invlalid args" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ▶ | my $res = $self->arango->http->post( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ▶ | sub createCollection { shift->_get_set_bool('createCollection', @_) } | ||||||||||
|
Subroutine
createCollection: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 59 | |||||||||||||
| 60 | # delete | ||||||||||||
| 61 | # | ||||||||||||
| 62 | # DELETE /_api/document/{document-handle} | ||||||||||||
| 63 | sub delete | ||||||||||||
| 64 | 0 | ▶ | { | ||||||||||
|
Subroutine
delete: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 65 | 0 | my($self, $args) = @_; | |||||||||||
| 66 | # process args | ||||||||||||
| 67 | 0 | $args = $self->_build_args($args, ['policy', 'rev', 'waitForSync']); | |||||||||||
| 68 | # make request | ||||||||||||
| 69 | 0 | ▶ | my $res = $self->arango->http->delete( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | $self->api_path($self->_class, $self->collection->name, $self->name), | ||||||||||||
| 71 | $args, | ||||||||||||
| 72 | ) or return; | ||||||||||||
| 73 | # empty data | ||||||||||||
| 74 | 0 | ▶ | if (my $data = $self->data) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | 0 | ▶ | { | ||||||||||
|
Subroutine
edges: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 96 | 0 | my($self, $collection, $args) = @_; | |||||||||||
| 97 | # set default args | ||||||||||||
| 98 | 0 | ▶ | $args ||= {}; | ||||||||||
|
Condition0%0/2
$args ||= {}
MC/DC0%0/1
$args ||= {}
$args
Truth table0%0/2
A
A= $args
| |||||||||||||
| 99 | # require valid args | ||||||||||||
| 100 | 0 | ▶ | die 'Invalid Args' | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | 0 | ▶ | { | ||||||||||
|
Subroutine
get: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 116 | 0 | my($self) = @_; | |||||||||||
| 117 | # make request | ||||||||||||
| 118 | 0 | ▶ | my $res = $self->arango->http->get( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ▶ | if (my $data = $self->data) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | 0 | ▶ | { | ||||||||||
|
Subroutine
head: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 144 | 0 | 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 | ▶ | sub keepNull { shift->_get_set_bool('keepNull', @_) } | ||||||||||
|
Subroutine
keepNull: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 157 | |||||||||||||
| 158 | # list | ||||||||||||
| 159 | # | ||||||||||||
| 160 | # GET /_api/document | ||||||||||||
| 161 | sub list | ||||||||||||
| 162 | 0 | ▶ | { | ||||||||||
|
Subroutine
list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 163 | 0 | 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 | # update | ||||||||||||
| 175 | # | ||||||||||||
| 176 | # PATCH /_api/document/{document-handle} | ||||||||||||
| 177 | sub update | ||||||||||||
| 178 | 0 | ▶ | { | ||||||||||
|
Subroutine
update: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 179 | 0 | my($self, $data, $args) = @_; | |||||||||||
| 180 | # process args | ||||||||||||
| 181 | 0 | $args = $self->_build_args($args, ['keepNull', 'policy', 'waitForSync']); | |||||||||||
| 182 | # make request | ||||||||||||
| 183 | 0 | ▶ | my $res = $self->arango->http->patch( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ▶ | if (my $orig_data = $self->data) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ▶ | sub policy { shift->_get_set('policy', @_) } | ||||||||||
|
Subroutine
policy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 209 | |||||||||||||
| 210 | # replace | ||||||||||||
| 211 | # | ||||||||||||
| 212 | # PUT /_api/document/{document-handle} | ||||||||||||
| 213 | sub replace | ||||||||||||
| 214 | 0 | ▶ | { | ||||||||||
|
Subroutine
replace: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 215 | 0 | my($self, $data, $args) = @_; | |||||||||||
| 216 | # process args | ||||||||||||
| 217 | 0 | $args = $self->_build_args($args, ['policy', 'waitForSync']); | |||||||||||
| 218 | # make request | ||||||||||||
| 219 | 0 | ▶ | my $res = $self->arango->http->put( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ▶ | if (my $orig_data = $self->data) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ▶ | sub type { shift->_get_set('type', @_) } | ||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 246 | |||||||||||||
| 247 | # waitForSync | ||||||||||||
| 248 | # | ||||||||||||
| 249 | # get/set waitForSync | ||||||||||||
| 250 | 0 | ▶ | sub waitForSync { shift->_get_set_bool('waitForSync', @_) } | ||||||||||
|
Subroutine
waitForSync: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 251 | |||||||||||||
| 252 | # _class | ||||||||||||
| 253 | # | ||||||||||||
| 254 | # internal name for class | ||||||||||||
| 255 | 0 | ▶ | sub _class { 'document' } | ||||||||||
|
Subroutine
_class: not called CC=1 SCAR=6.9
| |||||||||||||
| 256 | |||||||||||||
| 257 | # _register | ||||||||||||
| 258 | # | ||||||||||||
| 259 | # internal name for object index | ||||||||||||
| 260 | 0 | ▶ | sub _register { 'documents' } | ||||||||||
|
Subroutine
_register: not called CC=1 SCAR=6.9
| |||||||||||||
| 261 | |||||||||||||
| 262 | 22 | 1; | |||||||||||
| 263 | |||||||||||||
| 264 | __END__ | ||||||||||||