| 1 | package ArangoDB2::Graph::VertexCollection; | ||||||||||||||||||||
| 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 | ▶ | use ArangoDB2::Graph::Vertex; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 22 | my $JSON = JSON::XS->new->utf8; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | # create | ||||||||||||||||||||
| 20 | # | ||||||||||||||||||||
| 21 | # POST /_api/gharial/graph-name/vertex | ||||||||||||||||||||
| 22 | sub create | ||||||||||||||||||||
| 23 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
create: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 24 | 0 | my($self, $args) = @_; | |||||||||||||||||||
| 25 | # process request args | ||||||||||||||||||||
| 26 | 0 | $args = $self->_build_args($args, ['name']); | |||||||||||||||||||
| 27 | # make request | ||||||||||||||||||||
| 28 | my $res = $self->arango->http->post( | ||||||||||||||||||||
| 29 | $self->api_path('gharial', $self->graph->name, 'vertex'), | ||||||||||||||||||||
| 30 | undef, | ||||||||||||||||||||
| 31 | 0 | ▶ | $JSON->encode({collection => $args->{name}}), | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | ) or return; | ||||||||||||||||||||
| 33 | # set name | ||||||||||||||||||||
| 34 | 0 | $self->name($args->{name}); | |||||||||||||||||||
| 35 | # update parent graph object with response data | ||||||||||||||||||||
| 36 | 0 | $self->graph->_build_self($res, ['edgeDefinitions', 'name', 'orphanCollections']); | |||||||||||||||||||
| 37 | # register instance | ||||||||||||||||||||
| 38 | 0 | $self->graph->vertexCollections->{$self->name} = $self; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | return $self; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | # delete | ||||||||||||||||||||
| 44 | # | ||||||||||||||||||||
| 45 | # DELETE /_api/gharial/graph-name/vertex/collection-name | ||||||||||||||||||||
| 46 | sub delete | ||||||||||||||||||||
| 47 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 48 | 0 | my($self, $args) = @_; | |||||||||||||||||||
| 49 | # process request args | ||||||||||||||||||||
| 50 | 0 | $args = $self->_build_args($args, ['dropCollection', 'name']); | |||||||||||||||||||
| 51 | # make request | ||||||||||||||||||||
| 52 | my $res = $self->arango->http->delete( | ||||||||||||||||||||
| 53 | 0 | ▶ | $self->api_path('gharial', $self->graph->name, 'vertex', delete $args->{name}), | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | $args, | ||||||||||||||||||||
| 55 | ) or return; | ||||||||||||||||||||
| 56 | # update parent graph object with response data | ||||||||||||||||||||
| 57 | 0 | $self->graph->_build_self($res, ['edgeDefinitions', 'name', 'orphanCollections']); | |||||||||||||||||||
| 58 | # unregister instance | ||||||||||||||||||||
| 59 | 0 | delete $self->graph->vertexCollections->{$self->name}; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | return $res; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | # dropCollection | ||||||||||||||||||||
| 65 | # | ||||||||||||||||||||
| 66 | # get/set dropCollection | ||||||||||||||||||||
| 67 | 0 | ▶ | sub dropCollection { shift->_get_set_bool('dropCollection', @_) } | ||||||||||||||||||
|
Subroutine
dropCollection: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | # list | ||||||||||||||||||||
| 70 | # | ||||||||||||||||||||
| 71 | # GET /_api/gharial/graph-name/vertex | ||||||||||||||||||||
| 72 | sub list | ||||||||||||||||||||
| 73 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 74 | 0 | my($self) = @_; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 0 | ▶ | my $res = $self->arango->http->get( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | $self->api_path('gharial', $self->graph->name, 'vertex') | ||||||||||||||||||||
| 78 | ) or return; | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 0 | return $res->{collections}; | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | # vertex | ||||||||||||||||||||
| 84 | # | ||||||||||||||||||||
| 85 | # return an ArangoDB2::Graph::Vertex object | ||||||||||||||||||||
| 86 | sub vertex | ||||||||||||||||||||
| 87 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
vertex: called CC=3 SCAR=15.1
Pod
documented
| |||||||||||||||||||||
| 88 | 1 | my($self, $name) = @_; | |||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 1 | ▶ | if (defined $name) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | 0 | ▶ | return $self->vertices->{$name} ||= ArangoDB2::Graph::Vertex->new( | ||||||||||||||||||
|
Condition0%0/3
$self->vertices->{$name} ||= "ArangoDB2::Graph::Vertex"->new($self->arango, $self->database, $self->graph, $self, $name)
MC/DC0%0/2
$self->vertices->{$name} ||= "ArangoDB2::Graph::Vertex"->new($self->arango, $self->database, $self->graph, $self, $name)
$self->vertices->{$name}
"ArangoDB2::Graph::Vertex"->new($self->arango, $self->database, $self->graph, $self, $name)
Truth table0%0/3
A ||= B
A= $self->vertices->{$name}B= "ArangoDB2::Graph::Vertex"->new($self->arango, $self->database, $self->graph, $self, $name)
| |||||||||||||||||||||
| 92 | $self->arango, | ||||||||||||||||||||
| 93 | $self->database, | ||||||||||||||||||||
| 94 | $self->graph, | ||||||||||||||||||||
| 95 | $self, | ||||||||||||||||||||
| 96 | $name, | ||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | else { | ||||||||||||||||||||
| 100 | 1 | return ArangoDB2::Graph::Vertex->new( | |||||||||||||||||||
| 101 | $self->arango, | ||||||||||||||||||||
| 102 | $self->database, | ||||||||||||||||||||
| 103 | $self->graph, | ||||||||||||||||||||
| 104 | $self, | ||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | # vertices | ||||||||||||||||||||
| 110 | # | ||||||||||||||||||||
| 111 | # index of ArangoDB2::Graph::Vertex objects by name | ||||||||||||||||||||
| 112 | 0 | ▶ | sub vertices { $_[0]->{vertices} ||= {} } | ||||||||||||||||||
|
Subroutine
vertices: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/2
$_[0]{"vertices"} ||= {}
MC/DC0%0/1
$_[0]{"vertices"} ||= {}
$_[0]{"vertices"}
Truth table0%0/2
A
A= $_[0]{"vertices"}
| |||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | # _class | ||||||||||||||||||||
| 115 | # | ||||||||||||||||||||
| 116 | # internally treat this as a collection | ||||||||||||||||||||
| 117 | 1 | ▶ | sub _class { 'collection' } | ||||||||||||||||||
|
Subroutine
_class: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 22 | 1; | |||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | __END__ | ||||||||||||||||||||