| 1 | package ArangoDB2::Graph::EdgeDefinition; | ||||||||||||||||||||
| 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::Edge; | ||||||||||||||||||
|
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/edge | ||||||||||||||||||||
| 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, ['from', 'name', 'to']); | |||||||||||||||||||
| 27 | # copy name to collection | ||||||||||||||||||||
| 28 | 0 | my $name = $args->{collection} = delete $args->{name}; | |||||||||||||||||||
| 29 | # make request | ||||||||||||||||||||
| 30 | 0 | ▶ | my $res = $self->arango->http->post( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | $self->api_path('gharial', $self->graph->name, 'edge'), | ||||||||||||||||||||
| 32 | undef, | ||||||||||||||||||||
| 33 | $JSON->encode($args), | ||||||||||||||||||||
| 34 | ) or return; | ||||||||||||||||||||
| 35 | # set name | ||||||||||||||||||||
| 36 | 0 | $self->name($name); | |||||||||||||||||||
| 37 | # update parent graph object with response data | ||||||||||||||||||||
| 38 | 0 | $self->graph->_build_self($res, ['edgeDefinitions', 'name', 'orphanCollections']); | |||||||||||||||||||
| 39 | # register instance | ||||||||||||||||||||
| 40 | 0 | $self->graph->edgeDefinitionRegister->{$self->name} = $self; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | return $self; | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | # delete | ||||||||||||||||||||
| 46 | # | ||||||||||||||||||||
| 47 | # DELETE /_api/gharial/graph-name/vertex/collection-name | ||||||||||||||||||||
| 48 | sub delete | ||||||||||||||||||||
| 49 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 50 | 0 | my($self, $args) = @_; | |||||||||||||||||||
| 51 | # process request args | ||||||||||||||||||||
| 52 | 0 | $args = $self->_build_args($args, ['dropCollection', 'name']); | |||||||||||||||||||
| 53 | # make request | ||||||||||||||||||||
| 54 | my $res = $self->arango->http->delete( | ||||||||||||||||||||
| 55 | 0 | ▶ | $self->api_path('gharial', $self->graph->name, 'edge', delete $args->{name}), | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | $args, | ||||||||||||||||||||
| 57 | ) or return; | ||||||||||||||||||||
| 58 | # update parent graph object with response data | ||||||||||||||||||||
| 59 | 0 | $self->graph->_build_self($res, ['edgeDefinitions', 'name', 'orphanCollections']); | |||||||||||||||||||
| 60 | # unregister instance | ||||||||||||||||||||
| 61 | 0 | delete $self->graph->edgeDefinitionRegister->{$self->name}; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | return $res; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | # dropCollection | ||||||||||||||||||||
| 67 | # | ||||||||||||||||||||
| 68 | # get/set dropCollection | ||||||||||||||||||||
| 69 | 0 | ▶ | sub dropCollection { shift->_get_set_bool('dropCollection', @_) } | ||||||||||||||||||
|
Subroutine
dropCollection: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | # edge | ||||||||||||||||||||
| 72 | # | ||||||||||||||||||||
| 73 | # return an ArangoDB2::Graph::Edge object | ||||||||||||||||||||
| 74 | sub edge | ||||||||||||||||||||
| 75 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
edge: called CC=3 SCAR=15.1
Pod
documented
| |||||||||||||||||||||
| 76 | 1 | my($self, $name) = @_; | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 1 | ▶ | if (defined $name) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | 0 | ▶ | return $self->edges->{$name} ||= ArangoDB2::Graph::Edge->new( | ||||||||||||||||||
|
Condition0%0/3
$self->edges->{$name} ||= "ArangoDB2::Graph::Edge"->new($self->arango, $self->database, $self->graph, $self, $name)
MC/DC0%0/2
$self->edges->{$name} ||= "ArangoDB2::Graph::Edge"->new($self->arango, $self->database, $self->graph, $self, $name)
$self->edges->{$name}
"ArangoDB2::Graph::Edge"->new($self->arango, $self->database, $self->graph, $self, $name)
Truth table0%0/3
A ||= B
A= $self->edges->{$name}B= "ArangoDB2::Graph::Edge"->new($self->arango, $self->database, $self->graph, $self, $name)
| |||||||||||||||||||||
| 80 | $self->arango, | ||||||||||||||||||||
| 81 | $self->database, | ||||||||||||||||||||
| 82 | $self->graph, | ||||||||||||||||||||
| 83 | $self, | ||||||||||||||||||||
| 84 | $name, | ||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | else { | ||||||||||||||||||||
| 88 | 1 | return ArangoDB2::Graph::Edge->new( | |||||||||||||||||||
| 89 | $self->arango, | ||||||||||||||||||||
| 90 | $self->database, | ||||||||||||||||||||
| 91 | $self->graph, | ||||||||||||||||||||
| 92 | $self, | ||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | # edges | ||||||||||||||||||||
| 98 | # | ||||||||||||||||||||
| 99 | # index of ArangoDB2::Graph::Edge objects by name | ||||||||||||||||||||
| 100 | 0 | ▶ | sub edges { $_[0]->{edges} ||= {} } | ||||||||||||||||||
|
Subroutine
edges: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/2
$_[0]{"edges"} ||= {}
MC/DC0%0/1
$_[0]{"edges"} ||= {}
$_[0]{"edges"}
Truth table0%0/2
A
A= $_[0]{"edges"}
| |||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | # from | ||||||||||||||||||||
| 103 | # | ||||||||||||||||||||
| 104 | # get/set from (collection/name) | ||||||||||||||||||||
| 105 | 0 | ▶ | sub from { shift->_get_set('from', @_) }; | ||||||||||||||||||
|
Subroutine
from: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | # list | ||||||||||||||||||||
| 108 | # | ||||||||||||||||||||
| 109 | # GET /_api/gharial/graph-name/edge | ||||||||||||||||||||
| 110 | sub list | ||||||||||||||||||||
| 111 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 112 | 0 | my($self) = @_; | |||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 0 | ▶ | my $res = $self->arango->http->get( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 115 | $self->api_path('gharial', $self->graph->name, 'edge') | ||||||||||||||||||||
| 116 | ) or return; | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 0 | return $res->{collections}; | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | # replace | ||||||||||||||||||||
| 122 | # | ||||||||||||||||||||
| 123 | # PUT /_api/gharial/graph-name/edge/definition-name | ||||||||||||||||||||
| 124 | sub replace | ||||||||||||||||||||
| 125 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
replace: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 126 | 0 | my($self, $args) = @_; | |||||||||||||||||||
| 127 | # process request args | ||||||||||||||||||||
| 128 | 0 | $args = $self->_build_args($args, ['from', 'name', 'to']); | |||||||||||||||||||
| 129 | # copy name to collection | ||||||||||||||||||||
| 130 | 0 | my $name = $args->{collection} = delete $args->{name}; | |||||||||||||||||||
| 131 | # make request | ||||||||||||||||||||
| 132 | 0 | ▶ | my $res = $self->arango->http->put( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | $self->api_path('gharial', $self->graph->name, 'edge', $self->name), | ||||||||||||||||||||
| 134 | undef, | ||||||||||||||||||||
| 135 | $JSON->encode($args), | ||||||||||||||||||||
| 136 | ) or return; | ||||||||||||||||||||
| 137 | # set name | ||||||||||||||||||||
| 138 | 0 | $self->name($name); | |||||||||||||||||||
| 139 | # update parent graph object with response data | ||||||||||||||||||||
| 140 | 0 | $self->graph->_build_self($res, ['edgeDefinitions', 'name', 'orphanCollections']); | |||||||||||||||||||
| 141 | # register instance | ||||||||||||||||||||
| 142 | 0 | $self->graph->edgeDefinitionRegister->{$self->name} = $self; | |||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 0 | return $self; | |||||||||||||||||||
| 145 | } | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | # to | ||||||||||||||||||||
| 148 | # | ||||||||||||||||||||
| 149 | # get/set from (collection/name) | ||||||||||||||||||||
| 150 | 0 | ▶ | sub to { shift->_get_set('to', @_) }; | ||||||||||||||||||
|
Subroutine
to: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | # _class | ||||||||||||||||||||
| 153 | # | ||||||||||||||||||||
| 154 | # internally we treat this as a collection | ||||||||||||||||||||
| 155 | 1 | ▶ | sub _class { 'collection' } | ||||||||||||||||||
|
Subroutine
_class: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 22 | 1; | |||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | __END__ | ||||||||||||||||||||