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 58     58   196653 use strict;
  58         156  
  58         2012  
16 58     58   335 use warnings;
  58         134  
  58         2438  
17             package MongoDB::Role::_CommandCursorOp;
18              
19             # MongoDB interface for database commands with cursors
20              
21 58     58   337 use version;
  58         173  
  58         407  
22             our $VERSION = 'v2.2.0';
23              
24 58     58   4620 use Moo::Role;
  58         135  
  58         442  
25              
26 58     58   21281 use MongoDB::Error;
  58         193  
  58         7037  
27 58     58   456 use MongoDB::QueryResult;
  58         160  
  58         1706  
28              
29 58     58   367 use namespace::clean;
  58         162  
  58         493  
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;