Zonalizer/DB/CouchDB.pm

filter: Statementstmt 8.2% 37 / 630 (15 uncoverable) Branchbran 11.2% 0 / 470 (53 uncoverable) Conditioncond 0.0% 0 / 81 MC/DCmcdc 0.0% 0 / 50 Subroutinesub 25.5% 11 / 43 Podpod 100% 14 / 14 totaltotal 10.0% 62 / 1288 (68 uncoverable) CC 275 SCAR 67.7
CC
275
Cov
9%
ReadAnalysis
3721.5
HandleResponse
600.0
__ANON__
255.8
CRAP 873.1
« Zonalizer/DB.pm ↑ Summary Zonalizer/DB/Memory.pm »
1 package Lim::Plugin::Zonalizer::DB::CouchDB;
2  
3 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Scalar::Util qw(weaken blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Lim ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use AnyEvent::CouchDB ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Lim::Plugin::Zonalizer qw(:err);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use URI::Escape::XS qw(uri_escape);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use base qw(Lim::Plugin::Zonalizer::DB);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 our %VALID_ORDER_FIELD = ( analysis => { fqdn => 0, map { $_ => 1 } ( qw(created updated) ) } );
19 1 our $ID_DELIMITER = ':';
20  
21 =encoding utf8
22  
23 =head1 NAME
24  
25 Lim::Plugin::Zonalizer::DB::CouchDB - The CouchDB database for Zonalizer
26  
27 =head1 METHODS
28  
29 =over 4
30  
31 =item Init
32  
33 =cut
34  
35 0 ▶sub Init {
Subroutine Init: not called CC=5 SCAR=34.0
Pod documented
36 0 my ( $self, %args ) = @_;
37  
38 0 $self->{delete_batch} = 100;
39  
40 0 foreach ( qw(uri) ) {
41 0 ▶ unless ( defined $args{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{$_}) 0 0 0
42 0 confess 'configuration: ' . $_ . ' is not defined';
43 }
44 }
45  
46 0 foreach ( qw(delete_batch) ) {
47 0 ▶ if ( defined $args{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{$_}) 0 0 0
48 0 $self->{$_} = $args{$_};
49 }
50 }
51  
52 0 $self->{db} = AnyEvent::CouchDB::couchdb( $args{uri} );
53 0 return;
54 }
55  
56 =item Destroy
57  
58 =cut
59  
60 0 ▶sub Destroy {
Subroutine Destroy: not called CC=1 SCAR=0.0
Pod documented
61 }
62  
63 =item Name
64  
65 =cut
66  
67 0 ▶sub Name {
Subroutine Name: not called CC=1 SCAR=6.9
Pod documented
68 0 return 'CouchDB';
69 }
70  
71 =item $db->ReadAnalysis
72  
73 =cut
74  
75 0 ▶sub ReadAnalysis {
Subroutine ReadAnalysis: not called CC=64 SCAR=82.2
Pod documented
76 0 my ( $self, %args ) = @_;
77 0 my $real_self = $self;
78 0 weaken( $self );
79  
80 0 ▶ unless ( ref( $args{cb} ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args{"cb"} eq "CODE") 0 0 0
81 0 confess 'cb is not CODE';
82 }
83 0 undef $@;
84  
85 0 ▶ my $limit = defined $args{limit} ? $args{limit} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'limit'} ? : 0 0 0
86 0 ▶ if ( $limit == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($limit == 0) 0 0 0
87 0 $args{cb}->();
88 0 return;
89 }
90 0 ▶ unless ( $limit > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($limit > 0) 0 0 0
91 0 $@ = ERR_INVALID_LIMIT;
92 0 $args{cb}->();
93 0 return;
94 }
95  
96 0 my $search_fqdn;
97 my $search_fqdn2;
98 0 ▶ if ( defined $args{search} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"search"}) 0 0 0
99 0 ▶ if ( $args{search} =~ /^\../o ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'search'} =~ /^\../ou) { } 0 0 0
100 0 $search_fqdn2 = $args{search};
101 0 $search_fqdn2 =~ s/^\.//o;
102 0 $search_fqdn2 =~ s/\.$//o;
103 0 $search_fqdn2 = join( '.', reverse( split( /\./o, $search_fqdn2 ) ) );
104 }
105 else {
106 0 $search_fqdn = $args{search};
107 0 ▶ unless ( $search_fqdn =~ /\.$/o ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($search_fqdn =~ /\.$/ou) 0 0 0
108 0 $search_fqdn .= '.';
109 }
110 }
111 }
112  
113 0 my $view = '';
114 0 my %option = (
115 include_docs => 1,
116 limit => $limit
117 );
118 0 my $ignore_paging = 0;
119 0 my $reverse = 0;
120  
121 0 ▶ if ( defined $args{sort} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"sort"}) 0 0 0
122 0 ▶ if ( $args{direction} eq 'descending' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"direction"} eq "descending") 0 0 0
123 0 $option{descending} = 1;
124 }
125 }
126  
127 0 ▶ if ( defined $search_fqdn or defined $search_fqdn2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $search_fqdn or defined $search_fqdn2) 0 0 0
Condition0%0/3
defined $search_fqdn or defined $search_fqdn2
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $search_fqdn or defined $search_fqdn2
defined $search_fqdn defined $search_fqdn2
Truth table0%0/3
A or B
A= defined $search_fqdnB= defined $search_fqdn2
ABresult
1X1
011
000
128 0 ▶ if ( defined $args{after} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args{'after'}) { } 0 0 0
elsif (defined $args{'before'}) { } 0 0 0
129 0 ▶ $option{startkey} = [ $args{space} ? $args{space} : '', [ defined $search_fqdn ? $search_fqdn : $search_fqdn2, undef ] ];
Branch: 2 branches
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
defined $search_fqdn ? : 0 0 0
130 0 ▶ $option{endkey} = [ $args{space} ? $args{space} : '', [ defined $search_fqdn ? $search_fqdn : $search_fqdn2, $option{descending} ? () : ( {} ) ] ];
Branch: 3 branches
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
defined $search_fqdn ? : 0 0 0
$option{'descending'} ? : 0 0 0
131 }
132 elsif ( defined $args{before} ) {
133 0 $reverse = 1;
134 0 ▶ $option{startkey} = [ $args{space} ? $args{space} : '', [ defined $search_fqdn ? $search_fqdn : $search_fqdn2, undef ] ];
Branch: 2 branches
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
defined $search_fqdn ? : 0 0 0
135 0 ▶ $option{endkey} = [ $args{space} ? $args{space} : '', [ defined $search_fqdn ? $search_fqdn : $search_fqdn2, $option{descending} ? ( {} ) : () ] ];
Branch: 3 branches
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
defined $search_fqdn ? : 0 0 0
$option{'descending'} ? : 0 0 0
136 }
137 else {
138 0 ▶ $option{startkey} = [ $args{space} ? $args{space} : '', [ defined $search_fqdn ? $search_fqdn : $search_fqdn2, $option{descending} ? ( {} ) : () ] ];
Branch: 3 branches
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
defined $search_fqdn ? : 0 0 0
$option{'descending'} ? : 0 0 0
139 0 ▶ $option{endkey} = [ $args{space} ? $args{space} : '', [ defined $search_fqdn ? $search_fqdn : $search_fqdn2, $option{descending} ? () : ( {} ) ] ];
Branch: 3 branches
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
defined $search_fqdn ? : 0 0 0
$option{'descending'} ? : 0 0 0
140 }
141 }
142  
143 0 ▶ if ( defined $search_fqdn ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $search_fqdn) { } 0 0 0
elsif (defined $search_fqdn2) { } 0 0 0
144 0 $view = 'fqdn';
145 }
146 elsif ( defined $search_fqdn2 ) {
147 0 $view = 'rfqdn';
148 }
149  
150 0 ▶ if ( defined $args{sort} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{'sort'}) { } 0 0 0
151 0 ▶ unless ( exists $VALID_ORDER_FIELD{analysis}->{ $args{sort} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Plugin::Zonalizer::DB::CouchDB::VALID_ORDER_FIELD{"analysis"}{$args{"sort"}}) 0 0 0
152 0 $@ = ERR_INVALID_SORT_FIELD;
153 0 $args{cb}->();
154 0 return;
155 }
156  
157 0 my $startkey;
158  
159 0 ▶ if ( defined $args{after} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args{'after'}) { } 0 0 0
elsif (defined $args{'before'}) { } 0 0 0
160 0 ▶ $startkey = [ split( /$ID_DELIMITER/o, $args{after} ), !$option{descending} ? ( {} ) : () ];
Branch: 1 branch
BranchTrueFalseTotal
!$option{'descending'} ? : 0 0 0
161 0 ▶ unless ( scalar @{$startkey} == 2 + ( !$option{descending} ? 1 : 0 ) ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (scalar @{$startkey;} == 2 + (!$option{"descending"} ? 1 : 0)) 0 0 0
!$option{'descending'} ? : 0 0 0
162 0 $@ = ERR_INVALID_AFTER;
163 0 $args{cb}->();
164 0 return;
165 }
166  
167 # uncoverable branch false
168 0 ▶ if ( $VALID_ORDER_FIELD{analysis}->{ $args{sort} } == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Lim::Plugin::Zonalizer::DB::CouchDB::VALID_ORDER_FIELD{"analysis"}{$args{"sort"}} == 1) 0 0 0
169 0 $startkey->[0] = $startkey->[0] + 0;
170 }
171 }
172 elsif ( defined $args{before} ) {
173 0 $reverse = 1;
174 0 ▶ $startkey = [ split( /$ID_DELIMITER/o, $args{before} ), $option{descending} ? ( {} ) : () ];
Branch: 1 branch
BranchTrueFalseTotal
$option{'descending'} ? : 0 0 0
175 0 ▶ unless ( scalar @{$startkey} == 2 + ( $option{descending} ? 1 : 0 ) ) {
Branch: 2 branches
BranchTrueFalseTotal
unless (scalar @{$startkey;} == 2 + ($option{"descending"} ? 1 : 0)) 0 0 0
$option{'descending'} ? : 0 0 0
176 0 $@ = ERR_INVALID_BEFORE;
177 0 $args{cb}->();
178 0 return;
179 }
180  
181 # uncoverable branch false
182 0 ▶ if ( $VALID_ORDER_FIELD{analysis}->{ $args{sort} } == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Lim::Plugin::Zonalizer::DB::CouchDB::VALID_ORDER_FIELD{"analysis"}{$args{"sort"}} == 1) 0 0 0
183 0 $startkey->[0] = $startkey->[0] + 0;
184 }
185 }
186  
187 0 ▶ if ( $startkey ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($startkey) 0 0 0
188 0 ▶ unless ( $option{startkey} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($option{"startkey"}) 0 0 0
189 0 ▶ $option{startkey} = [ $args{space} ? $args{space} : '' ];
Branch: 1 branch
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
190 }
191 0 push( @{ $option{startkey} }, @$startkey );
192 }
193  
194 0 ▶ $view = ( $view ? $view . '_' : '' ) . 'by_' . $args{sort};
Branch: 1 branch
BranchTrueFalseTotal
$view ? : 0 0 0
195 }
196 else {
197 0 my $startkey;
198  
199 0 ▶ if ( defined $args{after} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $args{'after'}) { } 0 0 0
elsif (defined $args{'before'}) { } 0 0 0
200 0 ▶ $startkey = [ $args{space} ? $args{space} : '', $args{after}, {} ];
Branch: 1 branch
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
201 }
202 elsif ( defined $args{before} ) {
203 0 $reverse = 1;
204 0 ▶ $startkey = [ $args{space} ? $args{space} : '', $args{before} ];
Branch: 1 branch
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
205 }
206  
207 0 ▶ if ( $startkey ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($startkey) 0 0 0
208 0 push( @{ $option{startkey} }, @$startkey );
209 }
210  
211 0 ▶ unless ( $view ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($view) 0 0 0
212 0 $view = 'all';
213 }
214 }
215  
216 0 ▶ if ( $reverse ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reverse) 0 0 0
217 0 ▶ if ( $option{descending} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option{'descending'}) { } 0 0 0
218 0 delete $option{descending};
219 }
220 else {
221 0 $option{descending} = 1;
222 }
223 }
224  
225 0 ▶ unless ( $option{startkey} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($option{"startkey"}) 0 0 0
226 0 ▶ $option{startkey} = [ $args{space} ? $args{space} : '', $option{descending} ? ( {} ) : () ];
Branch: 2 branches
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
$option{'descending'} ? : 0 0 0
227 }
228 0 ▶ unless ( $option{endkey} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($option{"endkey"}) 0 0 0
229 0 ▶ $option{endkey} = [ $args{space} ? $args{space} : '', $option{descending} ? () : ( {} ) ];
Branch: 2 branches
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
$option{'descending'} ? : 0 0 0
230 }
231  
232 # uncoverable branch false
233 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb analysis/', $view, $args{space} ? ' ' . $args{space} : '' );
Branch: 2 branches
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb analysis/", $view, $args{"space"} ? ' ' . $args{"space"} : "") 0 0 0
$args{'space'} ? : 0 0 0
234 $self->{db}->view( 'analysis/' . $view, \%option )->cb(
235 0 ▶ sub {
Subroutine __ANON__: not called CC=17 SCAR=55.4
236 # uncoverable branch true
237 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
238  
239 # uncoverable statement
240 0 return;
241 }
242  
243 0 my ( $before, $after, $previous, $next, $rows, $total_rows, $offset );
244 0 eval { ( $before, $after, $previous, $next, $rows, $total_rows, $offset ) = $self->HandleResponse( $_[0], $reverse, 1 ); };
245 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
246  
247 # uncoverable branch false
248 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
249 0 $@ = ERR_INTERNAL_DATABASE;
250 0 $args{cb}->();
251 0 return;
252 }
253  
254 0 ▶ unless ( $offset ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($offset) 0 0 0
255 0 $previous = 0;
256 }
257  
258 0 my $extra = '';
259 0 ▶ if ( defined $search_fqdn ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $search_fqdn) 0 0 0
260 0 ▶ $extra .= ( $extra ? '&' : '' ) . 'search=' . uri_escape( $search_fqdn );
Branch: 1 branch
BranchTrueFalseTotal
$extra ? : 0 0 0
261 }
262 0 ▶ if ( defined $search_fqdn2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $search_fqdn2) 0 0 0
263 0 ▶ $extra .= ( $extra ? '&' : '' ) . 'search=' . uri_escape( '.' . $search_fqdn2 );
Branch: 1 branch
BranchTrueFalseTotal
$extra ? : 0 0 0
264 }
265 0 ▶ if ( $args{space} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"space"}) 0 0 0
266 0 ▶ $extra .= ( $extra ? '&' : '' ) . 'space=' . uri_escape( $args{space} );
Branch: 1 branch
BranchTrueFalseTotal
$extra ? : 0 0 0
267 }
268  
269 0 ▶ my $code = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
270 0 ▶ $args{cb}->(
Branch: 2 branches
BranchTrueFalseTotal
($previous || $next) && !$ignore_paging ? : 0 0 0
$extra ? : 0 0 0
Condition0%0/6
$previous || $next and not $ignore_paging
!ll&&!rl&&r
000
$previous or $next
l!l&&r!l&&!r
000
MC/DC0%0/3
$previous || $next and not $ignore_paging
$previous $next not $ignore_paging
Truth table0%0/5
A or B and not(C)
A= $previousB= $nextC= not $ignore_paging
ABCresult
00X0
1X00
0100
1X11
0111
271 ( $previous || $next ) && !$ignore_paging
272 ? {
273 before => $before,
274 after => $after,
275 previous => $previous,
276 next => $next,
277 $extra ? ( extra => $extra ) : ()
278 }
279 : undef,
280 @$rows
281 );
282 0 };
283  
284 0 ▶ unless ( scalar @$rows ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$rows) 0 0 0
285 0 $ignore_paging = 1;
286 0 $code->();
287 0 return;
288 }
289  
290 #
291 # We need to swap after/before since we are using a descending
292 # view to do reverse lookup
293 #
294 0 ▶ if ( $reverse ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reverse) 0 0 0
295 0 my $a = $after;
296 0 my $b = $before;
297 0 $before = $a;
298 0 $after = $b;
299 }
300  
301 # TODO: Can this be solved in a better way then fetching previous/next with skip?
302  
303 0 $option{limit} = 1;
304 0 delete $option{startkey};
305 0 delete $option{endkey};
306 0 delete $option{include_docs};
307  
308 0 ▶ my $code_next = sub {
Subroutine __ANON__: not called CC=5 SCAR=32.2
309 0 ▶ unless ( $next ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($next) 0 0 0
310 0 $code->();
311 0 return;
312 }
313  
314 0 ▶ if ( $reverse ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reverse) { } 0 0 0
315  
316 # uncoverable branch false
317 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb analysis/', $view, ' next check (reverse), skip ', $offset - 1 );
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb analysis/", $view, " next check (reverse), skip ", $offset - 1) 0 0 0
318 0 $option{skip} = $offset - 1;
319 }
320 else {
321 # uncoverable branch false
322 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb analysis/', $view, ' next check, skip ', $offset + scalar @$rows );
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb analysis/", $view, " next check, skip ", $offset + scalar(@$rows)) 0 0 0
323 0 $option{skip} = $offset + scalar @$rows;
324 }
325 $self->{db}->view( 'analysis/' . $view, \%option )->cb(
326 0 ▶ sub {
Subroutine __ANON__: not called CC=15 SCAR=53.2
327 # uncoverable branch true
328 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
329  
330 # uncoverable statement
331 0 return;
332 }
333  
334 0 my ( $keys );
335 0 eval {
336 0 $keys = $self->HandleResponseKey( $_[0] );
337  
338 0 ▶ unless ( ref( $keys->[0] ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $keys->[0] eq "ARRAY") 0 0 0
339 0 die 'invalid schema';
340 }
341 0 ▶ if ( defined $search_fqdn or defined $search_fqdn2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $search_fqdn or defined $search_fqdn2) 0 0 0
Condition0%0/3
defined $search_fqdn or defined $search_fqdn2
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $search_fqdn or defined $search_fqdn2
defined $search_fqdn defined $search_fqdn2
Truth table0%0/3
A or B
A= defined $search_fqdnB= defined $search_fqdn2
ABresult
1X1
011
000
342 0 ▶ unless ( ref( $keys->[0]->[1] ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $keys->[0][1] eq "ARRAY") 0 0 0
343 0 die 'invalid schema';
344 }
345 }
346 };
347 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
348  
349 # uncoverable branch false
350 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
351 0 $@ = ERR_INTERNAL_DATABASE;
352 0 $args{cb}->();
353 0 return;
354 }
355  
356 0 ▶ if ( defined $search_fqdn and $keys->[0]->[1]->[0] ne $search_fqdn ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $search_fqdn and $keys->[0][1][0] ne $search_fqdn) { } 0 0 0
elsif (defined $search_fqdn2 and $keys->[0][1][0] ne $search_fqdn2) { } 0 0 0
Condition0%0/3
defined $search_fqdn and $keys->[0][1][0] ne $search_fqdn
!ll&&!rl&&r
000
MC/DC0%0/2
defined $search_fqdn and $keys->[0][1][0] ne $search_fqdn
defined $search_fqdn $keys->[0][1][0] ne $search_fqdn
Truth table0%0/3
A and B
A= defined $search_fqdnB= $keys->[0][1][0] ne $search_fqdn
ABresult
0X0
100
111
357 0 $next = 0;
358 }
359 ▶ elsif ( defined $search_fqdn2 and $keys->[0]->[1]->[0] ne $search_fqdn2 ) {
Condition0%0/3
defined $search_fqdn2 and $keys->[0][1][0] ne $search_fqdn2
!ll&&!rl&&r
000
MC/DC0%0/2
defined $search_fqdn2 and $keys->[0][1][0] ne $search_fqdn2
defined $search_fqdn2 $keys->[0][1][0] ne $search_fqdn2
Truth table0%0/3
A and B
A= defined $search_fqdn2B= $keys->[0][1][0] ne $search_fqdn2
ABresult
0X0
100
111
360 0 $next = 0;
361 }
362  
363 0 ▶ if ( $args{space} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'space'}) { } 0 0 0
elsif ($keys->[0][0] ne '') { } 0 0 0
364 0 ▶ unless ( $keys->[0]->[0] eq $args{space} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($keys->[0][0] eq $args{"space"}) 0 0 0
365 0 $next = 0;
366 }
367 }
368 elsif ( $keys->[0]->[0] ne '' ) {
369 0 $next = 0;
370 }
371  
372 0 $code->();
373 }
374 0 );
375 0 };
376  
377 0 ▶ unless ( $previous ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($previous) 0 0 0
378 0 $code_next->();
379 0 return;
380 }
381  
382 0 ▶ if ( $reverse ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reverse) { } 0 0 0
383  
384 # uncoverable branch false
385 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb analysis/', $view, ' previous check (reverse), skip ', $offset + scalar @$rows );
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb analysis/", $view, " previous check (reverse), skip ", $offset + scalar(@$rows)) 0 0 0
386 0 $option{skip} = $offset + scalar @$rows;
387 }
388 else {
389 # uncoverable branch false
390 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb analysis/', $view, ' previous check, skip ', $offset - 1 );
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb analysis/", $view, " previous check, skip ", $offset - 1) 0 0 0
391 0 $option{skip} = $offset - 1;
392 }
393 $self->{db}->view( 'analysis/' . $view, \%option )->cb(
394 0 ▶ sub {
Subroutine __ANON__: not called CC=15 SCAR=53.2
395 # uncoverable branch true
396 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
397  
398 # uncoverable statement
399 0 return;
400 }
401  
402 0 my ( $keys );
403 0 eval {
404 0 $keys = $self->HandleResponseKey( $_[0] );
405  
406 0 ▶ unless ( ref( $keys->[0] ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $keys->[0] eq "ARRAY") 0 0 0
407 0 die 'invalid schema';
408 }
409 0 ▶ if ( defined $search_fqdn or defined $search_fqdn2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $search_fqdn or defined $search_fqdn2) 0 0 0
Condition0%0/3
defined $search_fqdn or defined $search_fqdn2
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $search_fqdn or defined $search_fqdn2
defined $search_fqdn defined $search_fqdn2
Truth table0%0/3
A or B
A= defined $search_fqdnB= defined $search_fqdn2
ABresult
1X1
011
000
410 0 ▶ unless ( ref( $keys->[0]->[1] ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $keys->[0][1] eq "ARRAY") 0 0 0
411 0 die 'invalid schema';
412 }
413 }
414 };
415 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
416  
417 # uncoverable branch false
418 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
419 0 $@ = ERR_INTERNAL_DATABASE;
420 0 $args{cb}->();
421 0 return;
422 }
423  
424 0 ▶ if ( defined $search_fqdn and $keys->[0]->[1]->[0] ne $search_fqdn ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $search_fqdn and $keys->[0][1][0] ne $search_fqdn) { } 0 0 0
elsif (defined $search_fqdn2 and $keys->[0][1][0] ne $search_fqdn2) { } 0 0 0
Condition0%0/3
defined $search_fqdn and $keys->[0][1][0] ne $search_fqdn
!ll&&!rl&&r
000
MC/DC0%0/2
defined $search_fqdn and $keys->[0][1][0] ne $search_fqdn
defined $search_fqdn $keys->[0][1][0] ne $search_fqdn
Truth table0%0/3
A and B
A= defined $search_fqdnB= $keys->[0][1][0] ne $search_fqdn
ABresult
0X0
100
111
425 0 $previous = 0;
426 }
427 ▶ elsif ( defined $search_fqdn2 and $keys->[0]->[1]->[0] ne $search_fqdn2 ) {
Condition0%0/3
defined $search_fqdn2 and $keys->[0][1][0] ne $search_fqdn2
!ll&&!rl&&r
000
MC/DC0%0/2
defined $search_fqdn2 and $keys->[0][1][0] ne $search_fqdn2
defined $search_fqdn2 $keys->[0][1][0] ne $search_fqdn2
Truth table0%0/3
A and B
A= defined $search_fqdn2B= $keys->[0][1][0] ne $search_fqdn2
ABresult
0X0
100
111
428 0 $previous = 0;
429 }
430  
431 0 ▶ if ( $args{space} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args{'space'}) { } 0 0 0
elsif ($keys->[0][0] ne '') { } 0 0 0
432 0 ▶ unless ( $keys->[0]->[0] eq $args{space} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($keys->[0][0] eq $args{"space"}) 0 0 0
433 0 $previous = 0;
434 }
435 }
436 elsif ( $keys->[0]->[0] ne '' ) {
437 0 $previous = 0;
438 }
439  
440 0 $code_next->();
441 }
442 0 );
443 }
444 0 );
445 0 return;
446 }
447  
448 =item DeleteAnalysis
449  
450 =over 4
451  
452 =item cb => sub { my ($deleted_analysis) = @_; ... }
453  
454 $@ on error
455  
456 =back
457  
458 =cut
459  
460 0 ▶sub DeleteAnalysis {
Subroutine DeleteAnalysis: not called CC=2 SCAR=15.5
Pod documented
461 0 my ( $self, %args ) = @_;
462 0 my $real_self = $self;
463 0 weaken( $self );
464  
465 0 ▶ unless ( ref( $args{cb} ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args{"cb"} eq "CODE") 0 0 0
466 0 confess 'cb is not CODE';
467 }
468 0 undef $@;
469  
470 0 my ( $deleted_analysis ) = ( 0 );
471 0 my $analysis;
472 0 ▶ $analysis = sub {
Subroutine __ANON__: not called CC=4 SCAR=26.2
473  
474 # uncoverable branch false
475 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb analysis/all', $args{space} ? ' ' . $args{space} : '' );
Branch: 2 branches
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb analysis/all", $args{"space"} ? ' ' . $args{"space"} : "") 0 0 0
$args{'space'} ? : 0 0 0
476 $self->{db}->view(
477 'analysis/all',
478 {
479 $args{space}
480 ? (
481 startkey => [ $args{space}, undef ],
482 endkey => [ $args{space}, {} ]
483 )
484 : (),
485 limit => $self->{delete_batch},
486 include_docs => 1
487 }
488 )->cb(
489 0 ▶ sub {
Subroutine __ANON__: not called CC=7 SCAR=36.0
490 # uncoverable branch true
491 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
492  
493 # uncoverable statement
494 0 return;
495 }
496  
497 0 my $rows;
498 0 eval { $rows = $self->HandleResponseIdRev( $_[0] ); };
499 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
500  
501 # uncoverable branch false
502 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
503 0 $@ = ERR_INTERNAL_DATABASE;
504 0 $args{cb}->( $deleted_analysis );
505 0 return;
506 }
507  
508 0 ▶ unless ( scalar @$rows ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$rows) 0 0 0
509 0 $args{cb}->( $deleted_analysis );
510 0 return;
511 }
512  
513 0 foreach ( @$rows ) {
514 0 $_->{_deleted} = JSON::true;
515 }
516  
517 # uncoverable branch false
518 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb bulk_docs analysis' );
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb bulk_docs analysis") 0 0 0
519 $self->{db}->bulk_docs( $rows )->cb(
520 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=25.8
521 0 my ( $cv ) = @_;
522  
523 # uncoverable branch true
524 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
525  
526 # uncoverable statement
527 0 return;
528 }
529  
530 0 eval { $cv->recv; };
531 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
532  
533 # uncoverable branch false
534 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
535 0 $@ = ERR_INTERNAL_DATABASE;
536 0 $args{cb}->( $deleted_analysis );
537 0 return;
538 }
539  
540 0 $deleted_analysis += scalar @$rows;
541 0 $analysis->();
542 }
543 0 );
544 }
545 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
546 0 };
547 0 $analysis->();
548 0 return;
549 }
550  
551 =item CreateAnalyze
552  
553 =cut
554  
555 0 ▶sub CreateAnalyze {
Subroutine CreateAnalyze: not called CC=7 SCAR=35.6
Pod documented
556 0 my ( $self, %args ) = @_;
557 0 my $real_self = $self;
558 0 weaken( $self );
559  
560 0 ▶ unless ( ref( $args{cb} ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args{"cb"} eq "CODE") 0 0 0
561 0 confess 'cb is not CODE';
562 }
563 0 $self->ValidateAnalyze( $args{analyze} );
564 0 undef $@;
565  
566 0 ▶ if ( exists $args{analyze}->{_id} or exists $args{analyze}->{_rev} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"analyze"}{"_id"} or exists $args{"analyze"}{"_rev"}) 0 0 0
Condition0%0/3
exists $args{"analyze"}{"_id"} or exists $args{"analyze"}{"_rev"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $args{"analyze"}{"_id"} or exists $args{"analyze"}{"_rev"}
exists $args{"analyze"}{"_id"} exists $args{"analyze"}{"_rev"}
Truth table0%0/3
A or B
A= exists $args{"analyze"}{"_id"}B= exists $args{"analyze"}{"_rev"}
ABresult
1X1
011
000
567  
568 # uncoverable branch false
569 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB specific fields _id/_rev existed during create' );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB specific fields _id/_rev existed during create") 0 0 0
570 0 $@ = ERR_INTERNAL_DATABASE;
571 0 $args{cb}->();
572 0 return;
573 }
574  
575 my %analyze = (
576 0 ▶ %{ clone $args{analyze} },
Branch: 1 branch
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
577 type => 'new_analyze',
578 0 space => $args{space} ? $args{space} : ''
579 );
580  
581 # uncoverable branch false
582 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb save_doc new_analyze' );
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb save_doc new_analyze") 0 0 0
583 $self->{db}->save_doc( \%analyze )->cb(
584 0 ▶ sub {
Subroutine __ANON__: not called CC=7 SCAR=34.8
585 0 my ( $cv ) = @_;
586  
587 # uncoverable branch true
588 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
589  
590 # uncoverable statement
591 0 return;
592 }
593  
594 0 eval { $cv->recv; };
595 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
596  
597 # uncoverable branch false
598 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
599 0 $@ = ERR_INTERNAL_DATABASE;
600 0 $args{cb}->();
601 0 return;
602 }
603  
604 # uncoverable branch false
605 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb new_analysis/all ', $analyze{id}, $args{space} ? ' ' . $args{space} : '' );
Branch: 2 branches
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb new_analysis/all ", $analyze{"id"}, $args{"space"} ? ' ' . $args{"space"} : "") 0 0 0
$args{'space'} ? : 0 0 0
606 $self->{db}->view(
607 'new_analysis/all',
608 {
609 key => [
610 $args{space} ? $args{space} : '',
611 $analyze{id}
612 ]
613 }
614 )->cb(
615 0 ▶ sub {
Subroutine __ANON__: not called CC=8 SCAR=36.9
616 # uncoverable branch true
617 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
618  
619 # uncoverable statement
620 0 return;
621 }
622  
623 0 my $rows;
624 0 eval { $rows = $self->HandleResponseId( $_[0] ); };
625 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
626  
627 # uncoverable branch false
628 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
629 0 $@ = ERR_INTERNAL_DATABASE;
630 0 $args{cb}->();
631 0 return;
632 }
633 0 ▶ unless ( scalar @$rows ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$rows) 0 0 0
634 $self->{db}->remove_doc( \%analyze )->cb(
635 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=17.3
636 0 eval { $_[0]->recv; };
637  
638 # uncoverable branch true
639 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
640  
641 # uncoverable statement
642 0 return;
643 }
644  
645 # uncoverable branch false
646 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
647 }
648 0 );
649  
650 # uncoverable branch false
651 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: created analyze but was not returned' );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: created analyze but was not returned") 0 0 0
652 0 $@ = ERR_INTERNAL_DATABASE;
653 0 $args{cb}->();
654 0 return;
655 }
656 0 ▶ unless ( scalar @$rows == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$rows == 1) 0 0 0
657 $self->{db}->remove_doc( \%analyze )->cb(
658 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=17.3
659 0 eval { $_[0]->recv; };
660  
661 # uncoverable branch true
662 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
663  
664 # uncoverable statement
665 0 return;
666 }
667  
668 # uncoverable branch false
669 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
670 }
671 0 );
672 0 $@ = ERR_DUPLICATE_ID;
673 0 $args{cb}->();
674 0 return;
675 }
676  
677 0 $analyze{type} = 'analyze';
678  
679 # uncoverable branch false
680 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb save_doc analyze' );
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb save_doc analyze") 0 0 0
681 $self->{db}->save_doc( \%analyze )->cb(
682 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=24.4
683 0 my ( $cv ) = @_;
684  
685 # uncoverable branch true
686 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
687  
688 # uncoverable statement
689 0 return;
690 }
691  
692 0 eval { $cv->recv; };
693 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
694 $self->{db}->remove_doc( \%analyze )->cb(
695 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=17.3
696 0 eval { $_[0]->recv; };
697  
698 # uncoverable branch true
699 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
700  
701 # uncoverable statement
702 0 return;
703 }
704  
705 # uncoverable branch false
706 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
707 }
708 0 );
709  
710 # uncoverable branch false
711 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
712 0 $@ = ERR_INTERNAL_DATABASE;
713 0 $args{cb}->();
714 0 return;
715 }
716  
717 0 $args{cb}->( \%analyze );
718 }
719 0 );
720 }
721 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
722 }
723 0 );
724 0 return;
725 }
726  
727 =item ReadAnalyze
728  
729 =cut
730  
731 0 ▶sub ReadAnalyze {
Subroutine ReadAnalyze: not called CC=6 SCAR=34.9
Pod documented
732 0 my ( $self, %args ) = @_;
733 0 my $real_self = $self;
734 0 weaken( $self );
735  
736 0 ▶ unless ( ref( $args{cb} ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args{"cb"} eq "CODE") 0 0 0
737 0 confess 'cb is not CODE';
738 }
739 0 ▶ unless ( defined $args{id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"id"}) 0 0 0
740 0 confess 'id is not defined';
741 }
742 0 undef $@;
743  
744 # uncoverable branch false
745 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb analysis/all ', $args{id}, $args{space} ? ' ' . $args{space} : '' );
Branch: 2 branches
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb analysis/all ", $args{"id"}, $args{"space"} ? ' ' . $args{"space"} : "") 0 0 0
$args{'space'} ? : 0 0 0
746 $self->{db}->view(
747 'analysis/all',
748 {
749 key => [
750 $args{space} ? $args{space} : '',
751 $args{id},
752 undef
753 ],
754 include_docs => 1
755 }
756 )->cb(
757 0 ▶ sub {
Subroutine __ANON__: not called CC=7 SCAR=36.8
758 # uncoverable branch true
759 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
760  
761 # uncoverable statement
762 0 return;
763 }
764  
765 0 my $rows;
766 0 eval { $rows = $self->HandleResponse( $_[0], 0, 1 ); };
767 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
768  
769 # uncoverable branch false
770 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
771 0 $@ = ERR_INTERNAL_DATABASE;
772 0 $args{cb}->();
773 0 return;
774 }
775 0 ▶ unless ( scalar @$rows ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$rows) 0 0 0
776 0 $@ = ERR_ID_NOT_FOUND;
777 0 $args{cb}->();
778 0 return;
779 }
780 0 ▶ if ( scalar @$rows > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$rows > 1) 0 0 0
781  
782 # uncoverable branch false
783 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: too many rows returned' );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: too many rows returned") 0 0 0
784 0 $@ = ERR_INTERNAL_DATABASE;
785 0 $args{cb}->();
786 0 return;
787 }
788  
789 0 $args{cb}->( $rows->[0] );
790 }
791 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
792 0 return;
793 }
794  
795 =item UpdateAnalyze
796  
797 =cut
798  
799 0 ▶sub UpdateAnalyze {
Subroutine UpdateAnalyze: not called CC=13 SCAR=49.4
Pod documented
800 0 my ( $self, %args ) = @_;
801 0 my $real_self = $self;
802 0 weaken( $self );
803  
804 0 ▶ unless ( ref( $args{cb} ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args{"cb"} eq "CODE") 0 0 0
805 0 confess 'cb is not CODE';
806 }
807 0 $self->ValidateAnalyze( $args{analyze} );
808 0 undef $@;
809  
810 0 ▶ unless ( defined $args{analyze}->{_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"analyze"}{"_id"}) 0 0 0
811  
812 # uncoverable branch false
813 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB specific _id is missing' );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB specific _id is missing") 0 0 0
814 0 $@ = ERR_ID_NOT_FOUND;
815 0 $args{cb}->();
816 0 return;
817 }
818 0 ▶ unless ( defined $args{analyze}->{_rev} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"analyze"}{"_rev"}) 0 0 0
819  
820 # uncoverable branch false
821 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB specific _rev is missing' );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB specific _rev is missing") 0 0 0
822 0 $@ = ERR_REVISION_MISSMATCH;
823 0 $args{cb}->();
824 0 return;
825 }
826 0 ▶ unless ( defined $args{analyze}->{space} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"analyze"}{"space"}) 0 0 0
827  
828 # uncoverable branch false
829 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB specific space is missing' );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB specific space is missing") 0 0 0
830 0 $@ = ERR_SPACE_MISSMATCH;
831 0 $args{cb}->();
832 0 return;
833 }
834 0 ▶ if ( defined $args{space} and $args{space} ne $args{analyze}->{space} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"space"} and $args{"space"} ne $args{"analyze"}{"space"}) 0 0 0
Condition0%0/3
defined $args{"space"} and $args{"space"} ne $args{"analyze"}{"space"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"space"} and $args{"space"} ne $args{"analyze"}{"space"}
defined $args{"space"} $args{"space"} ne $args{"analyze"}{"space"}
Truth table0%0/3
A and B
A= defined $args{"space"}B= $args{"space"} ne $args{"analyze"}{"space"}
ABresult
0X0
100
111
835 0 $@ = ERR_SPACE_MISSMATCH;
836 0 $args{cb}->();
837 0 return;
838 }
839 0 ▶ if ( !defined $args{space} and $args{analyze}->{space} ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $args{"space"} and $args{"analyze"}{"space"} ne "") 0 0 0
Condition0%0/3
not defined $args{"space"} and $args{"analyze"}{"space"} ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $args{"space"} and $args{"analyze"}{"space"} ne ""
not defined $args{"space"} $args{"analyze"}{"space"} ne ""
Truth table0%0/3
not(A) and B
A= not defined $args{"space"}B= $args{"analyze"}{"space"} ne ""
ABresult
0X0
100
111
840 0 $@ = ERR_SPACE_MISSMATCH;
841 0 $args{cb}->();
842 0 return;
843 }
844  
845 # uncoverable branch false
846 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb save_doc analyze' );
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb save_doc analyze") 0 0 0
847 0 my $analyze = clone $args{analyze};
848 $self->{db}->save_doc( $analyze )->cb(
849 0 ▶ sub {
Subroutine __ANON__: not called CC=4 SCAR=25.6
850 0 my ( $cv ) = @_;
851  
852 # uncoverable branch true
853 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
854  
855 # uncoverable statement
856 0 return;
857 }
858  
859 0 eval { $cv->recv; };
860 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
861  
862 # uncoverable branch false
863 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
864 0 $@ = ERR_INTERNAL_DATABASE;
865 0 $args{cb}->();
866 0 return;
867 }
868  
869 0 $args{cb}->( $analyze );
870 }
871 0 );
872 0 return;
873 }
874  
875 =item DeleteAnalyze
876  
877 =cut
878  
879 0 ▶sub DeleteAnalyze {
Subroutine DeleteAnalyze: not called CC=6 SCAR=34.7
Pod documented
880 0 my ( $self, %args ) = @_;
881 0 my $real_self = $self;
882 0 weaken( $self );
883  
884 0 ▶ unless ( ref( $args{cb} ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args{"cb"} eq "CODE") 0 0 0
885 0 confess 'cb is not CODE';
886 }
887 0 ▶ unless ( defined $args{id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"id"}) 0 0 0
888 0 confess 'id is not defined';
889 }
890 0 undef $@;
891  
892 # uncoverable branch false
893 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb analysis/all ', $args{id}, $args{space} ? ' ' . $args{space} : '' );
Branch: 2 branches
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb analysis/all ", $args{"id"}, $args{"space"} ? ' ' . $args{"space"} : "") 0 0 0
$args{'space'} ? : 0 0 0
894 $self->{db}->view(
895 'analysis/all',
896 {
897 key => [
898 $args{space} ? $args{space} : '',
899 $args{id},
900 undef
901 ],
902 include_docs => 1
903 }
904 )->cb(
905 0 ▶ sub {
Subroutine __ANON__: not called CC=8 SCAR=39.5
906 # uncoverable branch true
907 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
908  
909 # uncoverable statement
910 0 return;
911 }
912  
913 0 my $rows;
914 0 eval { $rows = $self->HandleResponse( $_[0] ); };
915 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
916  
917 # uncoverable branch false
918 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
919 0 $@ = ERR_INTERNAL_DATABASE;
920 0 $args{cb}->();
921 0 return;
922 }
923 0 ▶ unless ( scalar @$rows ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @$rows) 0 0 0
924 0 $@ = ERR_ID_NOT_FOUND;
925 0 $args{cb}->();
926 0 return;
927 }
928 0 ▶ if ( scalar @$rows > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$rows > 1) 0 0 0
929  
930 # uncoverable branch false
931 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: too many rows returned' );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: too many rows returned") 0 0 0
932 0 $@ = ERR_INTERNAL_DATABASE;
933 0 $args{cb}->();
934 0 return;
935 }
936  
937 0 $rows->[0]->{_deleted} = JSON::true;
938  
939 # uncoverable branch false
940 0 ▶ Lim::DEBUG and $self->{logger}->debug( 'couchdb save_doc ', $args{id} );
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("couchdb save_doc ", $args{"id"}) 0 0 0
941 $self->{db}->save_doc( $rows->[0] )->cb(
942 0 ▶ sub {
Subroutine __ANON__: not called CC=9 SCAR=42.3
943 0 my ( $cv ) = @_;
944  
945 # uncoverable branch true
946 0 ▶ unless ( defined $self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
947  
948 # uncoverable statement
949 0 return;
950 }
951  
952 0 eval { $cv->recv; };
953 0 ▶ if ( blessed $@ and $@->can( 'headers' ) and ref( $@->headers ) eq 'HASH' and $@->headers->{Status} == 200 and $@->headers->{Reason} eq 'OK' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($@) and $@->can("headers") and ref $@->headers eq "HASH" and $@->headers->{"Status"} == 200 and $@->headers->{"Reason"} eq "OK") 0 0 0
Condition0%0/12
builtin::blessed($@) and $@->can("headers") and ref $@->headers eq "HASH" and $@->headers->{"Status"} == 200 and $@->headers->{"Reason"} eq "OK"
!ll&&!rl&&r
000
builtin::blessed($@) and $@->can("headers") and ref $@->headers eq "HASH" and $@->headers->{"Status"} == 200
!ll&&!rl&&r
000
builtin::blessed($@) and $@->can("headers") and ref $@->headers eq "HASH"
!ll&&!rl&&r
000
builtin::blessed($@) and $@->can("headers")
!ll&&!rl&&r
000
MC/DC0%0/5
builtin::blessed($@) and $@->can("headers") and ref $@->headers eq "HASH" and $@->headers->{"Status"} == 200 and $@->headers->{"Reason"} eq "OK"
builtin::blessed($@) $@->can("headers") ref $@->headers eq "HASH" $@->headers->{"Status"} == 200 $@->headers->{"Reason"} eq "OK"
Truth table0%0/6
A and B and C and D and E
A= builtin::blessed($@)B= $@->can("headers")C= ref $@->headers eq "HASH"D= $@->headers->{"Status"} == 200E= $@->headers->{"Reason"} eq "OK"
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
954 0 undef $@;
955 }
956 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
957  
958 # uncoverable branch false
959 0 ▶ Lim::ERR and $self->{logger}->error( 'CouchDB error: ', $@ );
Branch: 1 branch
BranchTrueFalseTotal
Lim::ERR() and $self->{"logger"}->error("CouchDB error: ", $@) 0 0 0
960 0 $@ = ERR_INTERNAL_DATABASE;
961 }
962  
963 0 $args{cb}->();
964 }
965 0 );
966 }
967 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$args{'space'} ? : 0 0 0
968 0 return;
969 }
970  
971 =back
972  
973 =head1 PRIVATE METHODS
974  
975 =over 4
976  
977 =item HandleResponse
978  
979 =cut
980  
981 0 ▶sub HandleResponse {
Subroutine HandleResponse: not called CC=24 SCAR=64.0
Pod documented
982 0 my ( $self, $cv, $reverse, $keyskip ) = @_;
983  
984 0 ▶ unless ( blessed $cv and $cv->can( 'recv' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($cv) and $cv->can("recv")) 0 0 0
Condition0%0/3
builtin::blessed($cv) and $cv->can("recv")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($cv) and $cv->can("recv")
builtin::blessed($cv) $cv->can("recv")
Truth table0%0/3
A and B
A= builtin::blessed($cv)B= $cv->can("recv")
ABresult
0X0
100
111
985 0 die 'cv is not object';
986 }
987  
988 0 my $data = $cv->recv;
989  
990 0 ▶ unless ( ref( $data ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data eq "HASH") 0 0 0
991 0 die 'data is not HASH';
992 }
993 0 foreach ( qw(offset total_rows rows) ) {
994 0 ▶ unless ( defined $data->{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data->{$_}) 0 0 0
995 0 die 'data->' . $_ . ' is not defined';
996 }
997 }
998 0 ▶ unless ( ref( $data->{rows} ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data->{"rows"} eq "ARRAY") 0 0 0
999 0 die 'data->rows is not ARRAY';
1000 }
1001  
1002 0 my ( $before, $after, $previous, $next, @rows ) = ( undef, undef, 0, 0 );
1003  
1004 0 foreach ( @{ $data->{rows} } ) {
1005 0 ▶ unless ( ref( $_ ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ eq "HASH") 0 0 0
1006 0 die 'data->rows[] entry is not HASH';
1007 }
1008 0 ▶ unless ( ref( $_->{key} ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_->{"key"} eq "ARRAY") 0 0 0
1009 0 die 'data->rows[]->key is not ARRAY';
1010 }
1011 0 ▶ unless ( ref( $_->{doc} ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_->{"doc"} eq "HASH") 0 0 0
1012 0 die 'data->rows[]->doc is not HASH';
1013 }
1014 0 push( @rows, $_->{doc} );
1015 }
1016  
1017 0 ▶ unless ( wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (wantarray) 0 0 0
1018 0 return \@rows;
1019 }
1020  
1021 0 ▶ if ( $reverse ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reverse) { } 0 0 0
1022 0 @rows = reverse @rows;
1023  
1024 0 ▶ if ( $data->{offset} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"offset"} > 0) 0 0 0
1025 0 $next = 1;
1026 }
1027 0 ▶ if ( ( $data->{total_rows} - $data->{offset} - scalar @rows ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"total_rows"} - $data->{"offset"} - scalar(@rows) > 0) 0 0 0
1028 0 $previous = 1;
1029 }
1030 }
1031 else {
1032 0 ▶ if ( $data->{offset} > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"offset"} > 0) 0 0 0
1033 0 $previous = 1;
1034 }
1035 0 ▶ if ( ( $data->{total_rows} - $data->{offset} - scalar @rows ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"total_rows"} - $data->{"offset"} - scalar(@rows) > 0) 0 0 0
1036 0 $next = 1;
1037 }
1038 }
1039  
1040 0 ▶ if ( $keyskip ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keyskip) { } 0 0 0
1041 0 my ( $skip, @key );
1042  
1043 0 ▶ @key = grep { defined $_ && !ref( $_ ) } @{ $data->{rows}->[0]->{key} };
Condition0%0/3
defined $_ && !ref($_)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && !ref($_)
defined $_ !ref($_)
Truth table0%0/3
A && not(B)
A= defined $_B= !ref($_)
ABresult
0X0
100
111
1044 0 $skip = $keyskip;
1045 0 ▶ while ( $skip-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip--) 0 0 0
1046 0 shift( @key );
1047 }
1048 0 $before = join( $ID_DELIMITER, @key );
1049  
1050 0 ▶ @key = grep { defined $_ && !ref( $_ ) } @{ $data->{rows}->[-1]->{key} };
Condition0%0/3
defined $_ && !ref($_)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && !ref($_)
defined $_ !ref($_)
Truth table0%0/3
A && not(B)
A= defined $_B= !ref($_)
ABresult
0X0
100
111
1051 0 $skip = $keyskip;
1052 0 ▶ while ( $skip-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip--) 0 0 0
1053 0 shift( @key );
1054 }
1055 0 $after = join( $ID_DELIMITER, @key );
1056 }
1057 else {
1058 0 ▶ $before = join( $ID_DELIMITER, grep { defined $_ && !ref( $_ ) } @{ $data->{rows}->[0]->{key} } );
Condition0%0/3
defined $_ && !ref($_)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && !ref($_)
defined $_ !ref($_)
Truth table0%0/3
A && not(B)
A= defined $_B= !ref($_)
ABresult
0X0
100
111
1059 0 ▶ $after = join( $ID_DELIMITER, grep { defined $_ && !ref( $_ ) } @{ $data->{rows}->[-1]->{key} } );
Condition0%0/3
defined $_ && !ref($_)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && !ref($_)
defined $_ !ref($_)
Truth table0%0/3
A && not(B)
A= defined $_B= !ref($_)
ABresult
0X0
100
111
1060 }
1061  
1062 0 return ( $before, $after, $previous, $next, \@rows, $data->{total_rows}, $data->{offset} );
1063 }
1064  
1065 =item HandleResponseKey
1066  
1067 =cut
1068  
1069 0 ▶sub HandleResponseKey {
Subroutine HandleResponseKey: not called CC=12 SCAR=50.5
Pod documented
1070 0 my ( $self, $cv ) = @_;
1071  
1072 0 ▶ unless ( blessed $cv and $cv->can( 'recv' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($cv) and $cv->can("recv")) 0 0 0
Condition0%0/3
builtin::blessed($cv) and $cv->can("recv")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($cv) and $cv->can("recv")
builtin::blessed($cv) $cv->can("recv")
Truth table0%0/3
A and B
A= builtin::blessed($cv)B= $cv->can("recv")
ABresult
0X0
100
111
1073 0 die 'cv is not object';
1074 }
1075  
1076 0 my $data = $cv->recv;
1077  
1078 0 ▶ unless ( ref( $data ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data eq "HASH") 0 0 0
1079 0 die 'data is not HASH';
1080 }
1081 0 foreach ( qw(rows) ) {
1082 0 ▶ unless ( defined $data->{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data->{$_}) 0 0 0
1083 0 die 'data->' . $_ . ' is not defined';
1084 }
1085 }
1086 0 ▶ unless ( ref( $data->{rows} ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data->{"rows"} eq "ARRAY") 0 0 0
1087 0 die 'data->rows is not ARRAY';
1088 }
1089  
1090 0 my @rows;
1091  
1092 0 foreach ( @{ $data->{rows} } ) {
1093 0 ▶ unless ( ref( $_ ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ eq "HASH") 0 0 0
1094 0 die 'data->rows[] entry is not HASH';
1095 }
1096 0 ▶ if ( exists $_->{doc} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $_->{'doc'}) { } 0 0 0
elsif (ref $_->{'key'} eq 'ARRAY') { } 0 0 0
1097 0 ▶ unless ( ref( $_->{doc} ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_->{"doc"} eq "HASH") 0 0 0
1098 0 die 'data->rows[]->doc is not HASH';
1099 }
1100 0 push( @rows, $_->{doc} );
1101 }
1102 elsif ( ref( $_->{key} ) eq 'ARRAY' ) {
1103 0 push( @rows, [ grep { defined $_ } @{ $_->{key} } ] );
1104 }
1105 else {
1106 0 push( @rows, $_->{key} );
1107 }
1108 }
1109  
1110 0 return \@rows;
1111 }
1112  
1113 =item HandleResponseId
1114  
1115 =cut
1116  
1117 0 ▶sub HandleResponseId {
Subroutine HandleResponseId: not called CC=10 SCAR=47.0
Pod documented
1118 0 my ( $self, $cv ) = @_;
1119  
1120 0 ▶ unless ( blessed $cv and $cv->can( 'recv' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($cv) and $cv->can("recv")) 0 0 0
Condition0%0/3
builtin::blessed($cv) and $cv->can("recv")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($cv) and $cv->can("recv")
builtin::blessed($cv) $cv->can("recv")
Truth table0%0/3
A and B
A= builtin::blessed($cv)B= $cv->can("recv")
ABresult
0X0
100
111
1121 0 die 'cv is not object';
1122 }
1123  
1124 0 my $data = $cv->recv;
1125  
1126 0 ▶ unless ( ref( $data ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data eq "HASH") 0 0 0
1127 0 die 'data is not HASH';
1128 }
1129 0 foreach ( qw(rows) ) {
1130 0 ▶ unless ( defined $data->{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data->{$_}) 0 0 0
1131 0 die 'data->' . $_ . ' is not defined';
1132 }
1133 }
1134 0 ▶ unless ( ref( $data->{rows} ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data->{"rows"} eq "ARRAY") 0 0 0
1135 0 die 'data->rows is not ARRAY';
1136 }
1137  
1138 0 my @rows;
1139  
1140 0 foreach ( @{ $data->{rows} } ) {
1141 0 ▶ unless ( ref( $_ ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ eq "HASH") 0 0 0
1142 0 die 'data->rows[] entry is not HASH';
1143 }
1144 0 ▶ unless ( defined $_->{id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_->{"id"}) 0 0 0
1145 0 die 'data->rows[]->id is not defined';
1146 }
1147 0 push( @rows, $_->{id} );
1148 }
1149  
1150 0 return \@rows;
1151 }
1152  
1153 =item HandleResponseIdRev
1154  
1155 =cut
1156  
1157 0 ▶sub HandleResponseIdRev {
Subroutine HandleResponseIdRev: not called CC=12 SCAR=50.5
Pod documented
1158 0 my ( $self, $cv ) = @_;
1159  
1160 0 ▶ unless ( blessed $cv and $cv->can( 'recv' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($cv) and $cv->can("recv")) 0 0 0
Condition0%0/3
builtin::blessed($cv) and $cv->can("recv")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($cv) and $cv->can("recv")
builtin::blessed($cv) $cv->can("recv")
Truth table0%0/3
A and B
A= builtin::blessed($cv)B= $cv->can("recv")
ABresult
0X0
100
111
1161 0 die 'cv is not object';
1162 }
1163  
1164 0 my $data = $cv->recv;
1165  
1166 0 ▶ unless ( ref( $data ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data eq "HASH") 0 0 0
1167 0 die 'data is not HASH';
1168 }
1169 0 foreach ( qw(rows) ) {
1170 0 ▶ unless ( defined $data->{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data->{$_}) 0 0 0
1171 0 die 'data->' . $_ . ' is not defined';
1172 }
1173 }
1174 0 ▶ unless ( ref( $data->{rows} ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data->{"rows"} eq "ARRAY") 0 0 0
1175 0 die 'data->rows is not ARRAY';
1176 }
1177  
1178 0 my @rows;
1179  
1180 0 foreach ( @{ $data->{rows} } ) {
1181 0 ▶ unless ( ref( $_ ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ eq "HASH") 0 0 0
1182 0 die 'data->rows[] entry is not HASH';
1183 }
1184 0 ▶ unless ( ref( $_->{doc} ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_->{"doc"} eq "HASH") 0 0 0
1185 0 die 'data->rows[]->doc is not HASH';
1186 }
1187 0 ▶ unless ( defined $_->{doc}->{_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_->{"doc"}{"_id"}) 0 0 0
1188 0 die 'data->rows[]->doc->_id is not defined';
1189 }
1190 0 ▶ unless ( defined $_->{doc}->{_rev} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_->{"doc"}{"_rev"}) 0 0 0
1191 0 die 'data->rows[]->doc->_rev is not defined';
1192 }
1193 0 push( @rows, { _id => $_->{doc}->{_id}, _rev => $_->{doc}->{_rev} } );
1194 }
1195  
1196 0 return \@rows;
1197 }
1198  
1199 =item HandleResponseBulk
1200  
1201 =cut
1202  
1203 0 ▶sub HandleResponseBulk {
Subroutine HandleResponseBulk: not called CC=15 SCAR=54.8
Pod documented
1204 0 my ( $self, $cv ) = @_;
1205  
1206 0 ▶ unless ( blessed $cv and $cv->can( 'recv' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($cv) and $cv->can("recv")) 0 0 0
Condition0%0/3
builtin::blessed($cv) and $cv->can("recv")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($cv) and $cv->can("recv")
builtin::blessed($cv) $cv->can("recv")
Truth table0%0/3
A and B
A= builtin::blessed($cv)B= $cv->can("recv")
ABresult
0X0
100
111
1207 0 die 'cv is not object';
1208 }
1209  
1210 0 my $data = $cv->recv;
1211  
1212 0 ▶ unless ( ref( $data ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data eq "ARRAY") 0 0 0
1213 0 die 'data is not ARRAY';
1214 }
1215  
1216 0 foreach ( @$data ) {
1217 0 ▶ unless ( ref( $_ ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ eq "HASH") 0 0 0
1218 0 die 'data[] is not HASH';
1219 }
1220 0 ▶ unless ( defined $_->{id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_->{"id"}) 0 0 0
1221 0 die 'data[]->id is not defined';
1222 }
1223 0 ▶ if ( exists $_->{rev} and exists $_->{ok} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $_->{'rev'} and exists $_->{'ok'}) { } 0 0 0
elsif (exists $_->{'error'} and exists $_->{'reason'}) { } 0 0 0
Condition0%0/3
exists $_->{"rev"} and exists $_->{"ok"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $_->{"rev"} and exists $_->{"ok"}
exists $_->{"rev"} exists $_->{"ok"}
Truth table0%0/3
A and B
A= exists $_->{"rev"}B= exists $_->{"ok"}
ABresult
0X0
100
111
1224 0 ▶ unless ( defined $_->{rev} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_->{"rev"}) 0 0 0
1225 0 die 'data[]->rev is not defined';
1226 }
1227 0 ▶ unless ( defined $_->{ok} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_->{"ok"}) 0 0 0
1228 0 die 'data[]->ok is not defined';
1229 }
1230 }
1231 ▶ elsif ( exists $_->{error} and exists $_->{reason} ) {
Condition0%0/3
exists $_->{"error"} and exists $_->{"reason"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $_->{"error"} and exists $_->{"reason"}
exists $_->{"error"} exists $_->{"reason"}
Truth table0%0/3
A and B
A= exists $_->{"error"}B= exists $_->{"reason"}
ABresult
0X0
100
111
1232 0 ▶ unless ( defined $_->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_->{"error"}) 0 0 0
1233 0 die 'data[]->error is not defined';
1234 }
1235 0 ▶ unless ( defined $_->{reason} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_->{"reason"}) 0 0 0
1236 0 die 'data[]->reason is not defined';
1237 }
1238 }
1239 else {
1240 0 die 'data[] missing rev/id or error/reason';
1241 }
1242 }
1243  
1244 0 return $data;
1245 }
1246  
1247 =back
1248  
1249 =head1 AUTHOR
1250  
1251 Jerry Lundström, C<< <lundstrom.jerry@gmail.com> >>
1252  
1253 =head1 BUGS
1254  
1255 Please report any bugs or feature requests to L<https://github.com/jelu/lim-plugin-zonalizer/issues>.
1256  
1257 =head1 SUPPORT
1258  
1259 You can find documentation for this module with the perldoc command.
1260  
1261 perldoc Lim::Plugin::Zonalizer::DB::CouchDB
1262  
1263 You can also look for information at:
1264  
1265 =over 4
1266  
1267 =item * Lim issue tracker (report bugs here)
1268  
1269 L<https://github.com/jelu/lim-plugin-zonalizer/issues>
1270  
1271 =back
1272  
1273 =head1 ACKNOWLEDGEMENTS
1274  
1275 =head1 LICENSE AND COPYRIGHT
1276  
1277 Copyright 2015-2016 Jerry Lundström
1278 Copyright 2015-2016 IIS (The Internet Foundation in Sweden)
1279  
1280 This program is free software; you can redistribute it and/or modify it
1281 under the terms of either: the GNU General Public License as published
1282 by the Free Software Foundation; or the Artistic License.
1283  
1284 See http://dev.perl.org/licenses/ for more information.
1285  
1286  
1287 =cut
1288  
1289 1 1; # End of Lim::Plugin::Zonalizer::DB::CouchDB
« Zonalizer/DB.pm ↑ Summary Zonalizer/DB/Memory.pm »