| 1 | package Net::Presto; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Furl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = "0.02"; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Net::Presto::Statement; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | has protocol => ( | ||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||
| 14 | 0 | ▶ | isa => sub { die "Unsupported protocol: $_[0]" unless $_[0] =~ /\Ahttps?\z/ }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | default => sub { 'http' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 16 | 3 | ); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | has path => ( | ||||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||
| 20 | 0 | ▶ | default => sub { '/v1/statement' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 21 | 3 | ); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | has server => ( | |||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||
| 25 | required => 1, | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 3 | has catalog => ( | |||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||
| 30 | required => 1, | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 3 | has schema => ( | |||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||
| 35 | required => 1, | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 3 | has user => ( | |||||||||||||||||||||||||||
| 39 | is => 'ro', | ||||||||||||||||||||||||||||
| 40 | required => 1, | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 3 | has time_zone => ( | |||||||||||||||||||||||||||
| 44 | is => 'ro', | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 3 | has language => ( | |||||||||||||||||||||||||||
| 48 | is => 'ro', | ||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | has properties => ( | ||||||||||||||||||||||||||||
| 52 | is => 'ro', | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | isa => sub { die "properties is not a HashRef" unless ref $_[0] eq 'HASH' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 3 | ); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | has furl => ( | ||||||||||||||||||||||||||||
| 57 | is => 'ro', | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | isa => sub { die "furl is not a Furl object" unless blessed $_[0] && $_[0]->isa('Furl') }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
Condition0%0/3
builtin::blessed($_[0]) and $_[0]->isa("Furl")
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa("Furl")
builtin::blessed($_[0])
$_[0]->isa("Furl")
Truth table0%0/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("Furl")
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 0 | Furl->new( | |||||||||||||||||||||||||||
| 62 | agent => $self->source, | ||||||||||||||||||||||||||||
| 63 | timeout => 180, | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | }, | ||||||||||||||||||||||||||||
| 66 | 3 | ); | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | has source => ( | ||||||||||||||||||||||||||||
| 69 | is => 'ro', | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | default => sub { join('/', __PACKAGE__, $VERSION) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 71 | 3 | ); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 0 | my ($self, $query) = @_; | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | confess 'No query specified' unless defined $query; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | my $url = sprintf '%s://%s%s', $self->protocol, $self->server, $self->path; | |||||||||||||||||||||||||||
| 77 | my $headers = [ | ||||||||||||||||||||||||||||
| 78 | 'X-Presto-User' => $self->user, | ||||||||||||||||||||||||||||
| 79 | 'X-Presto-Source' => $self->source, | ||||||||||||||||||||||||||||
| 80 | 'X-Presto-Catalog' => $self->catalog, | ||||||||||||||||||||||||||||
| 81 | 'X-Presto-Schema' => $self->schema, | ||||||||||||||||||||||||||||
| 82 | $self->time_zone ? ('X-Presto-Time-Zone' => $self->time_zone) : (), | ||||||||||||||||||||||||||||
| 83 | $self->language ? ('X-Presto-Language' => $self->language) : (), | ||||||||||||||||||||||||||||
| 84 | $self->properties ? ( | ||||||||||||||||||||||||||||
| 85 | map { | ||||||||||||||||||||||||||||
| 86 | 0 | ('X-Presto-Session' => join('=', $_, $self->properties->{$_})) # need to validate? | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | } keys %{$self->properties} | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 88 | ) : (), | ||||||||||||||||||||||||||||
| 89 | ]; | ||||||||||||||||||||||||||||
| 90 | 0 | my $response = $self->furl->post($url, $headers, $query); | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | confess $response->status_line unless $response->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | my $res = decode_json $response->content; | |||||||||||||||||||||||||||
| 93 | 0 | Net::Presto::Statement->create( | |||||||||||||||||||||||||||
| 94 | furl => $self->furl, | ||||||||||||||||||||||||||||
| 95 | headers => $headers, | ||||||||||||||||||||||||||||
| 96 | res => $res, | ||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub do { | ||||||||||||||||||||||||||
|
Subroutine
do: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | 0 | my ($self, $query) = @_; | |||||||||||||||||||||||||||
| 102 | 0 | my $st = $self->execute($query); | |||||||||||||||||||||||||||
| 103 | 0 | $st->wait_for_completion; | |||||||||||||||||||||||||||
| 104 | 0 | 1; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub select_one { | ||||||||||||||||||||||||||
|
Subroutine
select_one: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 0 | my ($self, $query) = @_; | |||||||||||||||||||||||||||
| 109 | 0 | my $st = $self->execute($query); | |||||||||||||||||||||||||||
| 110 | 0 | my $rows = $st->fetch; | |||||||||||||||||||||||||||
| 111 | 0 | $st->wait_for_completion; | |||||||||||||||||||||||||||
| 112 | 0 | $rows->[0]->[0]; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub select_row { | ||||||||||||||||||||||||||
|
Subroutine
select_row: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 0 | my ($self, $query) = @_; | |||||||||||||||||||||||||||
| 117 | 0 | my $st = $self->execute($query); | |||||||||||||||||||||||||||
| 118 | 0 | my $rows = $st->fetch_hashref; | |||||||||||||||||||||||||||
| 119 | 0 | $st->wait_for_completion; | |||||||||||||||||||||||||||
| 120 | 0 | $rows->[0]; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub select_all { | ||||||||||||||||||||||||||
|
Subroutine
select_all: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 0 | my ($self, $query) = @_; | |||||||||||||||||||||||||||
| 125 | 0 | my $st = $self->execute($query); | |||||||||||||||||||||||||||
| 126 | 0 | my @rows; | |||||||||||||||||||||||||||
| 127 | 0 | ▶ | while (my $rows = $st->fetch_hashref) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | push @rows, @$rows; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 0 | \@rows; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 3 | 1; | |||||||||||||||||||||||||||
| 134 | __END__ | ||||||||||||||||||||||||||||