File Coverage

blib/lib/MongoDB/Role/_CommandCursorOp.pm
Criterion Covered Total %
statement 21 34 61.7
branch 0 14 0.0
condition 0 6 0.0
subroutine 7 9 77.7
pod n/a
total 28 63 44.4


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   199082 use strict;
  59         162  
  59         1947  
16 59     59   327 use warnings;
  59         146  
  59         2410  
17             package MongoDB::Role::_CommandCursorOp;
18              
19             # MongoDB interface for database commands with cursors
20              
21 59     59   329 use version;
  59         137  
  59         415  
22             our $VERSION = 'v2.2.1';
23              
24 59     59   4683 use Moo::Role;
  59         138  
  59         445  
25              
26 59     59   21568 use MongoDB::Error;
  59         171  
  59         7024  
27 59     59   445 use MongoDB::QueryResult;
  59         145  
  59         1590  
28              
29 59     59   344 use namespace::clean;
  59         150  
  59         416  
30              
31             requires qw/session client bson_codec/;
32              
33             sub _build_result_from_cursor {
34 0     0     my ( $self, $res ) = @_;
35              
36             my $c = $res->output->{cursor}
37 0 0         or MongoDB::DatabaseError->throw(
38             message => "no cursor found in command response",
39             result => $res,
40             );
41              
42 0           my $max_time_ms = 0;
43 0 0 0       if ($self->isa('MongoDB::Op::_Query') &&
    0 0        
44             $self->options->{cursorType} eq 'tailable_await') {
45 0 0         $max_time_ms = $self->options->{maxAwaitTimeMS} if $self->options->{maxAwaitTimeMS};
46             }
47             elsif (
48             $self->isa('MongoDB::Op::_Aggregate') ||
49             $self->isa('MongoDB::Op::_ChangeStream')
50             ) {
51 0 0         $max_time_ms = $self->maxAwaitTimeMS if $self->maxAwaitTimeMS;
52             }
53              
54 0           my $limit = 0;
55 0 0         if ($self->isa('MongoDB::Op::_Query')) {
56 0 0         $limit = $self->options->{limit} if $self->options->{limit};
57             }
58              
59 0           my $batch = $c->{firstBatch};
60             my $qr = MongoDB::QueryResult->_new(
61             _client => $self->client,
62             _address => $res->address,
63             _full_name => $c->{ns},
64             _bson_codec => $self->bson_codec,
65             _batch_size => scalar @$batch,
66             _cursor_at => 0,
67             _limit => $limit,
68             _cursor_id => $c->{id},
69             _cursor_start => 0,
70             _cursor_flags => {},
71             _cursor_num => scalar @$batch,
72             _docs => $batch,
73             _max_time_ms => $max_time_ms,
74             _session => $self->session,
75             _post_batch_resume_token => $c->{postBatchResumeToken},
76 0           );
77             }
78              
79             sub _empty_query_result {
80 0     0     my ( $self, $link ) = @_;
81              
82 0           my $qr = MongoDB::QueryResult->_new(
83             _client => $self->client,
84             _address => $link->address,
85             _full_name => '',
86             _bson_codec => $self->bson_codec,
87             _batch_size => 1,
88             _cursor_at => 0,
89             _limit => 0,
90             _cursor_id => 0,
91             _cursor_start => 0,
92             _cursor_flags => {},
93             _cursor_num => 0,
94             _docs => [],
95             );
96             }
97              
98             1;