| 1 | package ArangoDB2; | ||||||||||||||||||||
| 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 | our $VERSION = '0.11'; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 22 | ▶ | use URI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 22 | ▶ | use ArangoDB2::Admin; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 22 | ▶ | use ArangoDB2::Database; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 22 | ▶ | use ArangoDB2::Endpoint; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 22 | ▶ | use ArangoDB2::HTTP; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 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 | 19 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 27 | 19 | my($class, $uri, $username, $password) = @_; | |||||||||||||||||||
| 28 | # create instance | ||||||||||||||||||||
| 29 | 19 | my $self = {}; | |||||||||||||||||||
| 30 | 19 | bless($self, $class); | |||||||||||||||||||
| 31 | # set values | ||||||||||||||||||||
| 32 | 19 | $self->uri($uri); | |||||||||||||||||||
| 33 | 19 | $self->username($username); | |||||||||||||||||||
| 34 | 19 | $self->password($password); | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 19 | 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 | 2 | ▶ | { | ||||||||||||||||||
|
Subroutine
admin: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 45 | 2 | my($self) = @_; | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 2 | 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 | 25 | ▶ | { | ||||||||||||||||||
|
Subroutine
database: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 56 | 25 | my($self, $name) = @_; | |||||||||||||||||||
| 57 | # default database for arango is _system | ||||||||||||||||||||
| 58 | 25 | ▶ | $name ||= "_system"; | ||||||||||||||||||
|
Condition100%2/2
$name ||= "_system"
MC/DC100%1/1
$name ||= "_system"
$name
Truth table100%2/2
A
A= $name
| |||||||||||||||||||||
| 59 | # only create one instance per ArangoDB2 per database, each ArangoDB2 | ||||||||||||||||||||
| 60 | # keeps its own instances since they may have different credentials | ||||||||||||||||||||
| 61 | 25 | ▶ | return $self->databases->{$name} ||= ArangoDB2::Database->new($self, $name); | ||||||||||||||||||
|
Condition66%2/3
$self->databases->{$name} ||= "ArangoDB2::Database"->new($self, $name)
MC/DC0%0/2
$self->databases->{$name} ||= "ArangoDB2::Database"->new($self, $name)
$self->databases->{$name}
"ArangoDB2::Database"->new($self, $name)
Truth table66%2/3
A ||= B
A= $self->databases->{$name}B= "ArangoDB2::Database"->new($self, $name)
| |||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | # databases | ||||||||||||||||||||
| 65 | # | ||||||||||||||||||||
| 66 | # Index of active ArangoDB2::Database objects by name | ||||||||||||||||||||
| 67 | 25 | ▶ | sub databases { $_[0]->{databases} ||= {} } | ||||||||||||||||||
|
Subroutine
databases: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
$_[0]{"databases"} ||= {}
MC/DC100%1/1
$_[0]{"databases"} ||= {}
$_[0]{"databases"}
Truth table100%2/2
A
A= $_[0]{"databases"}
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | # endpoint | ||||||||||||||||||||
| 70 | # | ||||||||||||||||||||
| 71 | # ArangoDB2::Endpoint object | ||||||||||||||||||||
| 72 | sub endpoint | ||||||||||||||||||||
| 73 | 2 | ▶ | { | ||||||||||||||||||
|
Subroutine
endpoint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 74 | 2 | my($self, $name) = @_; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 2 | 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 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
http: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 85 | 1 | my($self, $http) = @_; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 1 | ▶ | $self->{http} = $http | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | if defined $http; | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 1 | ▶ | return $self->{http} ||= ArangoDB2::HTTP->new($self); | ||||||||||||||||||
|
Condition33%1/3
$self->{"http"} ||= "ArangoDB2::HTTP"->new($self)
MC/DC0%0/2
$self->{"http"} ||= "ArangoDB2::HTTP"->new($self)
$self->{"http"}
"ArangoDB2::HTTP"->new($self)
Truth table33%1/3
A ||= B
A= $self->{"http"}B= "ArangoDB2::HTTP"->new($self)
| |||||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | # http_client | ||||||||||||||||||||
| 94 | # | ||||||||||||||||||||
| 95 | # set string indicating http client to use | ||||||||||||||||||||
| 96 | 1 | ▶ | sub http_client { | ||||||||||||||||||
|
Subroutine
http_client: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||
| 97 | 1 | my($self) = shift; | |||||||||||||||||||
| 98 | # get/set http client value | ||||||||||||||||||||
| 99 | 1 | ▶ | my $http_client = $self->_get_set('http_client', @_) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | or return; | ||||||||||||||||||||
| 101 | # flush current http client instance so that it will be | ||||||||||||||||||||
| 102 | # re-created using the correct client | ||||||||||||||||||||
| 103 | 0 | $self->{http} = undef; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | return $http_client; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | # uri | ||||||||||||||||||||
| 109 | # | ||||||||||||||||||||
| 110 | # get/set URI for API | ||||||||||||||||||||
| 111 | sub uri | ||||||||||||||||||||
| 112 | 20 | ▶ | { | ||||||||||||||||||
|
Subroutine
uri: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 113 | 20 | my($self, $uri) = @_; | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 20 | ▶ | $self->{uri} = URI->new($uri) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 116 | if defined $uri; | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 20 | return $self->{uri}; | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | # version | ||||||||||||||||||||
| 122 | # | ||||||||||||||||||||
| 123 | # GET /_api/version | ||||||||||||||||||||
| 124 | # | ||||||||||||||||||||
| 125 | # Returns the server name and version number. The response is a JSON object with the following attributes: | ||||||||||||||||||||
| 126 | # | ||||||||||||||||||||
| 127 | # server: will always contain arango | ||||||||||||||||||||
| 128 | # 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. | ||||||||||||||||||||
| 129 | # details: an optional JSON object with additional details. This is returned only if the details URL parameter is set to true in the request. | ||||||||||||||||||||
| 130 | sub version | ||||||||||||||||||||
| 131 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 132 | 0 | my($self) = @_; | |||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | 0 | return $self->http->get('/_api/version'); | |||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | #################### | ||||||||||||||||||||
| 138 | # PROPERTY METHODS # | ||||||||||||||||||||
| 139 | #################### | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | 20 | ▶ | sub username { shift->_get_set('username', @_) } | ||||||||||||||||||
|
Subroutine
username: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 142 | 19 | ▶ | sub password { shift->_get_set('password', @_) } | ||||||||||||||||||
|
Subroutine
password: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | #################### | ||||||||||||||||||||
| 145 | # INTERNAL METHODS # | ||||||||||||||||||||
| 146 | #################### | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | # _class | ||||||||||||||||||||
| 149 | # | ||||||||||||||||||||
| 150 | # internal name for class | ||||||||||||||||||||
| 151 | 53 | ▶ | sub _class { 'arango' } | ||||||||||||||||||
|
Subroutine
_class: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 22 | 1; | |||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | __END__ | ||||||||||||||||||||