line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ArangoDB2::Cursor; |
2
|
|
|
|
|
|
|
|
3
|
21
|
|
|
21
|
|
80
|
use strict; |
|
21
|
|
|
|
|
24
|
|
|
21
|
|
|
|
|
618
|
|
4
|
21
|
|
|
21
|
|
79
|
use warnings; |
|
21
|
|
|
|
|
20
|
|
|
21
|
|
|
|
|
462
|
|
5
|
|
|
|
|
|
|
|
6
|
21
|
|
|
|
|
1264
|
use base qw( |
7
|
|
|
|
|
|
|
ArangoDB2::Base |
8
|
21
|
|
|
21
|
|
70
|
); |
|
21
|
|
|
|
|
21
|
|
9
|
|
|
|
|
|
|
|
10
|
21
|
|
|
21
|
|
96
|
use Data::Dumper; |
|
21
|
|
|
|
|
27
|
|
|
21
|
|
|
|
|
10157
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# new |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# create new instance |
17
|
|
|
|
|
|
|
sub new |
18
|
|
|
|
|
|
|
{ |
19
|
1
|
|
|
1
|
1
|
7
|
my($class, $arango, $database, $data) = @_; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
6
|
my $self = $class->SUPER::new($arango, $database); |
22
|
1
|
|
|
|
|
3
|
$self->{data} = $data; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
2
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# all |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
# get all results |
30
|
|
|
|
|
|
|
sub all |
31
|
|
|
|
|
|
|
{ |
32
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
33
|
|
|
|
|
|
|
# need data |
34
|
0
|
0
|
|
|
|
|
return unless $self->data; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $result = $self->data->{result}; |
37
|
|
|
|
|
|
|
# add any additional batches to the initial result |
38
|
0
|
|
|
|
|
|
while ($self->get) { |
39
|
0
|
|
|
|
|
|
push(@$result, @{$self->data->{result}}); |
|
0
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return $result; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# count |
46
|
|
|
|
|
|
|
# |
47
|
|
|
|
|
|
|
# get count of results |
48
|
|
|
|
|
|
|
sub count |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
0
|
|
|
|
return $self->data && $self->data->{count}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# delete |
56
|
|
|
|
|
|
|
# |
57
|
|
|
|
|
|
|
# DELETE /_api/cursor/{cursor-identifier} |
58
|
|
|
|
|
|
|
sub delete |
59
|
|
|
|
|
|
|
{ |
60
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
61
|
|
|
|
|
|
|
# need data |
62
|
0
|
0
|
0
|
|
|
|
return unless $self->data |
63
|
|
|
|
|
|
|
and $self->data->{hasMore}; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return $self->arango->http->delete( |
66
|
|
|
|
|
|
|
$self->api_path('cursor', $self->data->{id}), |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# each |
71
|
|
|
|
|
|
|
# |
72
|
|
|
|
|
|
|
# iterate over results calling callback function |
73
|
|
|
|
|
|
|
sub each |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
0
|
1
|
|
my($self, $func) = @_; |
76
|
|
|
|
|
|
|
# require code ref |
77
|
0
|
0
|
|
|
|
|
die "Invalid Args" |
78
|
|
|
|
|
|
|
unless ref $func eq 'CODE'; |
79
|
|
|
|
|
|
|
# need data |
80
|
0
|
0
|
|
|
|
|
return unless $self->data; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $i=0; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
while () { |
85
|
0
|
|
|
|
|
|
$func->($i++, $_) for @{$self->data->{result}}; |
|
0
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
last unless $self->get; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# fullCount |
93
|
|
|
|
|
|
|
# |
94
|
|
|
|
|
|
|
# get fullCount for LIMIT result |
95
|
|
|
|
|
|
|
sub fullCount |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
0
|
|
|
|
return $self->data && $self->data->{extra} && $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
|
|
|
|
|
|
|
{ |
109
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
110
|
|
|
|
|
|
|
# need data |
111
|
0
|
0
|
0
|
|
|
|
return unless $self->data |
112
|
|
|
|
|
|
|
and $self->data->{hasMore}; |
113
|
|
|
|
|
|
|
# request next batch |
114
|
0
|
0
|
|
|
|
|
my $res = $self->arango->http->put( |
115
|
|
|
|
|
|
|
$self->api_path('cursor', $self->data->{id}), |
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
|
|
|
|
|
|
|
{ |
129
|
0
|
|
|
0
|
1
|
|
my($self) = @_; |
130
|
|
|
|
|
|
|
# need data |
131
|
0
|
0
|
|
|
|
|
return unless $self->data; |
132
|
|
|
|
|
|
|
# increment counter, starting at 0 |
133
|
0
|
|
|
|
|
|
my $i = $self->{i}++; |
134
|
|
|
|
|
|
|
# return next result if it exists |
135
|
0
|
0
|
|
|
|
|
return $self->data->{result}->[$i] |
136
|
|
|
|
|
|
|
if exists $self->data->{result}->[$i]; |
137
|
|
|
|
|
|
|
# try to get more data |
138
|
0
|
0
|
|
|
|
|
$self->get or return; |
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
|
|
|
|
|
|
|
1; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |