MongoDB/Cursor.pm

filter: Statementstmt 36.6% 48 / 131 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 40.0% 14 / 35 Podpod 95.0% 19 / 20 totaltotal 32.2% 81 / 251 CC 30 SCAR 24.0
CC
30
Cov
25%
read_preference
30.0
fields
20.0
max_await_time_ms
20.0
CRAP 11.0
« MongoDB/_TransactionOptions.pm ↑ Summary MongoDB/Op/_EndTxn.pm »
1 # Copyright 2009 - 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::Cursor;
18  
19  
20 # ABSTRACT: A lazy cursor for Mongo query results
21  
22 59 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 59 our $VERSION = 'v2.2.2';
24  
25 59 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 59 ▶use MongoDB::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 59 ▶use MongoDB::QueryResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 59 ▶use MongoDB::ReadPreference;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 59 ▶use MongoDB::_Protocol;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 59 ▶use MongoDB::Op::_Explain;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 59 ▶use MongoDB::_Types -types, qw/to_IxHash is_OrderedDoc/;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 59 ▶use Types::Standard qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
33 InstanceOf
34 is_Str
35 59 );
36 59 ▶use boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 59 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 59 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 #pod =attr started_iterating
41 #pod
42 #pod A boolean indicating if this cursor has queried the database yet. Methods
43 #pod modifying the query will complain if they are called after the database is
44 #pod queried.
45 #pod
46 #pod =cut
47  
48 59 with $_ for qw(
49 MongoDB::Role::_CursorAPI
50 MongoDB::Role::_DeprecationWarner
51 );
52  
53 # attributes for sending a query
54 59 has client => (
55 is => 'ro',
56 required => 1,
57 isa => InstanceOf ['MongoDB::MongoClient'],
58 );
59  
60 59 has _query => (
61 is => 'ro',
62 isa => InstanceOf['MongoDB::Op::_Query'],
63 required => 1,
64 init_arg => 'query',
65 );
66  
67 # lazy result attribute
68 59 has result => (
69 is => 'lazy',
70 isa => InstanceOf['MongoDB::QueryResult'],
71 builder => '_build_result',
72 predicate => 'started_iterating',
73 clearer => '_clear_result',
74 );
75  
76 # this does the query if it hasn't been done yet
77 0 ▶sub _build_result {
Subroutine _build_result: not called CC=1 SCAR=6.9
78 0 my ($self) = @_;
79  
80 0 return $self->{client}->send_retryable_read_op( $self->_query );
81 }
82  
83 #--------------------------------------------------------------------------#
84 # methods that modify the query
85 #--------------------------------------------------------------------------#
86  
87 #pod =head1 QUERY MODIFIERS
88 #pod
89 #pod These methods modify the query to be run. An exception will be thrown if
90 #pod they are called after results are iterated.
91 #pod
92 #pod =head2 immortal
93 #pod
94 #pod $cursor->immortal(1);
95 #pod
96 #pod Ordinarily, a cursor "dies" on the database server after a certain length of
97 #pod time (approximately 10 minutes), to prevent inactive cursors from hogging
98 #pod resources. This option indicates that a cursor should not die until all of its
99 #pod results have been fetched or it goes out of scope in Perl.
100 #pod
101 #pod Boolean value, defaults to 0.
102 #pod
103 #pod Note: C<immortal> only affects the server-side timeout. If you are getting
104 #pod client-side timeouts you will need to change your client configuration.
105 #pod See L<MongoDB::MongoClient/max_time_ms> and
106 #pod L<MongoDB::MongoClient/socket_timeout_ms>.
107 #pod
108 #pod Returns this cursor for chaining operations.
109 #pod
110 #pod =cut
111  
112 0 ▶sub immortal {
Subroutine immortal: not called CC=2 SCAR=17.9
Pod documented
113 0 my ( $self, $bool ) = @_;
114 0 ▶ MongoDB::UsageError->throw("cannot set immortal after querying")
Branch: 1 branch
BranchTrueFalseTotal
if $self->started_iterating 0 0 0
115 if $self->started_iterating;
116  
117 0 $self->_query->set_noCursorTimeout($bool);
118 0 return $self;
119 }
120  
121 #pod =head2 fields
122 #pod
123 #pod $coll->insert({name => "Fred", age => 20});
124 #pod my $cursor = $coll->find->fields({ name => 1 });
125 #pod my $obj = $cursor->next;
126 #pod $obj->{name}; "Fred"
127 #pod $obj->{age}; # undef
128 #pod
129 #pod Selects which fields are returned. The default is all fields. When fields
130 #pod are specified, _id is returned by default, but this can be disabled by
131 #pod explicitly setting it to "0". E.g. C<< _id => 0 >>. Argument must be either a
132 #pod hash reference or a L<Tie::IxHash> object.
133 #pod
134 #pod See L<Limit fields to
135 #pod return|http://docs.mongodb.org/manual/tutorial/project-fields-from-query-results/>
136 #pod in the MongoDB documentation for details.
137 #pod
138 #pod Returns this cursor for chaining operations.
139 #pod
140 #pod =cut
141  
142 0 ▶sub fields {
Subroutine fields: not called CC=4 SCAR=30.0
Pod documented
143 0 my ($self, $f) = @_;
144 0 ▶ MongoDB::UsageError->throw("cannot set fields after querying")
Branch: 1 branch
BranchTrueFalseTotal
if $self->started_iterating 0 0 0
145 if $self->started_iterating;
146 0 ▶ MongoDB::UsageError->throw("not a hash reference")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $f eq "HASH" or ref $f eq "Tie::IxHash" 0 0 0
Condition0%0/3
ref $f eq "HASH" or ref $f eq "Tie::IxHash"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $f eq "HASH" or ref $f eq "Tie::IxHash"
ref $f eq "HASH" ref $f eq "Tie::IxHash"
Truth table0%0/3
A or B
A= ref $f eq "HASH"B= ref $f eq "Tie::IxHash"
ABresult
1X1
011
000
147 unless ref $f eq 'HASH' || ref $f eq 'Tie::IxHash';
148  
149 0 $self->_query->set_projection($f);
150 0 return $self;
151 }
152  
153 #pod =head2 sort
154 #pod
155 #pod # sort by name, descending
156 #pod $cursor->sort([name => -1]);
157 #pod
158 #pod Adds a sort to the query. Argument is either a hash reference or a
159 #pod L<Tie::IxHash> or an array reference of key/value pairs. Because hash
160 #pod references are not ordered, do not use them for more than one key.
161 #pod
162 #pod Returns this cursor for chaining operations.
163 #pod
164 #pod =cut
165  
166 0 ▶sub sort {
Subroutine sort: not called CC=2 SCAR=17.9
Pod documented
167 0 my ( $self, $order ) = @_;
168 0 ▶ MongoDB::UsageError->throw("cannot set sort after querying")
Branch: 1 branch
BranchTrueFalseTotal
if $self->started_iterating 0 0 0
169 if $self->started_iterating;
170  
171 0 $self->_query->set_sort($order);
172 0 return $self;
173 }
174  
175  
176 #pod =head2 limit
177 #pod
178 #pod $cursor->limit(20);
179 #pod
180 #pod Sets cursor to return a maximum of N results.
181 #pod
182 #pod Returns this cursor for chaining operations.
183 #pod
184 #pod =cut
185  
186 0 ▶sub limit {
Subroutine limit: not called CC=2 SCAR=17.9
Pod documented
187 0 my ( $self, $num ) = @_;
188 0 ▶ MongoDB::UsageError->throw("cannot set limit after querying")
Branch: 1 branch
BranchTrueFalseTotal
if $self->started_iterating 0 0 0
189 if $self->started_iterating;
190 0 $self->_query->set_limit($num);
191 0 return $self;
192 }
193  
194  
195 #pod =head2 max_await_time_ms
196 #pod
197 #pod $cursor->max_await_time_ms( 500 );
198 #pod
199 #pod The maximum amount of time in milliseconds for the server to wait on new
200 #pod documents to satisfy a tailable cursor query. This only applies to a
201 #pod cursor of type 'tailble_await'. This is ignored if the cursor is not
202 #pod a 'tailable_await' cursor or the server version is less than version 3.2.
203 #pod
204 #pod Returns this cursor for chaining operations.
205 #pod
206 #pod =cut
207  
208 0 ▶sub max_await_time_ms {
Subroutine max_await_time_ms: not called CC=4 SCAR=30.0
Pod documented
209 0 my ( $self, $num ) = @_;
210 0 ▶ $num = 0 unless defined $num;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 0 0 0
211 0 ▶ MongoDB::UsageError->throw("max_await_time_ms must be non-negative")
Branch: 1 branch
BranchTrueFalseTotal
if $num < 0 0 0 0
212 if $num < 0;
213 0 ▶ MongoDB::UsageError->throw("can not set max_await_time_ms after querying")
Branch: 1 branch
BranchTrueFalseTotal
if $self->started_iterating 0 0 0
214 if $self->started_iterating;
215  
216 0 $self->_query->set_maxAwaitTimeMS( $num );
217 0 return $self;
218 }
219  
220 #pod =head2 max_time_ms
221 #pod
222 #pod $cursor->max_time_ms( 500 );
223 #pod
224 #pod Causes the server to abort the operation if the specified time in milliseconds
225 #pod is exceeded.
226 #pod
227 #pod Returns this cursor for chaining operations.
228 #pod
229 #pod =cut
230  
231 0 ▶sub max_time_ms {
Subroutine max_time_ms: not called CC=4 SCAR=30.0
Pod documented
232 0 my ( $self, $num ) = @_;
233 0 ▶ $num = 0 unless defined $num;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 0 0 0
234 0 ▶ MongoDB::UsageError->throw("max_time_ms must be non-negative")
Branch: 1 branch
BranchTrueFalseTotal
if $num < 0 0 0 0
235 if $num < 0;
236 0 ▶ MongoDB::UsageError->throw("can not set max_time_ms after querying")
Branch: 1 branch
BranchTrueFalseTotal
if $self->started_iterating 0 0 0
237 if $self->started_iterating;
238  
239 0 $self->_query->set_maxTimeMS( $num );
240 0 return $self;
241  
242 }
243  
244 #pod =head2 tailable
245 #pod
246 #pod $cursor->tailable(1);
247 #pod
248 #pod If a cursor should be tailable. Tailable cursors can only be used on capped
249 #pod collections and are similar to the C<tail -f> command: they never die and keep
250 #pod returning new results as more is added to a collection.
251 #pod
252 #pod They are often used for getting log messages.
253 #pod
254 #pod Boolean value, defaults to 0.
255 #pod
256 #pod If you want the tailable cursor to block for a few seconds, use
257 #pod L</tailable_await> instead. B<Note> calling this with a false value
258 #pod disables tailing, even if C<tailable_await> was previously called.
259 #pod
260 #pod Returns this cursor for chaining operations.
261 #pod
262 #pod =cut
263  
264 0 ▶sub tailable {
Subroutine tailable: not called CC=3 SCAR=24.8
Pod documented
265 0 my ( $self, $bool ) = @_;
266 0 ▶ MongoDB::UsageError->throw("cannot set tailable after querying")
Branch: 1 branch
BranchTrueFalseTotal
if $self->started_iterating 0 0 0
267 if $self->started_iterating;
268  
269 0 ▶ $self->_query->set_cursorType($bool ? 'tailable' : 'non_tailable');
Branch: 1 branch
BranchTrueFalseTotal
$bool ? : 0 0 0
270 0 return $self;
271 }
272  
273 #pod =head2 tailable_await
274 #pod
275 #pod $cursor->tailable_await(1);
276 #pod
277 #pod Sets a cursor to be tailable and block for a few seconds if no data
278 #pod is immediately available.
279 #pod
280 #pod Boolean value, defaults to 0.
281 #pod
282 #pod If you want the tailable cursor without blocking, use L</tailable> instead.
283 #pod B<Note> calling this with a false value disables tailing, even if C<tailable>
284 #pod was previously called.
285 #pod
286 #pod =cut
287  
288 0 ▶sub tailable_await {
Subroutine tailable_await: not called CC=3 SCAR=24.8
Pod documented
289 0 my ( $self, $bool ) = @_;
290 0 ▶ MongoDB::UsageError->throw("cannot set tailable_await after querying")
Branch: 1 branch
BranchTrueFalseTotal
if $self->started_iterating 0 0 0
291 if $self->started_iterating;
292  
293 0 ▶ $self->_query->set_cursorType($bool ? 'tailable_await' : 'non_tailable');
Branch: 1 branch
BranchTrueFalseTotal
$bool ? : 0 0 0
294 0 return $self;
295 }
296  
297 #pod =head2 skip
298 #pod
299 #pod $cursor->skip( 50 );
300 #pod
301 #pod Skips the first N results.
302 #pod
303 #pod Returns this cursor for chaining operations.
304 #pod
305 #pod =cut
306  
307 0 ▶sub skip {
Subroutine skip: not called CC=3 SCAR=24.8
Pod documented
308 0 my ( $self, $num ) = @_;
309 0 ▶ MongoDB::UsageError->throw("skip must be non-negative")
Branch: 1 branch
BranchTrueFalseTotal
if $num < 0 0 0 0
310 if $num < 0;
311 0 ▶ MongoDB::UsageError->throw("cannot set skip after querying")
Branch: 1 branch
BranchTrueFalseTotal
if $self->started_iterating 0 0 0
312 if $self->started_iterating;
313  
314 0 $self->_query->set_skip($num);
315 0 return $self;
316 }
317  
318 #pod =head2 hint
319 #pod
320 #pod Hint the query to use a specific index by name:
321 #pod
322 #pod $cursor->hint("index_name");
323 #pod
324 #pod Hint the query to use index based on individual keys and direction:
325 #pod
326 #pod $cursor->hint([field_1 => 1, field_2 => -1, field_3 => 1]);
327 #pod
328 #pod Use of a hash reference should be avoided except for single key indexes.
329 #pod
330 #pod The hint must be a string or L<ordered document|MongoDB::Collection/Ordered
331 #pod document>.
332 #pod
333 #pod Returns this cursor for chaining operations.
334 #pod
335 #pod =cut
336  
337 0 ▶sub hint {
Subroutine hint: not called CC=4 SCAR=30.0
Pod documented
338 0 my ( $self, $index ) = @_;
339 0 ▶ MongoDB::UsageError->throw("cannot set hint after querying")
Branch: 1 branch
BranchTrueFalseTotal
if $self->started_iterating 0 0 0
340 if $self->started_iterating;
341 0 ▶ MongoDB::UsageError->throw("hint must be string or ordered document, not '$index'")
Branch: 1 branch
BranchTrueFalseTotal
unless is_Str($index) or &is_OrderedDoc($index) 0 0 0
Condition0%0/3
is_Str($index) or &is_OrderedDoc($index)
l!l&&r!l&&!r
000
MC/DC0%0/2
is_Str($index) or &is_OrderedDoc($index)
is_Str($index) &is_OrderedDoc($index)
Truth table0%0/3
A or B
A= is_Str($index)B= &is_OrderedDoc($index)
ABresult
1X1
011
000
342 if ! (is_Str($index) || is_OrderedDoc($index));
343  
344 0 $self->_query->set_hint( $index );
345  
346 0 return $self;
347 }
348  
349 #pod =head2 partial
350 #pod
351 #pod $cursor->partial(1);
352 #pod
353 #pod If a shard is down, mongos will return an error when it tries to query that
354 #pod shard. If this is set, mongos will just skip that shard, instead.
355 #pod
356 #pod Boolean value, defaults to 0.
357 #pod
358 #pod Returns this cursor for chaining operations.
359 #pod
360 #pod =cut
361  
362 0 ▶sub partial {
Subroutine partial: not called CC=2 SCAR=17.9
Pod documented
363 0 my ($self, $value) = @_;
364 0 ▶ MongoDB::UsageError->throw("cannot set partial after querying")
Branch: 1 branch
BranchTrueFalseTotal
if $self->started_iterating 0 0 0
365 if $self->started_iterating;
366  
367 0 $self->_query->set_allowPartialResults( $value );
368  
369 # returning self is an API change but more consistent with other cursor methods
370 0 return $self;
371 }
372  
373 #pod =head2 read_preference
374 #pod
375 #pod $cursor->read_preference($read_preference_object);
376 #pod $cursor->read_preference('secondary', [{foo => 'bar'}]);
377 #pod
378 #pod Sets read preference for the cursor's connection.
379 #pod
380 #pod If given a single argument that is a L<MongoDB::ReadPreference> object, the
381 #pod read preference is set to that object. Otherwise, it takes positional
382 #pod arguments: the read preference mode and a tag set list, which must be a valid
383 #pod mode and tag set list as described in the L<MongoDB::ReadPreference>
384 #pod documentation.
385 #pod
386 #pod Returns this cursor for chaining operations.
387 #pod
388 #pod =cut
389  
390 0 ▶sub read_preference {
Subroutine read_preference: not called CC=5 SCAR=34.0
Pod documented
391 0 my $self = shift;
392 0 ▶ MongoDB::UsageError->throw("cannot set read preference after querying")
Branch: 1 branch
BranchTrueFalseTotal
if $self->started_iterating 0 0 0
393 if $self->started_iterating;
394  
395 0 my $type = ref $_[0];
396 0 ▶ if ( $type eq 'MongoDB::ReadPreference' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'MongoDB::ReadPreference') { } 0 0 0
397 0 $self->_query->read_preference( $_[0] );
398 }
399 else {
400 0 ▶ my $mode = shift || 'primary';
Condition0%0/2
shift() || 'primary'
l!l
00
MC/DC0%0/1
shift() || 'primary'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
401 0 my $tag_sets = shift;
402 0 ▶ my $rp = MongoDB::ReadPreference->new(
Branch: 1 branch
BranchTrueFalseTotal
$tag_sets ? : 0 0 0
403 mode => $mode,
404 ( $tag_sets ? ( tag_sets => $tag_sets ) : () )
405 );
406 0 $self->_query->read_preference($rp);
407 }
408  
409 0 return $self;
410 }
411  
412 #pod =head1 QUERY INTROSPECTION AND RESET
413 #pod
414 #pod These methods run introspection methods on the query conditions and modifiers
415 #pod stored within the cursor object.
416 #pod
417 #pod =head2 explain
418 #pod
419 #pod my $explanation = $cursor->explain;
420 #pod
421 #pod This will tell you the type of cursor used, the number of records the DB had to
422 #pod examine as part of this query, the number of records returned by the query, and
423 #pod the time in milliseconds the query took to execute.
424 #pod
425 #pod See also core documentation on explain:
426 #pod L<http://dochub.mongodb.org/core/explain>.
427 #pod
428 #pod =cut
429  
430 0 ▶sub explain {
Subroutine explain: not called CC=1 SCAR=6.9
Pod documented
431 0 my ($self) = @_;
432  
433 0 my $explain_op = MongoDB::Op::_Explain->_new(
434 db_name => $self->_query->db_name,
435 coll_name => $self->_query->coll_name,
436 full_name => $self->_query->full_name,
437 bson_codec => $self->_query->bson_codec,
438 query => $self->_query,
439 read_preference => $self->_query->read_preference,
440 read_concern => $self->_query->read_concern,
441 session => $self->_query->session,
442 monitoring_callback => $self->client->monitoring_callback,
443 );
444  
445 0 return $self->_query->client->send_retryable_read_op($explain_op);
446 }
447  
448 #pod =head1 QUERY ITERATION
449 #pod
450 #pod These methods allow you to iterate over results.
451 #pod
452 #pod =head2 result
453 #pod
454 #pod my $result = $cursor->result;
455 #pod
456 #pod This method will execute the query and return a L<MongoDB::QueryResult> object
457 #pod with the results.
458 #pod
459 #pod The C<has_next>, C<next>, and C<all> methods call C<result> internally,
460 #pod which executes the query "on demand".
461 #pod
462 #pod Iterating with a MongoDB::QueryResult object directly instead of a
463 #pod L<MongoDB::Cursor> will be slightly faster, since the L<MongoDB::Cursor>
464 #pod methods below just internally call the corresponding method on the result
465 #pod object.
466 #pod
467 #pod =cut
468  
469 #--------------------------------------------------------------------------#
470 # methods delgated to result object
471 #--------------------------------------------------------------------------#
472  
473 #pod =head2 has_next
474 #pod
475 #pod while ($cursor->has_next) {
476 #pod ...
477 #pod }
478 #pod
479 #pod Checks if there is another result to fetch. Will automatically fetch more
480 #pod data from the server if necessary.
481 #pod
482 #pod =cut
483  
484 0 ▶sub has_next { $_[0]->result->has_next }
Subroutine has_next: not called CC=1 SCAR=6.9
Pod documented
485  
486 #pod =head2 next
487 #pod
488 #pod while (my $object = $cursor->next) {
489 #pod ...
490 #pod }
491 #pod
492 #pod Returns the next object in the cursor. Will automatically fetch more data from
493 #pod the server if necessary. Returns undef if no more data is available.
494 #pod
495 #pod =cut
496  
497 0 ▶sub next { $_[0]->result->next }
Subroutine next: not called CC=1 SCAR=6.9
Pod documented
498  
499 #pod =head2 batch
500 #pod
501 #pod while (my @batch = $cursor->batch) {
502 #pod ...
503 #pod }
504 #pod
505 #pod Returns the next batch of data from the cursor. Will automatically fetch more
506 #pod data from the server if necessary. Returns an empty list if no more data is available.
507 #pod
508 #pod =cut
509  
510 0 ▶sub batch { $_[0]->result->batch }
Subroutine batch: not called CC=1 SCAR=6.9
Pod documented
511  
512 #pod =head2 all
513 #pod
514 #pod my @objects = $cursor->all;
515 #pod
516 #pod Returns a list of all objects in the result.
517 #pod
518 #pod =cut
519  
520 0 ▶sub all { $_[0]->result->all }
Subroutine all: not called CC=1 SCAR=6.9
Pod documented
521  
522 #pod =head2 reset
523 #pod
524 #pod Resets the cursor. After being reset, pre-query methods can be
525 #pod called on the cursor (sort, limit, etc.) and subsequent calls to
526 #pod result, next, has_next, or all will re-query the database.
527 #pod
528 #pod =cut
529  
530 0 ▶sub reset {
Subroutine reset: not called CC=1 SCAR=6.9
Pod documented
531 0 my ($self) = @_;
532 0 $self->_clear_result;
533 0 return $self;
534 }
535  
536 #pod =head2 info
537 #pod
538 #pod Returns a hash of information about this cursor. This is intended for
539 #pod debugging purposes and users should not rely on the contents of this method for
540 #pod production use. Currently the fields are:
541 #pod
542 #pod =for :list
543 #pod * C<cursor_id> -- the server-side id for this cursor. See below for details.
544 #pod * C<num> -- the number of results received from the server so far
545 #pod * C<at> -- the (zero-based) index of the document that will be returned next from L</next>
546 #pod * C<flag> -- if the database could not find the cursor or another error occurred, C<flag> may
547 #pod contain a hash reference of flags set in the response (depending on the error). See
548 #pod L<http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-OPREPLY>
549 #pod for a full list of flag values.
550 #pod * C<start> -- the index of the result that the current batch of results starts at.
551 #pod
552 #pod If the cursor has not yet executed, only the C<num> field will be returned with
553 #pod a value of 0.
554 #pod
555 #pod The C<cursor_id> could appear in one of three forms:
556 #pod
557 #pod =for :list
558 #pod * MongoDB::CursorID object (a blessed reference to an 8-byte string)
559 #pod * A perl scalar (an integer)
560 #pod * A Math::BigInt object (64 bit integer on 32-bit perl)
561 #pod
562 #pod When the C<cursor_id> is zero, there are no more results to fetch.
563 #pod
564 #pod =cut
565  
566 0 ▶sub info {
Subroutine info: not called CC=2 SCAR=17.9
Pod documented
567 0 my $self = shift;
568 0 ▶ if ( $self->started_iterating ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->started_iterating) { } 0 0 0
569 0 return $self->result->_info;
570 }
571 else {
572 0 return { num => 0 };
573 }
574 }
575  
576 #--------------------------------------------------------------------------#
577 # Deprecated methods
578 #--------------------------------------------------------------------------#
579  
580 0 ▶sub snapshot {
Subroutine snapshot: not called CC=3 SCAR=24.8
Pod undocumented
581 0 my ($self, $bool) = @_;
582  
583 0 $self->_warn_deprecated_method(
584 'snapshot' => "Snapshot is deprecated as of MongoDB 3.6" );
585  
586 0 ▶ MongoDB::UsageError->throw("cannot set snapshot after querying")
Branch: 1 branch
BranchTrueFalseTotal
if $self->started_iterating 0 0 0
587 if $self->started_iterating;
588  
589 0 ▶ MongoDB::UsageError->throw("snapshot requires a defined, boolean argument")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bool 0 0 0
590 unless defined $bool;
591  
592 0 $self->_query->set_snapshot($bool);
593 0 return $self;
594 }
595  
596 59 1;
597  
598  
599  
600 # vim: ts=4 sts=4 sw=4 et tw=75:
601  
602 __END__
« MongoDB/_TransactionOptions.pm ↑ Summary MongoDB/Op/_EndTxn.pm »