ArangoDB2/Index.pm

filter: Statementstmt 32.1% 18 / 56 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 26.3% 5 / 19 Podpod 100% 14 / 14 totaltotal 32.7% 37 / 113 CC 11 SCAR 22.6
CC
11
Cov
23%
create
20.0
get
20.0
list
20.0
CRAP 9.6
« ArangoDB2/Document.pm ↑ Summary ArangoDB2/HTTP.pm »
1 package ArangoDB2::Index;
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 22 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # parameters that can be set when creating index or
14 # are returned when creating/getting index
15 22 our @PARAMS = qw(
16 byteSize constraint fields geoJson id ignoreNull
17 isNewlyCreated minLength size type unique
18 );
19  
20 22 my $JSON = JSON::XS->new->utf8;
21  
22  
23  
24 # byteSize
25 #
26 # get/set byteSize
27 0 ▶sub byteSize { shift->_get_set('byteSize', @_) }
Subroutine byteSize: not called CC=1 SCAR=6.9
Pod documented
28  
29 # constraint
30 #
31 # get/set constraint value
32 0 ▶sub constraint { shift->_get_set_bool('constraint', @_) }
Subroutine constraint: not called CC=1 SCAR=6.9
Pod documented
33  
34 # create
35 #
36 # POST /_api/index
37 sub create
38 0 ▶{
Subroutine create: not called CC=4 SCAR=30.0
Pod documented
39 0 my($self, $index, $args) = @_;
40 # require index
41 0 ▶ die "Invalid Args"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $index eq "HASH" 0 0 0
42 unless ref $index eq 'HASH';
43 # process args
44 0 $args = $self->_build_args($args, \@PARAMS);
45 # set collection name
46 0 $args->{collection} = $self->collection->name;
47 # make request
48 0 ▶ my $res = $self->arango->http->post(
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->arango->http->post($self->api_path("index"), $args, $JSON->encode($index)) or return 0 0 0
49 $self->api_path('index'),
50 $args,
51 $JSON->encode($index),
52 ) or return;
53 # get name from id
54 0 ▶ my($name) = $res->{id} =~ m{/(\d+)$}
Branch: 1 branch
BranchTrueFalseTotal
my($name) = $res->{"id"} =~ m[/(\d+)$] or return 0 0 0
55 or return;
56 0 $self->{name} = $name;
57 # copy response data to instance
58 0 $self->_build_self($res, \@PARAMS);
59 # register
60 0 $self->collection->indexes->{$name} = $self;
61  
62 0 return $self;
63 }
64  
65 # delete
66 #
67 # DELETE /_api/index/{index-handle}
68 sub delete
69 0 ▶{
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
70 0 my($self) = @_;
71 # make request
72 0 ▶ my $res = $self->arango->http->delete(
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->arango->http->delete($self->api_path("index", $self->id)) or return 0 0 0
73 $self->api_path('index', $self->id),
74 ) or return;
75 # remove from register
76 0 delete $self->collection->indexes->{$self->name};
77  
78 0 return $res;
79 }
80  
81 # fields
82 #
83 # get/set fields
84 0 ▶sub fields { shift->_get_set('fields', @_) }
Subroutine fields: not called CC=1 SCAR=6.9
Pod documented
85  
86 # geoJson
87 #
88 # get/set geoJson value
89 0 ▶sub geoJson { shift->_get_set_bool('geoJson', @_) }
Subroutine geoJson: not called CC=1 SCAR=6.9
Pod documented
90  
91 # get
92 #
93 # GET /_api/index/{index-handle}
94 sub get
95 0 ▶{
Subroutine get: not called CC=4 SCAR=30.0
Pod documented
96 0 my($self, $args) = @_;
97 # process args
98 0 $args = $self->_build_args($args, ['name']);
99 # use either id or name
100 my $id = $self->id
101 ? $self->id
102 0 ▶ : join('/', $self->collection->name, delete $args->{name});
Branch: 1 branch
BranchTrueFalseTotal
$self->id ? : 0 0 0
103 # make request
104 0 ▶ my $res = $self->arango->http->get(
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->arango->http->get($self->api_path("index", $id)) or return 0 0 0
105 $self->api_path('index', $id),
106 ) or return;
107 # get name from id
108 0 ▶ my($name) = $res->{id} =~ m{/(\d+)$}
Branch: 1 branch
BranchTrueFalseTotal
my($name) = $res->{"id"} =~ m[/(\d+)$] or return 0 0 0
109 or return;
110 0 $self->{name} = $name;
111 # copy response data to instance
112 0 $self->_build_self($res, \@PARAMS);
113 # register
114 0 $self->collection->indexes->{$name} = $self;
115  
116 0 return $self;
117 }
118  
119 # ignoreNull
120 #
121 # get/set ignoreNull value
122 0 ▶sub ignoreNull { shift->_get_set_bool('ignoreNull', @_) }
Subroutine ignoreNull: not called CC=1 SCAR=6.9
Pod documented
123  
124 # isNewlyCreated
125 #
126 # get isNewlyCreated value
127 0 ▶sub isNewlyCreated { $_[0]->{isNewlyCreated} }
Subroutine isNewlyCreated: not called CC=1 SCAR=6.9
Pod documented
128  
129 # list
130 #
131 # GET /_api/index
132 sub list
133 0 ▶{
Subroutine list: not called CC=4 SCAR=30.0
Pod documented
134 0 my($self, $args) = @_;
135 # set default args
136 0 ▶ $args ||= {};
Condition0%0/2
$args ||= {}
l!l
00
MC/DC0%0/1
$args ||= {}
$args
Truth table0%0/2
A
A= $args
Aresult
11
00
137 # require valid args
138 0 ▶ die 'Invalid Args'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args eq "HASH" 0 0 0
139 unless ref $args eq 'HASH';
140  
141 0 ▶ $args->{collection} ||= $self->collection->name;
Condition0%0/3
$args->{"collection"} ||= $self->collection->name
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"collection"} ||= $self->collection->name
$args->{"collection"} $self->collection->name
Truth table0%0/3
A ||= B
A= $args->{"collection"}B= $self->collection->name
ABresult
1X1
011
000
142  
143 0 return $self->arango->http->get(
144 $self->api_path('index'),
145 $args
146 );
147 }
148  
149 # minLength
150 #
151 # get/set minLength
152 0 ▶sub minLength { shift->_get_set('minLength', @_) }
Subroutine minLength: not called CC=1 SCAR=6.9
Pod documented
153  
154 # size
155 #
156 # get/set size
157 0 ▶sub size { shift->_get_set('size', @_) }
Subroutine size: not called CC=1 SCAR=6.9
Pod documented
158  
159 # type
160 #
161 # get/set type
162 0 ▶sub type { shift->_get_set('type', @_) }
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
163  
164 # unique
165 #
166 # get/set unique value
167 0 ▶sub unique { shift->_get_set_bool('unique', @_) }
Subroutine unique: not called CC=1 SCAR=6.9
Pod documented
168  
169 22 1;
170  
171 __END__
« ArangoDB2/Document.pm ↑ Summary ArangoDB2/HTTP.pm »