File Coverage

blib/lib/ArangoDB2/Graph/VertexCollection.pm
Criterion Covered Total %
statement 22 41 53.6
branch 1 8 12.5
condition 0 5 0.0
subroutine 8 13 61.5
pod 6 6 100.0
total 37 73 50.6


line stmt bran cond sub pod time code
1             package ArangoDB2::Graph::VertexCollection;
2              
3 21     21   87 use strict;
  21         24  
  21         747  
4 21     21   574 use warnings;
  21         36  
  21         562  
5              
6 21         1515 use base qw(
7             ArangoDB2::Base
8 21     21   77 );
  21         35  
9              
10 21     21   94 use Data::Dumper;
  21         22  
  21         881  
11 21     21   81 use JSON::XS;
  21         25  
  21         775  
12              
13 21     21   81 use ArangoDB2::Graph::Vertex;
  21         24  
  21         8034  
14              
15             my $JSON = JSON::XS->new->utf8;
16              
17              
18              
19             # create
20             #
21             # POST /_api/gharial/graph-name/vertex
22             sub create
23             {
24 0     0 1 0 my($self, $args) = @_;
25             # process request args
26 0         0 $args = $self->_build_args($args, ['name']);
27             # make request
28 0 0       0 my $res = $self->arango->http->post(
29             $self->api_path('gharial', $self->graph->name, 'vertex'),
30             undef,
31             $JSON->encode({collection => $args->{name}}),
32             ) or return;
33             # set name
34 0         0 $self->name($args->{name});
35             # update parent graph object with response data
36 0         0 $self->graph->_build_self($res, ['edgeDefinitions', 'name', 'orphanCollections']);
37             # register instance
38 0         0 $self->graph->vertexCollections->{$self->name} = $self;
39              
40 0         0 return $self;
41             }
42              
43             # delete
44             #
45             # DELETE /_api/gharial/graph-name/vertex/collection-name
46             sub delete
47             {
48 0     0 1 0 my($self, $args) = @_;
49             # process request args
50 0         0 $args = $self->_build_args($args, ['dropCollection', 'name']);
51             # make request
52 0 0       0 my $res = $self->arango->http->delete(
53             $self->api_path('gharial', $self->graph->name, 'vertex', delete $args->{name}),
54             $args,
55             ) or return;
56             # update parent graph object with response data
57 0         0 $self->graph->_build_self($res, ['edgeDefinitions', 'name', 'orphanCollections']);
58             # unregister instance
59 0         0 delete $self->graph->vertexCollections->{$self->name};
60              
61 0         0 return $res;
62             }
63              
64             # dropCollection
65             #
66             # get/set dropCollection
67 0     0 1 0 sub dropCollection { shift->_get_set_bool('dropCollection', @_) }
68              
69             # list
70             #
71             # GET /_api/gharial/graph-name/vertex
72             sub list
73             {
74 0     0 1 0 my($self) = @_;
75              
76 0 0       0 my $res = $self->arango->http->get(
77             $self->api_path('gharial', $self->graph->name, 'vertex')
78             ) or return;
79              
80 0         0 return $res->{collections};
81             }
82              
83             # vertex
84             #
85             # return an ArangoDB2::Graph::Vertex object
86             sub vertex
87             {
88 1     1 1 4 my($self, $name) = @_;
89              
90 1 50       3 if (defined $name) {
91 0   0     0 return $self->vertices->{$name} ||= ArangoDB2::Graph::Vertex->new(
92             $self->arango,
93             $self->database,
94             $self->graph,
95             $self,
96             $name,
97             );
98             }
99             else {
100 1         5 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   0 0 1 0 sub vertices { $_[0]->{vertices} ||= {} }
113              
114             # _class
115             #
116             # internally treat this as a collection
117 1     1   4 sub _class { 'collection' }
118              
119             1;
120              
121             __END__