| 1 | package ArangoDB2::Cursor; | ||||||||||||||||||||||||||||||||||
| 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 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | # new | ||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||
| 16 | # create new instance | ||||||||||||||||||||||||||||||||||
| 17 | sub new | ||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 19 | 1 | my($class, $arango, $database, $data) = @_; | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 1 | my $self = $class->SUPER::new($arango, $database); | |||||||||||||||||||||||||||||||||
| 22 | 1 | $self->{data} = $data; | |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | 1 | return $self; | |||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | # all | ||||||||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||||||||
| 29 | # get all results | ||||||||||||||||||||||||||||||||||
| 30 | sub all | ||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
all: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 32 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||
| 33 | # need data | ||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | return unless $self->data; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | 0 | my $result = $self->data->{result}; | |||||||||||||||||||||||||||||||||
| 37 | # add any additional batches to the initial result | ||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | while ($self->get) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 39 | 0 | push(@$result, @{$self->data->{result}}); | |||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | 0 | return $result; | |||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | # count | ||||||||||||||||||||||||||||||||||
| 46 | # | ||||||||||||||||||||||||||||||||||
| 47 | # get count of results | ||||||||||||||||||||||||||||||||||
| 48 | sub count | ||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
count: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 50 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | return $self->data && $self->data->{count}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->data && $self->data->{'count'}
MC/DC0%0/2
$self->data && $self->data->{'count'}
$self->data
$self->data->{'count'}
Truth table0%0/3
A && B
A= $self->dataB= $self->data->{'count'}
| |||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | # delete | ||||||||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||||||||
| 57 | # DELETE /_api/cursor/{cursor-identifier} | ||||||||||||||||||||||||||||||||||
| 58 | sub delete | ||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 60 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||
| 61 | # need data | ||||||||||||||||||||||||||||||||||
| 62 | return unless $self->data | ||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | and $self->data->{hasMore}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->data and $self->data->{"hasMore"}
MC/DC0%0/2
$self->data and $self->data->{"hasMore"}
$self->data
$self->data->{"hasMore"}
Truth table0%0/3
A and B
A= $self->dataB= $self->data->{"hasMore"}
| |||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | return $self->arango->http->delete( | ||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->api_path('cursor', $self->data->{id}), | |||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | # each | ||||||||||||||||||||||||||||||||||
| 71 | # | ||||||||||||||||||||||||||||||||||
| 72 | # iterate over results calling callback function | ||||||||||||||||||||||||||||||||||
| 73 | sub each | ||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
each: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 75 | 0 | my($self, $func) = @_; | |||||||||||||||||||||||||||||||||
| 76 | # require code ref | ||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | die "Invalid Args" | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 78 | unless ref $func eq 'CODE'; | ||||||||||||||||||||||||||||||||||
| 79 | # need data | ||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | return unless $self->data; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | 0 | my $i=0; | |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 0 | while () { | |||||||||||||||||||||||||||||||||
| 85 | 0 | $func->($i++, $_) for @{$self->data->{result}}; | |||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | last unless $self->get; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | 0 | return; | |||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | # fullCount | ||||||||||||||||||||||||||||||||||
| 93 | # | ||||||||||||||||||||||||||||||||||
| 94 | # get fullCount for LIMIT result | ||||||||||||||||||||||||||||||||||
| 95 | sub fullCount | ||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
fullCount: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 97 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | return $self->data && $self->data->{extra} && $self->data->{extra}->{fullCount}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->data && $self->data->{'extra'} && $self->data->{'extra'}{'fullCount'}
$self->data and $self->data->{"extra"}
MC/DC0%0/3
$self->data && $self->data->{'extra'} && $self->data->{'extra'}{'fullCount'}
$self->data
$self->data->{"extra"}
$self->data->{'extra'}{'fullCount'}
Truth table0%0/4
A and B && C
A= $self->dataB= $self->data->{"extra"}C= $self->data->{'extra'}{'fullCount'}
| |||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | # get | ||||||||||||||||||||||||||||||||||
| 103 | # | ||||||||||||||||||||||||||||||||||
| 104 | # PUT /_api/cursor/{cursor-identifier} | ||||||||||||||||||||||||||||||||||
| 105 | # | ||||||||||||||||||||||||||||||||||
| 106 | # get next batch of results from api | ||||||||||||||||||||||||||||||||||
| 107 | sub get | ||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
get: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 109 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||
| 110 | # need data | ||||||||||||||||||||||||||||||||||
| 111 | return unless $self->data | ||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | and $self->data->{hasMore}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->data and $self->data->{"hasMore"}
MC/DC0%0/2
$self->data and $self->data->{"hasMore"}
$self->data
$self->data->{"hasMore"}
Truth table0%0/3
A and B
A= $self->dataB= $self->data->{"hasMore"}
| |||||||||||||||||||||||||||||||||||
| 113 | # request next batch | ||||||||||||||||||||||||||||||||||
| 114 | my $res = $self->arango->http->put( | ||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | $self->api_path('cursor', $self->data->{id}), | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 116 | ) or return; | ||||||||||||||||||||||||||||||||||
| 117 | # update internal state | ||||||||||||||||||||||||||||||||||
| 118 | 0 | $self->{data} = $res; | |||||||||||||||||||||||||||||||||
| 119 | 0 | $self->{i} = 0; | |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | 0 | return $res; | |||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||
| 124 | # next | ||||||||||||||||||||||||||||||||||
| 125 | # | ||||||||||||||||||||||||||||||||||
| 126 | # get next result | ||||||||||||||||||||||||||||||||||
| 127 | sub next | ||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
next: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 129 | 0 | my($self) = @_; | |||||||||||||||||||||||||||||||||
| 130 | # need data | ||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | return unless $self->data; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 132 | # increment counter, starting at 0 | ||||||||||||||||||||||||||||||||||
| 133 | 0 | my $i = $self->{i}++; | |||||||||||||||||||||||||||||||||
| 134 | # return next result if it exists | ||||||||||||||||||||||||||||||||||
| 135 | return $self->data->{result}->[$i] | ||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if exists $self->data->{result}->[$i]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 137 | # try to get more data | ||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | $self->get or return; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 139 | # try read again | ||||||||||||||||||||||||||||||||||
| 140 | 0 | $i = $self->{i}++; | |||||||||||||||||||||||||||||||||
| 141 | # return next result if it exists | ||||||||||||||||||||||||||||||||||
| 142 | 0 | return $self->data->{result}->[$i]; | |||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||
| 145 | 22 | 1; | |||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||
| 147 | __END__ | ||||||||||||||||||||||||||||||||||