line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2014 - present MongoDB, Inc. |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
4
|
|
|
|
|
|
|
# you may not use this file except in compliance with the License. |
5
|
|
|
|
|
|
|
# You may obtain a copy of the License at |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software |
10
|
|
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
11
|
|
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12
|
|
|
|
|
|
|
# See the License for the specific language governing permissions and |
13
|
|
|
|
|
|
|
# limitations under the License. |
14
|
|
|
|
|
|
|
|
15
|
59
|
|
|
59
|
|
341
|
use strict; |
|
59
|
|
|
|
|
114
|
|
|
59
|
|
|
|
|
1575
|
|
16
|
59
|
|
|
59
|
|
296
|
use warnings; |
|
59
|
|
|
|
|
109
|
|
|
59
|
|
|
|
|
1758
|
|
17
|
|
|
|
|
|
|
package MongoDB::QueryResult::Filtered; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# ABSTRACT: An iterator for Mongo query results with client-side filtering |
20
|
|
|
|
|
|
|
|
21
|
59
|
|
|
59
|
|
293
|
use version; |
|
59
|
|
|
|
|
102
|
|
|
59
|
|
|
|
|
317
|
|
22
|
|
|
|
|
|
|
our $VERSION = 'v2.2.2'; |
23
|
|
|
|
|
|
|
|
24
|
59
|
|
|
59
|
|
3913
|
use Moo; |
|
59
|
|
|
|
|
136
|
|
|
59
|
|
|
|
|
280
|
|
25
|
59
|
|
|
|
|
531
|
use Types::Standard qw( |
26
|
|
|
|
|
|
|
CodeRef |
27
|
59
|
|
|
59
|
|
16298
|
); |
|
59
|
|
|
|
|
132
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
extends 'MongoDB::QueryResult'; |
30
|
|
|
|
|
|
|
|
31
|
59
|
|
|
59
|
|
32077
|
use namespace::clean; |
|
59
|
|
|
|
|
153
|
|
|
59
|
|
|
|
|
407
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# N.B.: _post_filter may also munge documents in addition to filtering; |
34
|
|
|
|
|
|
|
# it *must* be run on all documents |
35
|
|
|
|
|
|
|
has _post_filter => ( |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
isa => CodeRef, |
38
|
|
|
|
|
|
|
required => 1, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub has_next { |
42
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
43
|
0
|
|
|
|
|
|
my $limit = $self->_limit; |
44
|
0
|
0
|
0
|
|
|
|
if ( $limit > 0 && ( $self->cursor_at + 1 ) > $limit ) { |
45
|
0
|
|
|
|
|
|
$self->_kill_cursor; |
46
|
0
|
|
|
|
|
|
return 0; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
0
|
|
|
|
while ( !$self->_drained || $self->_get_more ) { |
49
|
0
|
|
|
|
|
|
my $peek = $self->_docs->[0]; |
50
|
0
|
0
|
|
|
|
|
if ( $self->_post_filter->($peek) ) { |
51
|
|
|
|
|
|
|
# if meets criteria, has_next is true |
52
|
0
|
|
|
|
|
|
return 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
|
|
|
|
|
|
# otherwise throw it away and repeat |
56
|
0
|
|
|
|
|
|
$self->_inc_cursor_at; |
57
|
0
|
|
|
|
|
|
$self->_next_doc; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
# ran out of docs, so nothing left |
61
|
0
|
|
|
|
|
|
return 0; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub all { |
65
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
66
|
0
|
|
|
|
|
|
my @ret; |
67
|
0
|
|
|
|
|
|
push @ret, grep { $self->_post_filter->($_) } $self->_drain_docs |
|
0
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
while $self->has_next; |
69
|
0
|
|
|
|
|
|
return @ret; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |