File Coverage

blib/lib/Catmandu/Store/MongoDB/Searcher.pm
Criterion Covered Total %
statement 9 24 37.5
branch 0 6 0.0
condition 0 2 0.0
subroutine 3 7 42.8
pod 0 3 0.0
total 12 42 28.5


line stmt bran cond sub pod time code
1             package Catmandu::Store::MongoDB::Searcher;
2              
3 3     3   19 use Catmandu::Sane;
  3         5  
  3         16  
4              
5             our $VERSION = '0.0803';
6              
7 3     3   467 use Moo;
  3         6  
  3         15  
8 3     3   884 use namespace::clean;
  3         23  
  3         25  
9              
10             with 'Catmandu::Iterable';
11              
12             has bag => (is => 'ro', required => 1);
13             has query => (is => 'ro', required => 1);
14             has start => (is => 'ro', required => 1);
15             has limit => (is => 'ro', required => 1);
16             has total => (is => 'ro');
17             has sort => (is => 'ro');
18             has fields => (is => 'ro');
19              
20             sub generator {
21 0     0 0   my ($self) = @_;
22             sub {
23 0     0     state $cursor = do {
24 0           my $c = $self->bag->_cursor($self->query);
25 0 0         $c->fields($self->fields) if defined $self->fields;
26              
27             # limit is unused because the perl driver doesn't expose batchSize
28 0 0         $c->limit($self->total) if defined $self->total;
29 0 0         $c->sort($self->sort) if defined $self->sort;
30 0           $c->immortal(1);
31 0           $c;
32             };
33 0           $cursor->next;
34 0           };
35             }
36              
37             sub slice { # TODO constrain total?
38 0     0 0   my ($self, $start, $total) = @_;
39 0   0       $start //= 0;
40 0           $self->new(
41             bag => $self->bag,
42             query => $self->query,
43             start => $self->start + $start,
44             limit => $self->limit,
45             total => $total,
46             sort => $self->sort,
47             fields => $self->fields,
48             );
49             }
50              
51             sub count { # TODO constrain on start, total?
52 0     0 0   my ($self) = @_;
53 0           $self->bag->collection->count_documents($self->query,
54             $self->bag->_options);
55             }
56              
57             1;