ArangoDB2/Cursor.pm

filter: Statementstmt 32.0% 17 / 53 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 41.6% 5 / 12 Podpod 100% 8 / 8 totaltotal 25.2% 30 / 119 CC 18 SCAR 27.1
CC
18
Cov
19%
each
30.0
get
20.0
next
20.0
CRAP 15.0
« ArangoDB2/Graph/Vertex.pm ↑ Summary ArangoDB2/Document.pm »
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
BranchTrueFalseTotal
unless $self->data 0 0 0
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
BranchTrueFalseTotal
if ($self->get) 0 0 0
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'}
!ll&&!rl&&r
000
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'}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $self->data and $self->data->{"hasMore"} 0 0 0
Condition0%0/3
$self->data and $self->data->{"hasMore"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless ref $func eq "CODE" 0 0 0
78 unless ref $func eq 'CODE';
79 # need data
80 0 ▶ return unless $self->data;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data 0 0 0
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
BranchTrueFalseTotal
unless $self->get 0 0 0
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'}
!ll&&!rl&&r
000
$self->data and $self->data->{"extra"}
!ll&&!rl&&r
000
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'}
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
unless $self->data and $self->data->{"hasMore"} 0 0 0
Condition0%0/3
$self->data and $self->data->{"hasMore"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
113 # request next batch
114 my $res = $self->arango->http->put(
115 0 ▶ $self->api_path('cursor', $self->data->{id}),
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->arango->http->put($self->api_path("cursor", $self->data->{"id"})) or return 0 0 0
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
BranchTrueFalseTotal
unless $self->data 0 0 0
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
BranchTrueFalseTotal
if exists $self->data->{"result"}[$i] 0 0 0
137 # try to get more data
138 0 ▶ $self->get or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->get or return 0 0 0
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__
« ArangoDB2/Graph/Vertex.pm ↑ Summary ArangoDB2/Document.pm »