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
|
59
|
|
|
59
|
|
99100
|
use strict; |
|
59
|
|
|
|
|
168
|
|
|
59
|
|
|
|
|
1968
|
|
16
|
59
|
|
|
59
|
|
325
|
use warnings; |
|
59
|
|
|
|
|
150
|
|
|
59
|
|
|
|
|
2271
|
|
17
|
|
|
|
|
|
|
package MongoDB::Role::_WriteResult; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# MongoDB interface for common write result attributes and methods |
20
|
|
|
|
|
|
|
|
21
|
59
|
|
|
59
|
|
329
|
use version; |
|
59
|
|
|
|
|
129
|
|
|
59
|
|
|
|
|
339
|
|
22
|
|
|
|
|
|
|
our $VERSION = 'v2.2.0'; |
23
|
|
|
|
|
|
|
|
24
|
59
|
|
|
59
|
|
4466
|
use Moo::Role; |
|
59
|
|
|
|
|
175
|
|
|
59
|
|
|
|
|
439
|
|
25
|
|
|
|
|
|
|
|
26
|
59
|
|
|
59
|
|
19846
|
use MongoDB::Error; |
|
59
|
|
|
|
|
149
|
|
|
59
|
|
|
|
|
5757
|
|
27
|
59
|
|
|
59
|
|
388
|
use MongoDB::_Constants; |
|
59
|
|
|
|
|
139
|
|
|
59
|
|
|
|
|
6054
|
|
28
|
59
|
|
|
|
|
432
|
use MongoDB::_Types qw( |
29
|
|
|
|
|
|
|
ArrayOfHashRef |
30
|
59
|
|
|
59
|
|
384
|
); |
|
59
|
|
|
|
|
132
|
|
31
|
|
|
|
|
|
|
|
32
|
59
|
|
|
59
|
|
56356
|
use namespace::clean; |
|
59
|
|
|
|
|
141
|
|
|
59
|
|
|
|
|
379
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has [qw/write_errors write_concern_errors/] => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
required => 1, |
37
|
|
|
|
|
|
|
isa => ArrayOfHashRef, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
with 'MongoDB::Role::_DatabaseErrorThrower'; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
0
|
0
|
|
sub acknowledged { 1 }; # override to 0 for MongoDB::UnacknowledgedResult |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# inline assert_no_write_error and assert_no_write_concern rather |
45
|
|
|
|
|
|
|
# than having to make to additional method calls |
46
|
|
|
|
|
|
|
sub assert { |
47
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$self->_throw_database_error("MongoDB::WriteError") |
50
|
0
|
0
|
|
|
|
|
if scalar @{ $self->write_errors }; |
|
0
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
MongoDB::WriteConcernError->throw( |
53
|
|
|
|
|
|
|
message => $self->last_errmsg, |
54
|
|
|
|
|
|
|
result => $self, |
55
|
|
|
|
|
|
|
code => WRITE_CONCERN_ERROR, |
56
|
0
|
0
|
|
|
|
|
) if scalar @{ $self->write_concern_errors }; |
|
0
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub assert_no_write_error { |
62
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$self->_throw_database_error("MongoDB::WriteError") |
65
|
0
|
0
|
|
|
|
|
if scalar @{ $self->write_errors }; |
|
0
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub assert_no_write_concern_error { |
71
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
MongoDB::WriteConcernError->throw( |
74
|
|
|
|
|
|
|
message => $self->last_errmsg, |
75
|
|
|
|
|
|
|
result => $self, |
76
|
|
|
|
|
|
|
code => WRITE_CONCERN_ERROR, |
77
|
0
|
0
|
|
|
|
|
) if scalar @{ $self->write_concern_errors }; |
|
0
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return $self; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub count_write_errors { |
83
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
84
|
0
|
|
|
|
|
|
return scalar @{ $self->write_errors }; |
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub count_write_concern_errors { |
88
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
89
|
0
|
|
|
|
|
|
return scalar @{ $self->write_concern_errors }; |
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub last_errmsg { |
93
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
94
|
0
|
0
|
|
|
|
|
if ( $self->count_write_errors ) { |
|
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub last_code { |
106
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
107
|
0
|
0
|
|
|
|
|
if ( $self->count_write_errors ) { |
|
|
0
|
|
|
|
|
|
108
|
0
|
|
0
|
|
|
|
return $self->write_errors->[-1]{code} || UNKNOWN_ERROR; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
elsif ( $self->count_write_concern_errors ) { |
111
|
0
|
|
0
|
|
|
|
return $self->write_concern_errors->[-1]{code} || UNKNOWN_ERROR; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
else { |
114
|
0
|
|
|
|
|
|
return 0; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub last_wtimeout { |
119
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
120
|
|
|
|
|
|
|
# if we have actual write errors, we don't want to report a |
121
|
|
|
|
|
|
|
# write concern error |
122
|
0
|
|
0
|
|
|
|
return !!( $self->count_write_concern_errors && !$self->count_write_errors ); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub last_error_labels { |
126
|
0
|
|
|
0
|
0
|
|
my ( $self ) = @_; |
127
|
0
|
0
|
|
|
|
|
if ( $self->count_write_errors ) { |
|
|
0
|
|
|
|
|
|
128
|
0
|
|
0
|
|
|
|
return $self->write_errors->[-1]{errorLabels} || []; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
elsif ( $self->count_write_concern_errors ) { |
131
|
0
|
|
0
|
|
|
|
return $self->write_errors->[-1]{errorLabels} || []; |
132
|
|
|
|
|
|
|
} |
133
|
0
|
|
|
|
|
|
return []; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |