| 1 | package Net::Presto::Statement; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use constant DEBUG => $ENV{PERL_PRESTO_DEBUG} ? 1 : 0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | has furl => ( | |||||||||||||||||||||||||||
| 9 | is => 'ro', | ||||||||||||||||||||||||||||
| 10 | required => 1, | ||||||||||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | has headers => ( | |||||||||||||||||||||||||||
| 14 | is => 'ro', | ||||||||||||||||||||||||||||
| 15 | required => 1, | ||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | has res => ( | |||||||||||||||||||||||||||
| 19 | is => 'rw', | ||||||||||||||||||||||||||||
| 20 | required => 1, | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | has columns => ( | |||||||||||||||||||||||||||
| 24 | is => 'rw', | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 3 | has stats => ( | |||||||||||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 3 | has state => ( | |||||||||||||||||||||||||||
| 32 | is => 'rw', | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 3 | has error => ( | |||||||||||||||||||||||||||
| 36 | is => 'rw', | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub create { | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 41 | 0 | my $self = $class->new(@_); | |||||||||||||||||||||||||||
| 42 | 0 | $self->_set_state($self->res); | |||||||||||||||||||||||||||
| 43 | 0 | $self; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub fetch { | ||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | 0 | my $data; | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | $self->poll(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | return 1 unless $_[0]->{data}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | $data = $_[0]->{data}; | |||||||||||||||||||||||||||
| 52 | 0 | return 0; | |||||||||||||||||||||||||||
| 53 | 0 | }); | |||||||||||||||||||||||||||
| 54 | 0 | $data; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub fetch_hashref { | ||||||||||||||||||||||||||
|
Subroutine
fetch_hashref: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | my $data = $self->fetch or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | my @names = $self->column_names; | |||||||||||||||||||||||||||
| 61 | 0 | my @rows; | |||||||||||||||||||||||||||
| 62 | 0 | for my $row (@$data) { | |||||||||||||||||||||||||||
| 63 | 0 | my %row; | |||||||||||||||||||||||||||
| 64 | 0 | @row{@names} = @$row; | |||||||||||||||||||||||||||
| 65 | 0 | push @rows, \%row; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 0 | \@rows; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub column_names { | ||||||||||||||||||||||||||
|
Subroutine
column_names: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $columns = $self->columns or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | map { $_->{name} } @$columns; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub poll { | ||||||||||||||||||||||||||
|
Subroutine
poll: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 0 | my ($self, $cb) = @_; | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | until ($self->state eq 'FINISHED') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | my $url = $self->res->{nextUri} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | my $res = $self->_request(get => $url); | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | my @ret = $cb->($res) if $cb; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | last if @ret && !$ret[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@ret and not $ret[0]
MC/DC0%0/2
@ret and not $ret[0]
@ret
not $ret[0]
Truth table0%0/3
A and not(B)
A= @retB= not $ret[0]
| |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 0 | return; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub wait_for_completion { | ||||||||||||||||||||||||||
|
Subroutine
wait_for_completion: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 89 | 0 | $self->poll; | |||||||||||||||||||||||||||
| 90 | 0 | return; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub cancel { | ||||||||||||||||||||||||||
|
Subroutine
cancel: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $url = $self->res->{nextUri} or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | $self->_request(delete => $url); | |||||||||||||||||||||||||||
| 97 | 0 | 1; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub _request { | ||||||||||||||||||||||||||
|
Subroutine
_request: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 101 | 0 | my ($self, $method, $url) = @_; | |||||||||||||||||||||||||||
| 102 | 0 | my $response = $self->furl->$method($url, $self->headers); | |||||||||||||||||||||||||||
| 103 | 0 | ▶ | confess $response->status_line unless $response->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | warn "$method $url " . $response->content || '' if DEBUG; | |||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($response->content) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | my $res = decode_json $response->content; | |||||||||||||||||||||||||||
| 107 | 0 | $self->_set_state($res); | |||||||||||||||||||||||||||
| 108 | 0 | return $res; | |||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||
| 110 | 0 | $self->_set_state({}); | |||||||||||||||||||||||||||
| 111 | 0 | return; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub _set_state { | ||||||||||||||||||||||||||
|
Subroutine
_set_state: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 116 | 0 | my ($self, $res) = @_; | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | $self->columns($res->{columns} || []); | ||||||||||||||||||||||||||
|
Condition0%0/2
$res->{'columns'} || []
MC/DC0%0/1
$res->{'columns'} || []
$res->{'columns'}
Truth table0%0/2
A
A= $res->{'columns'}
| |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | $self->stats($res->{stats} || {}); | ||||||||||||||||||||||||||
|
Condition0%0/2
$res->{'stats'} || {}
MC/DC0%0/1
$res->{'stats'} || {}
$res->{'stats'}
Truth table0%0/2
A
A= $res->{'stats'}
| |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $self->state($res->{stats}->{state} || ''); | ||||||||||||||||||||||||||
|
Condition0%0/2
$res->{'stats'}{'state'} || ''
MC/DC0%0/1
$res->{'stats'}{'state'} || ''
$res->{'stats'}{'state'}
Truth table0%0/2
A
A= $res->{'stats'}{'state'}
| |||||||||||||||||||||||||||||
| 120 | 0 | $self->error($res->{error}); | |||||||||||||||||||||||||||
| 121 | 0 | $self->res($res); | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($self->error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | confess 'ERROR ' . $self->error->{errorCode} . ': ' . $self->error->{message}; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | 0 | return; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 129 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 130 | 0 | ▶ | unless ($self->state eq 'FINISHED') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | eval { $self->cancel }; | |||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | warn "Error at Net::Presto::Statement::DESTROY: $@"; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 3 | 1; | |||||||||||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||||||||||||