| 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 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 59 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | package MongoDB::QueryResult::Filtered; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # ABSTRACT: An iterator for Mongo query results with client-side filtering | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 59 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 59 | our $VERSION = 'v2.2.2'; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 59 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 59 | ▶ | use Types::Standard qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | CodeRef | ||||||||||||||||||||||||||||
| 27 | 59 | ); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 59 | extends 'MongoDB::QueryResult'; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 59 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # N.B.: _post_filter may also munge documents in addition to filtering; | ||||||||||||||||||||||||||||
| 34 | # it *must* be run on all documents | ||||||||||||||||||||||||||||
| 35 | 59 | has _post_filter => ( | |||||||||||||||||||||||||||
| 36 | is => 'ro', | ||||||||||||||||||||||||||||
| 37 | isa => CodeRef, | ||||||||||||||||||||||||||||
| 38 | required => 1, | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub has_next { | ||||||||||||||||||||||||||
|
Subroutine
has_next: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 43 | 0 | my $limit = $self->_limit; | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ( $limit > 0 && ( $self->cursor_at + 1 ) > $limit ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$limit > 0 and $self->cursor_at + 1 > $limit
MC/DC0%0/2
$limit > 0 and $self->cursor_at + 1 > $limit
$limit > 0
$self->cursor_at + 1 > $limit
Truth table0%0/3
A and B
A= $limit > 0B= $self->cursor_at + 1 > $limit
| |||||||||||||||||||||||||||||
| 45 | 0 | $self->_kill_cursor; | |||||||||||||||||||||||||||
| 46 | 0 | return 0; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | while ( !$self->_drained || $self->_get_more ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $self->_drained or $self->_get_more
MC/DC0%0/2
not $self->_drained or $self->_get_more
not $self->_drained
$self->_get_more
Truth table0%0/3
not(A) or B
A= not $self->_drainedB= $self->_get_more
| |||||||||||||||||||||||||||||
| 49 | 0 | my $peek = $self->_docs->[0]; | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ( $self->_post_filter->($peek) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub all { | ||||||||||||||||||||||||||
|
Subroutine
all: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 66 | 0 | my @ret; | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | push @ret, grep { $self->_post_filter->($_) } $self->_drain_docs | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | while $self->has_next; | ||||||||||||||||||||||||||||
| 69 | 0 | return @ret; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 59 | 1; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||