| 1 | package Mojo::InfluxDB; | ||||||||||
| 2 | # ABSTRACT: Super simple InfluxDB async cappable client with a nice interface | ||||||||||
| 3 | 1 | $Mojo::InfluxDB::VERSION = '0.1'; | |||||||||
| 4 | 1 | ▶ | use Mojo::Base -base, -signatures; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Mojo::Collection qw/ c /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Mojo::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Mojo::InfluxDB::Result; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | has host => 'localhost'; | |||||||||
| 11 | 1 | has port => 8086; | |||||||||
| 12 | 0 | ▶ | has database => sub { die "database ir required" }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 13 | |||||||||||
| 14 | 0 | ▶ | has ua => sub { Mojo::UserAgent->new }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 15 | 0 | ▶ | has url => sub ( $self ) { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 16 | 0 | Mojo::URL->new( sprintf( 'http://%s:%s', $self->host, $self->port ) ); | |||||||||
| 17 | 1 | }; | |||||||||
| 18 | |||||||||||
| 19 | 1 | has time_zone => undef; | |||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | sub query ( $self, $query ) { | ||||||||
|
Subroutine
query: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 22 | 0 | my ($results, $error); | |||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | $self->query_p( $query )->then(sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 25 | 0 | $results = shift | |||||||||
| 26 | 0 | ▶ | })->catch( sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 27 | 0 | $error = shift | |||||||||
| 28 | 0 | })->wait; | |||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | die $error if $error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | $results; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub query_p ( $self, $query ) { | ||||||||
|
Subroutine
query_p: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 35 | 0 | ▶ | $self->raw_query_p( $query )->then(sub($tx){ | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 36 | 0 | ▶ | c($tx->res->json('/results')->@*)->map(sub($src){ | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 37 | 0 | Mojo::InfluxDB::Result->new( | |||||||||
| 38 | time_zone => $self->time_zone, | ||||||||||
| 39 | src => $src | ||||||||||
| 40 | ); | ||||||||||
| 41 | 0 | }); | |||||||||
| 42 | 0 | }); | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub raw_query_p ( $self, $query ) { | ||||||||
|
Subroutine
raw_query_p: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 46 | 0 | ▶ | $query = join( ';', @$query ) if $query eq 'ARRAY'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | $self->ua->get_p( | |||||||||
| 48 | $self->_url('query')->query({ q => $query, db => $self->database }) | ||||||||||
| 49 | ); | ||||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub _url ( $self, $action ) { | ||||||||
|
Subroutine
_url: not called CC=1 SCAR=6.9
| |||||||||||
| 53 | 0 | $self->url->path("/$action")->clone | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 1 | 1; | |||||||||
| 57 | |||||||||||
| 58 | __END__ | ||||||||||