Tango/Collection.pm

filter: Statementstmt 36.3% 16 / 44 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 42.8% 6 / 14 Podpod 100% 9 / 9 totaltotal 40.7% 31 / 76 CC 5 SCAR 12.4
CC
5
Cov
31%
bulk_import
6.0
document_paths
6.0
create_document
6.0
CRAP 3.4
« Tango.pm ↑ Summary Tango/Database.pm »
1 # ABSTRACT: ArangoDB Collection object
2 package Arango::Tango::Collection;
3 9 $Arango::Tango::Collection::VERSION = '0.021';
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use Arango::Tango::API;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 Arango::Tango::API::_install_methods "Arango::Tango::Collection" => {
11  
12 ## Document Management -- Keeping here for now.
13 delete_document => {
14 rest => [ delete => '{{database}}_api/document/{name}/{key}'],
15 inject_properties => ['database', 'name'],
16 signature => ['key'],
17 ## FIXME - Header parameters still not supported
18 ## FIXME: missing schema options
19 },
20  
21 document => {
22 rest => [ get => '{{database}}_api/document/{name}/{key}' ],
23 inject_properties => [ 'database', 'name' ],
24 signature => ['key'],
25 ## FIXME - Header parameters still not supported
26 },
27  
28 ## Collection Management
29 load_indexes => {
30 rest => [ put => '{{database}}_api/collection/{name}/loadIndexesIntoMemory' ],
31 inject_properties => [ 'database', 'name' ],
32 },
33  
34 rename => {
35 rest => [ put => '{{database}}_api/collection/{collection}/rename' ],
36 inject_properties => [ 'database', { prop => 'name', as => 'collection' } ],
37 signature => [ 'name' ],
38 schema => { name => { type => 'string' }},
39 },
40  
41 properties => {
42 rest => [ get => '{{database}}_api/collection/{name}/properties' ],
43 inject_properties => ['database', 'name' ],
44 },
45  
46 truncate => {
47 rest => [ put => '{{database}}_api/collection/{name}/truncate' ],
48 inject_properties => [ 'database', 'name' ]
49 },
50  
51 revision => {
52 rest => [ get => '{{database}}_api/collection/{name}/revision' ],
53 inject_properties => [ 'database', 'name' ],
54 },
55  
56 info => {
57 rest => [ get => '{{database}}_api/collection/{name}' ],
58 inject_properties => [ 'database', 'name' ],
59 },
60  
61 recalculate_count => {
62 rest => [ put => '{{database}}_api/collection/{name}/recalculateCount' ],
63 inject_properties => [ 'database', 'name' ],
64 },
65  
66 rotate => {
67 rest => [ put => '{{database}}_api/collection/{name}/rotate' ],
68 inject_properties => [ 'database', 'name' ],
69 },
70  
71 figures => {
72 rest => [ get => '{{database}}_api/collection/{name}/figures' ],
73 schema => { withRevisions => { type => 'boolean' }, withData => {type=>'boolean' }},
74 inject_properties => [ 'database', 'name' ],
75 },
76  
77 count => {
78 rest => [ get => '{{database}}_api/collection/{name}/count' ],
79 schema => { withRevisions => { type => 'boolean' }, withData => {type=>'boolean' }},
80 inject_properties => [ 'database', 'name' ],
81 },
82  
83  
84 checksum => {
85 rest => [ get => '{{database}}_api/collection/{name}/checksum' ],
86 schema => { withRevisions => { type => 'boolean' }, withData => {type=>'boolean' }},
87 inject_properties => [ 'database', 'name' ],
88 },
89  
90 set_properties => {
91 rest => [ put => '{{database}}_api/collection/{name}/properties'],
92 schema => { waitForSync => { type => 'boolean' }, journalSize => { type => 'integer' }},
93 inject_properties => [ 'database', 'name' ],
94 },
95  
96 };
97 }
98  
99  
100  
101 5 ▶sub _new {
Subroutine _new: called CC=1 SCAR=0.0
102 5 my ($class, %opts) = @_;
103 5 return bless {%opts} => $class;
104 }
105  
106 0 ▶sub bulk_import {
Subroutine bulk_import: not called CC=2 SCAR=17.9
Pod documented
107 0 my ($self, $documents, %options) = @_;
108 0 ▶ $options{type} ||= "list";
Condition0%0/2
$options{"type"} ||= "list"
l!l
00
MC/DC0%0/1
$options{"type"} ||= "list"
$options{"type"}
Truth table0%0/2
A
A= $options{"type"}
Aresult
11
00
109 return $self->{arango}->_api( bulk_import_list => {
110 database => $self->{database},
111 collection => $self->{name},
112 0 _body => $documents,
113 _url_parameters => \%options
114 })
115 }
116  
117 0 ▶sub document_paths { ## FIXME: try to get larger cursors whenever possible
Subroutine document_paths: not called CC=2 SCAR=17.9
Pod documented
118 0 my ($self) = @_;
119 0 my $paths = [];
120 0 my $query = qq!FOR doc IN $self->{name} RETURN CONCAT("/_db/", CURRENT_DATABASE(), "/_api/document/", doc._id)!;
121 0 my $cursor = $self->cursor($query);
122 0 ▶ while(my $row = $cursor->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $cursor->next) 0 0 0
123 0 push @$paths, @$row;
124 }
125 0 return $paths;
126 }
127  
128 0 ▶sub create_document {
Subroutine create_document: not called CC=2 SCAR=17.9
Pod documented
129 0 my ($self, $body) = @_;
130 0 ▶ if (defined($body)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body) { } 0 0 0
131 0 return $self->{arango}->_api( create_document => { database => $self->{database}, collection => $self->{name}, _body => $body})
132 } else {
133 0 $self->{arango}{error} = "Refusing to store undefined body";
134 0 return -1;
135 }
136 }
137  
138 0 ▶sub replace_document {
Subroutine replace_document: not called CC=2 SCAR=17.9
Pod documented
139 0 my ($self, $key, $body) = @_;
140 0 ▶ if (defined($body)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body) { } 0 0 0
141 0 return $self->{arango}->_api( replace_document => { database => $self->{database}, collection => $self->{name}, key => $key, _body => $body})
142 } else {
143 0 $self->{arango}{error} = "Refusing to store undefined body";
144 0 return -1;
145 }
146 }
147  
148 0 ▶sub get_access_level {
Subroutine get_access_level: not called CC=1 SCAR=6.9
Pod documented
149 0 my ($self, $username) = @_;
150 0 return $self->{arango}->get_access_level( $username, $self->{database}, $self->{name} );
151 }
152  
153 0 ▶sub clear_access_level {
Subroutine clear_access_level: not called CC=1 SCAR=6.9
Pod documented
154 0 my ($self, $username) = @_;
155 0 return $self->{arango}->clear_access_level( $username , $self->{database}, $self->{name} );
156 }
157  
158 0 ▶sub set_access_level {
Subroutine set_access_level: not called CC=1 SCAR=6.9
Pod documented
159 0 my ($self, $username, $grant) = @_;
160 0 return $self->{arango}->set_access_level($username, $grant, $self->{database}, $self->{name});
161 }
162  
163 0 ▶sub cursor {
Subroutine cursor: not called CC=1 SCAR=6.9
Pod documented
164 0 my ($self, $aql, %opts) = @_;
165 0 return Arango::Tango::Cursor->_new(arango => $self->{arango}, database => $self->{database}, query => $aql, %opts);
166 }
167  
168 1 ▶sub error {
Subroutine error: called CC=1 SCAR=0.0
Pod documented
169 1 my ($self) = @_;
170 1 return $self->{arango}->error;
171 }
172  
173 9 1;
174  
175 __END__
« Tango.pm ↑ Summary Tango/Database.pm »