| 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 | 60 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 60 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | package MongoDB::Role::_WriteResult; | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | # MongoDB interface for common write result attributes and methods | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 60 | ▶ | use version; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 60 | our $VERSION = 'v2.2.2'; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 60 | ▶ | use Moo::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 60 | ▶ | use MongoDB::Error; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | 60 | ▶ | use MongoDB::_Constants; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | 60 | ▶ | use MongoDB::_Types qw( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | ArrayOfHashRef | ||||||||||||||||||||
| 30 | 60 | ); | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 60 | ▶ | use namespace::clean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 60 | has [qw/write_errors write_concern_errors/] => ( | |||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||
| 36 | required => 1, | ||||||||||||||||||||
| 37 | isa => ArrayOfHashRef, | ||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 60 | with 'MongoDB::Role::_DatabaseErrorThrower'; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | ▶ | sub acknowledged { 1 }; # override to 0 for MongoDB::UnacknowledgedResult | ||||||||||||||||||
|
Subroutine
acknowledged: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | # inline assert_no_write_error and assert_no_write_concern rather | ||||||||||||||||||||
| 45 | # than having to make to additional method calls | ||||||||||||||||||||
| 46 | 0 | ▶ | sub assert { | ||||||||||||||||||
|
Subroutine
assert: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 47 | 0 | my ($self) = @_; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | $self->_throw_database_error("MongoDB::WriteError") | ||||||||||||||||||||
| 50 | 0 | ▶ | if scalar @{ $self->write_errors }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | MongoDB::WriteConcernError->throw( | ||||||||||||||||||||
| 53 | message => $self->last_errmsg, | ||||||||||||||||||||
| 54 | result => $self, | ||||||||||||||||||||
| 55 | code => WRITE_CONCERN_ERROR, | ||||||||||||||||||||
| 56 | 0 | ▶ | ) if scalar @{ $self->write_concern_errors }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | return $self; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | ▶ | sub assert_no_write_error { | ||||||||||||||||||
|
Subroutine
assert_no_write_error: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 62 | 0 | my ($self) = @_; | |||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | $self->_throw_database_error("MongoDB::WriteError") | ||||||||||||||||||||
| 65 | 0 | ▶ | if scalar @{ $self->write_errors }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 0 | return $self; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | ▶ | sub assert_no_write_concern_error { | ||||||||||||||||||
|
Subroutine
assert_no_write_concern_error: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 71 | 0 | my ($self) = @_; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | MongoDB::WriteConcernError->throw( | ||||||||||||||||||||
| 74 | message => $self->last_errmsg, | ||||||||||||||||||||
| 75 | result => $self, | ||||||||||||||||||||
| 76 | code => WRITE_CONCERN_ERROR, | ||||||||||||||||||||
| 77 | 0 | ▶ | ) if scalar @{ $self->write_concern_errors }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | return $self; | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 0 | ▶ | sub count_write_errors { | ||||||||||||||||||
|
Subroutine
count_write_errors: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 83 | 0 | my ($self) = @_; | |||||||||||||||||||
| 84 | 0 | return scalar @{ $self->write_errors }; | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 0 | ▶ | sub count_write_concern_errors { | ||||||||||||||||||
|
Subroutine
count_write_concern_errors: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 88 | 0 | my ($self) = @_; | |||||||||||||||||||
| 89 | 0 | return scalar @{ $self->write_concern_errors }; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | ▶ | sub last_errmsg { | ||||||||||||||||||
|
Subroutine
last_errmsg: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||
| 93 | 0 | my ($self) = @_; | |||||||||||||||||||
| 94 | 0 | ▶ | if ( $self->count_write_errors ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 95 | 0 | return $self->write_errors->[-1]{errmsg}; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | elsif ( $self->count_write_concern_errors ) { | ||||||||||||||||||||
| 98 | 0 | return $self->write_concern_errors->[-1]{errmsg}; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | else { | ||||||||||||||||||||
| 101 | 0 | return ""; | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | ▶ | sub last_code { | ||||||||||||||||||
|
Subroutine
last_code: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 106 | 0 | my ($self) = @_; | |||||||||||||||||||
| 107 | 0 | ▶ | if ( $self->count_write_errors ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 108 | 0 | ▶ | return $self->write_errors->[-1]{code} || UNKNOWN_ERROR; | ||||||||||||||||||
|
Condition0%0/2
$self->write_errors->[-1]{'code'} || 8
MC/DC0%0/1
$self->write_errors->[-1]{'code'} || 8
$self->write_errors->[-1]{'code'}
Truth table0%0/2
A
A= $self->write_errors->[-1]{'code'}
| |||||||||||||||||||||
| 109 | } | ||||||||||||||||||||
| 110 | elsif ( $self->count_write_concern_errors ) { | ||||||||||||||||||||
| 111 | 0 | ▶ | return $self->write_concern_errors->[-1]{code} || UNKNOWN_ERROR; | ||||||||||||||||||
|
Condition0%0/2
$self->write_concern_errors->[-1]{'code'} || 8
MC/DC0%0/1
$self->write_concern_errors->[-1]{'code'} || 8
$self->write_concern_errors->[-1]{'code'}
Truth table0%0/2
A
A= $self->write_concern_errors->[-1]{'code'}
| |||||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | else { | ||||||||||||||||||||
| 114 | 0 | return 0; | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 0 | ▶ | sub last_wtimeout { | ||||||||||||||||||
|
Subroutine
last_wtimeout: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 119 | 0 | my ($self) = @_; | |||||||||||||||||||
| 120 | # if we have actual write errors, we don't want to report a | ||||||||||||||||||||
| 121 | # write concern error | ||||||||||||||||||||
| 122 | 0 | ▶ | return !!( $self->count_write_concern_errors && !$self->count_write_errors ); | ||||||||||||||||||
|
Condition0%0/3
$self->count_write_concern_errors && !$self->count_write_errors
MC/DC0%0/2
$self->count_write_concern_errors && !$self->count_write_errors
$self->count_write_concern_errors
!$self->count_write_errors
Truth table0%0/3
A && not(B)
A= $self->count_write_concern_errorsB= !$self->count_write_errors
| |||||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 0 | ▶ | sub last_error_labels { | ||||||||||||||||||
|
Subroutine
last_error_labels: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 126 | 0 | my ( $self ) = @_; | |||||||||||||||||||
| 127 | 0 | ▶ | if ( $self->count_write_errors ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 128 | 0 | ▶ | return $self->write_errors->[-1]{errorLabels} || []; | ||||||||||||||||||
|
Condition0%0/2
$self->write_errors->[-1]{'errorLabels'} || []
MC/DC0%0/1
$self->write_errors->[-1]{'errorLabels'} || []
$self->write_errors->[-1]{'errorLabels'}
Truth table0%0/2
A
A= $self->write_errors->[-1]{'errorLabels'}
| |||||||||||||||||||||
| 129 | } | ||||||||||||||||||||
| 130 | elsif ( $self->count_write_concern_errors ) { | ||||||||||||||||||||
| 131 | 0 | ▶ | return $self->write_errors->[-1]{errorLabels} || []; | ||||||||||||||||||
|
Condition0%0/2
$self->write_errors->[-1]{'errorLabels'} || []
MC/DC0%0/1
$self->write_errors->[-1]{'errorLabels'} || []
$self->write_errors->[-1]{'errorLabels'}
Truth table0%0/2
A
A= $self->write_errors->[-1]{'errorLabels'}
| |||||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | 0 | return []; | |||||||||||||||||||
| 134 | } | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | 60 | 1; | |||||||||||||||||||