ArangoDB2
view release on metacpan or search on metacpan
lib/ArangoDB2.pm view on Meta::CPAN
package ArangoDB2;
use strict;
use warnings;
use base qw(
ArangoDB2::Base
);
our $VERSION = '0.11';
use URI;
use ArangoDB2::Admin;
use ArangoDB2::Database;
use ArangoDB2::Endpoint;
use ArangoDB2::HTTP;
# new
#
# create new ArangoDB2 instance from string argument specifying
# API endpoint or hashref of args
sub new
{
my($class, $uri, $username, $password) = @_;
# create instance
my $self = {};
bless($self, $class);
# set values
$self->uri($uri);
$self->username($username);
$self->password($password);
return $self;
}
# admin
#
# ArangoDB2::Admin object which provides access to methods in
# the /_admin group
sub admin
{
my($self) = @_;
return ArangoDB2::Admin->new($self);
}
# database
#
# ArangoDB2::Database object which provides access to methods
# in the /_api/database group
sub database
{
my($self, $name) = @_;
# default database for arango is _system
$name ||= "_system";
# only create one instance per ArangoDB2 per database, each ArangoDB2
# keeps its own instances since they may have different credentials
return $self->databases->{$name} ||= ArangoDB2::Database->new($self, $name);
}
# databases
#
# Index of active ArangoDB2::Database objects by name
sub databases { $_[0]->{databases} ||= {} }
# endpoint
#
# ArangoDB2::Endpoint object
sub endpoint
{
my($self, $name) = @_;
return ArangoDB2::Endpoint->new($self, $name);
}
# http
#
# ArangoDB2::HTTP object. This provides normalized interface to
# various HTTP clients.
sub http
{
my($self, $http) = @_;
$self->{http} = $http
if defined $http;
return $self->{http} ||= ArangoDB2::HTTP->new($self);
}
# http_client
#
# set string indicating http client to use
sub http_client {
my($self) = shift;
# get/set http client value
my $http_client = $self->_get_set('http_client', @_)
or return;
# flush current http client instance so that it will be
# re-created using the correct client
$self->{http} = undef;
return $http_client;
}
# uri
#
# get/set URI for API
sub uri
{
my($self, $uri) = @_;
$self->{uri} = URI->new($uri)
if defined $uri;
return $self->{uri};
}
( run in 2.309 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )