MongoDB/Op/_FindAndUpdate.pm

filter: Statementstmt 65.3% 34 / 52 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 1 totaltotal 51.8% 43 / 83 CC 9 SCAR 38.2
CC
9
Cov
49%
execute
90.0
BEGIN
1.0
BEGIN
1.0
CRAP 45.5
« MongoDB/Op/_FindAndDelete.pm ↑ Summary MongoDB/BulkWriteView.pm »
1 # Copyright 2015 - 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::Op::_FindAndUpdate;
18  
19 # Encapsulate find_and_update operation; atomically update and return doc
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  
26 59 ▶use MongoDB::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 59 ▶use MongoDB::Op::_Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 59 ▶use Types::Standard qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
29 HashRef
30 59 );
31 59 ▶use MongoDB::_Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
32 Boolish
33 59 );
34 59 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 59 has filter => (
37 is => 'ro',
38 required => 1,
39 isa => HashRef,
40 );
41  
42 59 has modifier => (
43 is => 'ro',
44 required => 1,
45 );
46  
47 59 has options => (
48 is => 'ro',
49 required => 1,
50 isa => HashRef,
51 );
52  
53 59 has is_replace => (
54 is => 'ro',
55 required => 1,
56 isa => Boolish,
57 );
58  
59 59 with $_ for qw(
60 MongoDB::Role::_PrivateConstructor
61 MongoDB::Role::_CollectionOp
62 MongoDB::Role::_WriteOp
63 MongoDB::Role::_BypassValidation
64 MongoDB::Role::_UpdatePreEncoder
65 );
66  
67 0 ▶sub execute {
Subroutine execute: not called CC=9 SCAR=45.0
Pod undocumented
68 0 my ( $self, $link, $topology ) = @_;
69  
70 0 ▶ if ( defined $self->options->{collation} and !$link->supports_collation ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->options->{"collation"} and not $link->supports_collation) 0 0 0
Condition0%0/3
defined $self->options->{"collation"} and not $link->supports_collation
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->options->{"collation"} and not $link->supports_collation
defined $self->options->{"collation"} not $link->supports_collation
Truth table0%0/3
A and not(B)
A= defined $self->options->{"collation"}B= not $link->supports_collation
ABresult
0X0
100
111
71 0 MongoDB::UsageError->throw(
72 "MongoDB host '" . $link->address . "' doesn't support collation" );
73 }
74  
75 my $command = $self->_maybe_bypass(
76 $link->supports_document_validation,
77 [
78 findAndModify => $self->coll_name,
79 query => $self->filter,
80 update => $self->_pre_encode_update(
81 $link->max_bson_object_size,
82 $self->modifier,
83 $self->is_replace,
84 ),
85 (
86 $link->supports_find_modify_write_concern
87 0 ? ( @{ $self->write_concern->as_args } )
88 : ()
89 ),
90 0 ▶ %{ $self->options },
Branch: 1 branch
BranchTrueFalseTotal
$link->supports_find_modify_write_concern ? : 0 0 0
91 ]
92 );
93  
94 0 my $op = MongoDB::Op::_Command->_new(
95 db_name => $self->db_name,
96 query => $command,
97 query_flags => {},
98 bson_codec => $self->bson_codec,
99 session => $self->session,
100 retryable_write => $self->retryable_write,
101 monitoring_callback => $self->monitoring_callback,
102 );
103  
104 # XXX more special error handling that will be a problem for
105 # command monitoring
106 0 my $result;
107 eval {
108 0 $result = $op->execute( $link, $topology );
109 0 $result = $result->{output};
110 0 1;
111 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $result = $op->execute($link, $topology); $result = $result->{"output"}; 1 } } or do { my $error = $@ || "Unknown error"; die $error unless $error eq "No matching object found" } 0 0 0
112 0 ▶ my $error = $@ || "Unknown error";
Condition0%0/2
$@ || 'Unknown error'
l!l
00
MC/DC0%0/1
$@ || 'Unknown error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
113 0 ▶ die $error unless $error eq 'No matching object found';
Branch: 1 branch
BranchTrueFalseTotal
unless $error eq "No matching object found" 0 0 0
114 };
115  
116 # findAndModify returns ok:1 even for write concern errors, so
117 # we must check and throw explicitly
118 0 ▶ if ( $result->{writeConcernError} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{"writeConcernError"}) 0 0 0
119 MongoDB::WriteConcernError->throw(
120 message => $result->{writeConcernError}{errmsg},
121 0 result => $result,
122 code => WRITE_CONCERN_ERROR,
123 );
124 }
125  
126 0 ▶ return $result->{value} if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 0 0 0
127 0 return;
128 }
129  
130 59 1;
« MongoDB/Op/_FindAndDelete.pm ↑ Summary MongoDB/BulkWriteView.pm »