| 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::_FindAndDelete; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # Encapsulate find_and_delete operation; atomically delete 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 boolean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 59 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 59 | has filter => ( | |||||||||||||||||||||||||||
| 36 | is => 'ro', | ||||||||||||||||||||||||||||
| 37 | required => 1, | ||||||||||||||||||||||||||||
| 38 | isa => HashRef, | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 59 | has options => ( | |||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||
| 43 | required => 1, | ||||||||||||||||||||||||||||
| 44 | isa => HashRef, | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 59 | with $_ for qw( | |||||||||||||||||||||||||||
| 48 | MongoDB::Role::_PrivateConstructor | ||||||||||||||||||||||||||||
| 49 | MongoDB::Role::_CollectionOp | ||||||||||||||||||||||||||||
| 50 | MongoDB::Role::_WriteOp | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 0 | my ( $self, $link, $topology ) = @_; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ( defined $self->options->{collation} and !$link->supports_collation ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->options->{"collation"} and not $link->supports_collation
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
| |||||||||||||||||||||||||||||
| 57 | 0 | MongoDB::UsageError->throw( | |||||||||||||||||||||||||||
| 58 | "MongoDB host '" . $link->address . "' doesn't support collation" ); | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | my $command = [ | ||||||||||||||||||||||||||||
| 62 | findAndModify => $self->coll_name, | ||||||||||||||||||||||||||||
| 63 | query => $self->filter, | ||||||||||||||||||||||||||||
| 64 | remove => true, | ||||||||||||||||||||||||||||
| 65 | ($link->supports_find_modify_write_concern ? | ||||||||||||||||||||||||||||
| 66 | 0 | (@{ $self->write_concern->as_args }) | |||||||||||||||||||||||||||
| 67 | : () ), | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | %{ $self->options }, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | ]; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | my $op = MongoDB::Op::_Command->_new( | |||||||||||||||||||||||||||
| 72 | db_name => $self->db_name, | ||||||||||||||||||||||||||||
| 73 | query => $command, | ||||||||||||||||||||||||||||
| 74 | query_flags => {}, | ||||||||||||||||||||||||||||
| 75 | bson_codec => $self->bson_codec, | ||||||||||||||||||||||||||||
| 76 | session => $self->session, | ||||||||||||||||||||||||||||
| 77 | retryable_write => $self->retryable_write, | ||||||||||||||||||||||||||||
| 78 | monitoring_callback => $self->monitoring_callback, | ||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # XXX more special error handling that will be a problem for | ||||||||||||||||||||||||||||
| 82 | # command monitoring | ||||||||||||||||||||||||||||
| 83 | 0 | my $result; | |||||||||||||||||||||||||||
| 84 | eval { | ||||||||||||||||||||||||||||
| 85 | 0 | $result = $op->execute( $link, $topology ); | |||||||||||||||||||||||||||
| 86 | 0 | $result = $result->{output}; | |||||||||||||||||||||||||||
| 87 | 0 | 1; | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my $error = $@ || "Unknown error"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'Unknown error'
MC/DC0%0/1
$@ || 'Unknown error'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | die $error unless $error eq 'No matching object found'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | }; | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # findAndModify returns ok:1 even for write concern errors, so | ||||||||||||||||||||||||||||
| 94 | # we must check and throw explicitly | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ( $result->{writeConcernError} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | MongoDB::WriteConcernError->throw( | ||||||||||||||||||||||||||||
| 97 | message => $result->{writeConcernError}{errmsg}, | ||||||||||||||||||||||||||||
| 98 | 0 | result => $result, | |||||||||||||||||||||||||||
| 99 | code => WRITE_CONCERN_ERROR, | ||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return $result->{value} if $result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | return; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 59 | 1; | |||||||||||||||||||||||||||