| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package ArangoDB2::Database; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 20 |  |  | 20 |  | 87 | use strict; | 
|  | 20 |  |  |  |  | 28 |  | 
|  | 20 |  |  |  |  | 661 |  | 
| 4 | 20 |  |  | 20 |  | 85 | use warnings; | 
|  | 20 |  |  |  |  | 24 |  | 
|  | 20 |  |  |  |  | 593 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 20 |  |  |  |  | 1425 | use base qw( | 
| 7 |  |  |  |  |  |  | ArangoDB2::Base | 
| 8 | 20 |  |  | 20 |  | 95 | ); | 
|  | 20 |  |  |  |  | 28 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 20 |  |  | 20 |  | 93 | use Data::Dumper; | 
|  | 20 |  |  |  |  | 25 |  | 
|  | 20 |  |  |  |  | 789 |  | 
| 11 | 20 |  |  | 20 |  | 84 | use JSON::XS; | 
|  | 20 |  |  |  |  | 23 |  | 
|  | 20 |  |  |  |  | 797 |  | 
| 12 | 20 |  |  | 20 |  | 79 | use Scalar::Util qw(reftype); | 
|  | 20 |  |  |  |  | 25 |  | 
|  | 20 |  |  |  |  | 729 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 20 |  |  | 20 |  | 7099 | use ArangoDB2::Collection; | 
|  | 20 |  |  |  |  | 37 |  | 
|  | 20 |  |  |  |  | 487 |  | 
| 15 | 20 |  |  | 20 |  | 6502 | use ArangoDB2::Graph; | 
|  | 20 |  |  |  |  | 41 |  | 
|  | 20 |  |  |  |  | 503 |  | 
| 16 | 20 |  |  | 20 |  | 6460 | use ArangoDB2::Query; | 
|  | 20 |  |  |  |  | 69 |  | 
|  | 20 |  |  |  |  | 477 |  | 
| 17 | 20 |  |  | 20 |  | 6933 | use ArangoDB2::Replication; | 
|  | 20 |  |  |  |  | 31 |  | 
|  | 20 |  |  |  |  | 439 |  | 
| 18 | 20 |  |  | 20 |  | 6132 | use ArangoDB2::Transaction; | 
|  | 20 |  |  |  |  | 36 |  | 
|  | 20 |  |  |  |  | 425 |  | 
| 19 | 20 |  |  | 20 |  | 6431 | use ArangoDB2::User; | 
|  | 20 |  |  |  |  | 39 |  | 
|  | 20 |  |  |  |  | 11320 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | my $JSON = JSON::XS->new->utf8; | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | # collection | 
| 26 |  |  |  |  |  |  | # | 
| 27 |  |  |  |  |  |  | # get/create ArangoDB2::Collection object | 
| 28 |  |  |  |  |  |  | sub collection | 
| 29 |  |  |  |  |  |  | { | 
| 30 | 8 |  |  | 8 | 1 | 44 | my($self, $name) = @_; | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 8 | 50 |  |  |  | 28 | if (defined $name) { | 
| 33 |  |  |  |  |  |  | # only create one ArangoDB2::Collection instance per name | 
| 34 | 8 |  | 33 |  |  | 33 | return $self->collections->{$name} ||= ArangoDB2::Collection->new( | 
| 35 |  |  |  |  |  |  | $self->arango, | 
| 36 |  |  |  |  |  |  | $self, | 
| 37 |  |  |  |  |  |  | $name, | 
| 38 |  |  |  |  |  |  | ); | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  | else { | 
| 41 | 0 |  |  |  |  | 0 | ArangoDB2::Collection->new( | 
| 42 |  |  |  |  |  |  | $self->arango, | 
| 43 |  |  |  |  |  |  | $self, | 
| 44 |  |  |  |  |  |  | $name, | 
| 45 |  |  |  |  |  |  | ); | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | # collections | 
| 50 |  |  |  |  |  |  | # | 
| 51 |  |  |  |  |  |  | # index of ArangoDB2::Collection objects by name | 
| 52 | 8 |  | 50 | 8 | 1 | 124 | sub collections { $_[0]->{collections} ||= {} } | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | # create | 
| 55 |  |  |  |  |  |  | # | 
| 56 |  |  |  |  |  |  | # POST /_api/database | 
| 57 |  |  |  |  |  |  | sub create | 
| 58 |  |  |  |  |  |  | { | 
| 59 | 0 |  |  | 0 | 1 | 0 | my($self, $args) = @_; | 
| 60 |  |  |  |  |  |  | # process args | 
| 61 | 0 |  |  |  |  | 0 | $args = $self->_build_args($args, ['name','users']); | 
| 62 |  |  |  |  |  |  | # make request | 
| 63 | 0 | 0 |  |  |  | 0 | my $res = $self->arango->http->post( | 
| 64 |  |  |  |  |  |  | '/_api/database', | 
| 65 |  |  |  |  |  |  | undef, | 
| 66 |  |  |  |  |  |  | $JSON->encode($args), | 
| 67 |  |  |  |  |  |  | ) or return; | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 0 |  |  |  |  | 0 | return $self; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | # current | 
| 73 |  |  |  |  |  |  | # | 
| 74 |  |  |  |  |  |  | # GET /_api/database/current | 
| 75 |  |  |  |  |  |  | sub current | 
| 76 |  |  |  |  |  |  | { | 
| 77 | 0 |  |  | 0 | 1 | 0 | my($self) = @_; | 
| 78 |  |  |  |  |  |  |  | 
| 79 | 0 |  |  |  |  | 0 | return $self->arango->http->get('/_api/database/current'); | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | # delete | 
| 83 |  |  |  |  |  |  | # | 
| 84 |  |  |  |  |  |  | # DELETE /_api/database/{database-name} | 
| 85 |  |  |  |  |  |  | sub delete | 
| 86 |  |  |  |  |  |  | { | 
| 87 | 0 |  |  | 0 | 1 | 0 | my($self) = @_; | 
| 88 |  |  |  |  |  |  |  | 
| 89 | 0 |  |  |  |  | 0 | return $self->arango->http->delete("/_api/database/".$self->name); | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | # graph | 
| 93 |  |  |  |  |  |  | # | 
| 94 |  |  |  |  |  |  | # get/create ArangoDB2::Graph object | 
| 95 |  |  |  |  |  |  | sub graph | 
| 96 |  |  |  |  |  |  | { | 
| 97 | 6 |  |  | 6 | 1 | 31 | my($self, $name) = @_; | 
| 98 |  |  |  |  |  |  |  | 
| 99 | 6 | 50 |  |  |  | 17 | if (defined $name) { | 
| 100 | 0 |  | 0 |  |  | 0 | return $self->graphs->{$name} ||= ArangoDB2::Graph->new( | 
| 101 |  |  |  |  |  |  | $self->arango, | 
| 102 |  |  |  |  |  |  | $self, | 
| 103 |  |  |  |  |  |  | $name, | 
| 104 |  |  |  |  |  |  | ); | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  | else { | 
| 107 | 6 |  |  |  |  | 36 | return ArangoDB2::Graph->new( | 
| 108 |  |  |  |  |  |  | $self->arango, | 
| 109 |  |  |  |  |  |  | $self, | 
| 110 |  |  |  |  |  |  | ); | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | # graphs | 
| 115 |  |  |  |  |  |  | # | 
| 116 |  |  |  |  |  |  | # index of ArangoDB2::Graph objects by name | 
| 117 | 0 |  | 0 | 0 | 1 | 0 | sub graphs { $_[0]->{graphs} ||= {} } | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | # list | 
| 120 |  |  |  |  |  |  | # | 
| 121 |  |  |  |  |  |  | # GET /_api/database | 
| 122 |  |  |  |  |  |  | # | 
| 123 |  |  |  |  |  |  | # Retrieves the list of all existing databases | 
| 124 |  |  |  |  |  |  | sub list | 
| 125 |  |  |  |  |  |  | { | 
| 126 | 0 |  |  | 0 | 1 | 0 | my($self) = @_; | 
| 127 |  |  |  |  |  |  |  | 
| 128 | 0 |  |  |  |  | 0 | return $self->arango->http->get('/_api/database'); | 
| 129 |  |  |  |  |  |  | } | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | # query | 
| 133 |  |  |  |  |  |  | # | 
| 134 |  |  |  |  |  |  | # get a new ArangoDB2::Query object | 
| 135 |  |  |  |  |  |  | sub query | 
| 136 |  |  |  |  |  |  | { | 
| 137 | 2 |  |  | 2 | 1 | 9 | my($self, $query) = @_; | 
| 138 |  |  |  |  |  |  |  | 
| 139 | 2 |  |  |  |  | 5 | return ArangoDB2::Query->new( | 
| 140 |  |  |  |  |  |  | $self->arango, | 
| 141 |  |  |  |  |  |  | $self, | 
| 142 |  |  |  |  |  |  | $query | 
| 143 |  |  |  |  |  |  | ); | 
| 144 |  |  |  |  |  |  | } | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | # replication | 
| 147 |  |  |  |  |  |  | # | 
| 148 |  |  |  |  |  |  | # get a new ArangoDB2::Replication object | 
| 149 |  |  |  |  |  |  | sub replication | 
| 150 |  |  |  |  |  |  | { | 
| 151 | 1 |  |  | 1 | 1 | 6 | my($self) = @_; | 
| 152 |  |  |  |  |  |  |  | 
| 153 | 1 |  |  |  |  | 6 | return ArangoDB2::Replication->new( | 
| 154 |  |  |  |  |  |  | $self->arango, | 
| 155 |  |  |  |  |  |  | $self, | 
| 156 |  |  |  |  |  |  | ); | 
| 157 |  |  |  |  |  |  | } | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | # transaction | 
| 160 |  |  |  |  |  |  | # | 
| 161 |  |  |  |  |  |  | # get a new ArangoDB2::Transaction object | 
| 162 |  |  |  |  |  |  | sub transaction | 
| 163 |  |  |  |  |  |  | { | 
| 164 | 1 |  |  | 1 | 1 | 6 | my($self) = @_; | 
| 165 |  |  |  |  |  |  |  | 
| 166 | 1 |  |  |  |  | 4 | return ArangoDB2::Transaction->new( | 
| 167 |  |  |  |  |  |  | $self->arango, | 
| 168 |  |  |  |  |  |  | $self, | 
| 169 |  |  |  |  |  |  | ); | 
| 170 |  |  |  |  |  |  | } | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | # user | 
| 173 |  |  |  |  |  |  | # | 
| 174 |  |  |  |  |  |  | # ArangoDB2::User object | 
| 175 |  |  |  |  |  |  | sub user | 
| 176 |  |  |  |  |  |  | { | 
| 177 | 1 |  |  | 1 | 1 | 2 | my($self, $name) = @_; | 
| 178 |  |  |  |  |  |  |  | 
| 179 | 1 |  |  |  |  | 5 | return ArangoDB2::User->new( | 
| 180 |  |  |  |  |  |  | $self->arango, | 
| 181 |  |  |  |  |  |  | $self, | 
| 182 |  |  |  |  |  |  | $name, | 
| 183 |  |  |  |  |  |  | ); | 
| 184 |  |  |  |  |  |  | } | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | # userDatabases | 
| 187 |  |  |  |  |  |  | # | 
| 188 |  |  |  |  |  |  | # GET /_api/database/user | 
| 189 |  |  |  |  |  |  | # | 
| 190 |  |  |  |  |  |  | # Retrieves the list of all databases the current user can access without specifying | 
| 191 |  |  |  |  |  |  | # a different username or password. | 
| 192 |  |  |  |  |  |  | sub userDatabases | 
| 193 |  |  |  |  |  |  | { | 
| 194 | 0 |  |  | 0 | 1 | 0 | my($self) = @_; | 
| 195 |  |  |  |  |  |  |  | 
| 196 | 0 |  |  |  |  | 0 | return $self->arango->http->get('/_api/database/user'); | 
| 197 |  |  |  |  |  |  | } | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | # users | 
| 200 |  |  |  |  |  |  | # | 
| 201 |  |  |  |  |  |  | # get/set users | 
| 202 | 0 |  |  | 0 | 1 | 0 | sub users { shift->_get_set('users', @_) } | 
| 203 |  |  |  |  |  |  |  | 
| 204 |  |  |  |  |  |  | # _class | 
| 205 |  |  |  |  |  |  | # | 
| 206 |  |  |  |  |  |  | # internal name for class | 
| 207 | 32 |  |  | 32 |  | 97 | sub _class { 'database' } | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | 1; | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  | __END__ |