| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package ArangoDB2; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 20 |  |  | 20 |  | 483318 | use strict; | 
|  | 20 |  |  |  |  | 35 |  | 
|  | 20 |  |  |  |  | 732 |  | 
| 4 | 20 |  |  | 20 |  | 77 | use warnings; | 
|  | 20 |  |  |  |  | 26 |  | 
|  | 20 |  |  |  |  | 572 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 20 |  |  |  |  | 7983 | use base qw( | 
| 7 |  |  |  |  |  |  | ArangoDB2::Base | 
| 8 | 20 |  |  | 20 |  | 88 | ); | 
|  | 20 |  |  |  |  | 26 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | our $VERSION = '0.10'; | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 20 |  |  | 20 |  | 10764 | use URI; | 
|  | 20 |  |  |  |  | 73026 |  | 
|  | 20 |  |  |  |  | 622 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 20 |  |  | 20 |  | 7913 | use ArangoDB2::Admin; | 
|  | 20 |  |  |  |  | 43 |  | 
|  | 20 |  |  |  |  | 471 |  | 
| 15 | 20 |  |  | 20 |  | 6592 | use ArangoDB2::Database; | 
|  | 20 |  |  |  |  | 51 |  | 
|  | 20 |  |  |  |  | 569 |  | 
| 16 | 20 |  |  | 20 |  | 6740 | use ArangoDB2::Endpoint; | 
|  | 20 |  |  |  |  | 80 |  | 
|  | 20 |  |  |  |  | 450 |  | 
| 17 | 20 |  |  | 20 |  | 6340 | use ArangoDB2::HTTP; | 
|  | 20 |  |  |  |  | 52 |  | 
|  | 20 |  |  |  |  | 7094 |  | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | # new | 
| 22 |  |  |  |  |  |  | # | 
| 23 |  |  |  |  |  |  | # create new ArangoDB2 instance from string argument specifying | 
| 24 |  |  |  |  |  |  | # API endpoint or hashref of args | 
| 25 |  |  |  |  |  |  | sub new | 
| 26 |  |  |  |  |  |  | { | 
| 27 | 19 |  |  | 19 | 1 | 312 | my($class, $uri, $username, $password) = @_; | 
| 28 |  |  |  |  |  |  | # create instance | 
| 29 | 19 |  |  |  |  | 43 | my $self = {}; | 
| 30 | 19 |  |  |  |  | 49 | bless($self, $class); | 
| 31 |  |  |  |  |  |  | # set values | 
| 32 | 19 |  |  |  |  | 89 | $self->uri($uri); | 
| 33 | 19 |  |  |  |  | 95 | $self->username($username); | 
| 34 | 19 |  |  |  |  | 80 | $self->password($password); | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 19 |  |  |  |  | 77 | return $self; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | # admin | 
| 40 |  |  |  |  |  |  | # | 
| 41 |  |  |  |  |  |  | # ArangoDB2::Admin object which provides access to methods in | 
| 42 |  |  |  |  |  |  | # the /_admin group | 
| 43 |  |  |  |  |  |  | sub admin | 
| 44 |  |  |  |  |  |  | { | 
| 45 | 2 |  |  | 2 | 1 | 3040 | my($self) = @_; | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 2 |  |  |  |  | 26 | return ArangoDB2::Admin->new($self); | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | # database | 
| 51 |  |  |  |  |  |  | # | 
| 52 |  |  |  |  |  |  | # ArangoDB2::Database object which provides access to methods | 
| 53 |  |  |  |  |  |  | # in the /_api/database group | 
| 54 |  |  |  |  |  |  | sub database | 
| 55 |  |  |  |  |  |  | { | 
| 56 | 25 |  |  | 25 | 1 | 3889 | my($self, $name) = @_; | 
| 57 |  |  |  |  |  |  | # default database for arango is _system | 
| 58 | 25 |  | 100 |  |  | 110 | $name ||= "_system"; | 
| 59 |  |  |  |  |  |  | # only create one instance per ArangoDB2 per database, each ArangoDB2 | 
| 60 |  |  |  |  |  |  | # keeps its own instances since they may have different credentials | 
| 61 | 25 |  | 66 |  |  | 1376 | return $self->databases->{$name} ||= ArangoDB2::Database->new($self, $name); | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | # databases | 
| 65 |  |  |  |  |  |  | # | 
| 66 |  |  |  |  |  |  | # Index of active ArangoDB2::Database objects by name | 
| 67 | 25 |  | 100 | 25 | 1 | 474 | sub databases { $_[0]->{databases} ||= {} } | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | # endpoint | 
| 70 |  |  |  |  |  |  | # | 
| 71 |  |  |  |  |  |  | # ArangoDB2::Endpoint object | 
| 72 |  |  |  |  |  |  | sub endpoint | 
| 73 |  |  |  |  |  |  | { | 
| 74 | 2 |  |  | 2 | 1 | 8 | my($self, $name) = @_; | 
| 75 |  |  |  |  |  |  |  | 
| 76 | 2 |  |  |  |  | 22 | return ArangoDB2::Endpoint->new($self, $name); | 
| 77 |  |  |  |  |  |  | } | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | # http | 
| 80 |  |  |  |  |  |  | # | 
| 81 |  |  |  |  |  |  | # ArangoDB2::HTTP object.  This provides normalized interface to | 
| 82 |  |  |  |  |  |  | # various HTTP clients. | 
| 83 |  |  |  |  |  |  | sub http | 
| 84 |  |  |  |  |  |  | { | 
| 85 | 1 |  |  | 1 | 1 | 3 | my($self, $http) = @_; | 
| 86 |  |  |  |  |  |  |  | 
| 87 | 1 | 50 |  |  |  | 4 | $self->{http} = $http | 
| 88 |  |  |  |  |  |  | if defined $http; | 
| 89 |  |  |  |  |  |  |  | 
| 90 | 1 |  | 33 |  |  | 13 | return $self->{http} ||= ArangoDB2::HTTP->new($self); | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | # uri | 
| 94 |  |  |  |  |  |  | # | 
| 95 |  |  |  |  |  |  | # get/set URI for API | 
| 96 |  |  |  |  |  |  | sub uri | 
| 97 |  |  |  |  |  |  | { | 
| 98 | 20 |  |  | 20 | 1 | 46 | my($self, $uri) = @_; | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 20 | 100 |  |  |  | 198 | $self->{uri} = URI->new($uri) | 
| 101 |  |  |  |  |  |  | if defined $uri; | 
| 102 |  |  |  |  |  |  |  | 
| 103 | 20 |  |  |  |  | 133965 | return $self->{uri}; | 
| 104 |  |  |  |  |  |  | } | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | # version | 
| 107 |  |  |  |  |  |  | # | 
| 108 |  |  |  |  |  |  | # GET /_api/version | 
| 109 |  |  |  |  |  |  | # | 
| 110 |  |  |  |  |  |  | # Returns the server name and version number. The response is a JSON object with the following attributes: | 
| 111 |  |  |  |  |  |  | # | 
| 112 |  |  |  |  |  |  | # server: will always contain arango | 
| 113 |  |  |  |  |  |  | # version: the server version string. The string has the format "major.minor.sub". major and minor will be numeric, and sub may contain a number or a textual version. | 
| 114 |  |  |  |  |  |  | # details: an optional JSON object with additional details. This is returned only if the details URL parameter is set to true in the request. | 
| 115 |  |  |  |  |  |  | sub version | 
| 116 |  |  |  |  |  |  | { | 
| 117 | 0 |  |  | 0 | 1 | 0 | my($self) = @_; | 
| 118 |  |  |  |  |  |  |  | 
| 119 | 0 |  |  |  |  | 0 | return $self->http->get('/_api/version'); | 
| 120 |  |  |  |  |  |  | } | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | #################### | 
| 123 |  |  |  |  |  |  | # PROPERTY METHODS # | 
| 124 |  |  |  |  |  |  | #################### | 
| 125 |  |  |  |  |  |  |  | 
| 126 | 20 |  |  | 20 | 1 | 188 | sub username { shift->_get_set('username', @_) } | 
| 127 | 19 |  |  | 19 | 1 | 71 | sub password { shift->_get_set('password', @_) } | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | #################### | 
| 130 |  |  |  |  |  |  | # INTERNAL METHODS # | 
| 131 |  |  |  |  |  |  | #################### | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | # _class | 
| 134 |  |  |  |  |  |  | # | 
| 135 |  |  |  |  |  |  | # internal name for class | 
| 136 | 53 |  |  | 53 |  | 204 | sub _class { 'arango' } | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | 1; | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | __END__ |