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
|
58
|
|
|
58
|
|
416
|
use strict; |
|
58
|
|
|
|
|
121
|
|
|
58
|
|
|
|
|
1685
|
|
16
|
58
|
|
|
58
|
|
286
|
use warnings; |
|
58
|
|
|
|
|
111
|
|
|
58
|
|
|
|
|
1869
|
|
17
|
|
|
|
|
|
|
package MongoDB::CommandResult; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# ABSTRACT: MongoDB generic command result document |
20
|
|
|
|
|
|
|
|
21
|
58
|
|
|
58
|
|
303
|
use version; |
|
58
|
|
|
|
|
439
|
|
|
58
|
|
|
|
|
300
|
|
22
|
|
|
|
|
|
|
our $VERSION = 'v2.2.0'; |
23
|
|
|
|
|
|
|
|
24
|
58
|
|
|
58
|
|
4217
|
use Moo; |
|
58
|
|
|
|
|
118
|
|
|
58
|
|
|
|
|
430
|
|
25
|
58
|
|
|
58
|
|
23646
|
use MongoDB::Error; |
|
58
|
|
|
|
|
169
|
|
|
58
|
|
|
|
|
7521
|
|
26
|
58
|
|
|
58
|
|
602
|
use MongoDB::_Constants; |
|
58
|
|
|
|
|
126
|
|
|
58
|
|
|
|
|
7559
|
|
27
|
58
|
|
|
|
|
534
|
use MongoDB::_Types qw( |
28
|
|
|
|
|
|
|
HostAddress |
29
|
|
|
|
|
|
|
ClientSession |
30
|
58
|
|
|
58
|
|
440
|
); |
|
58
|
|
|
|
|
117
|
|
31
|
58
|
|
|
|
|
452
|
use Types::Standard qw( |
32
|
|
|
|
|
|
|
HashRef |
33
|
|
|
|
|
|
|
Maybe |
34
|
58
|
|
|
58
|
|
77312
|
); |
|
58
|
|
|
|
|
126
|
|
35
|
58
|
|
|
58
|
|
48631
|
use namespace::clean; |
|
58
|
|
|
|
|
129
|
|
|
58
|
|
|
|
|
524
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
with $_ for qw( |
38
|
|
|
|
|
|
|
MongoDB::Role::_PrivateConstructor |
39
|
|
|
|
|
|
|
MongoDB::Role::_DatabaseErrorThrower |
40
|
|
|
|
|
|
|
MongoDB::Role::_DeprecationWarner |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#pod =attr output |
44
|
|
|
|
|
|
|
#pod |
45
|
|
|
|
|
|
|
#pod Hash reference with the output document of a database command |
46
|
|
|
|
|
|
|
#pod |
47
|
|
|
|
|
|
|
#pod =cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has output => ( |
50
|
|
|
|
|
|
|
is => 'ro', |
51
|
|
|
|
|
|
|
required => 1, |
52
|
|
|
|
|
|
|
isa => HashRef, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#pod =attr address |
56
|
|
|
|
|
|
|
#pod |
57
|
|
|
|
|
|
|
#pod Address ("host:port") of server that ran the command |
58
|
|
|
|
|
|
|
#pod |
59
|
|
|
|
|
|
|
#pod =cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has address => ( |
62
|
|
|
|
|
|
|
is => 'ro', |
63
|
|
|
|
|
|
|
required => 1, |
64
|
|
|
|
|
|
|
isa => HostAddress, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#pod =attr session |
68
|
|
|
|
|
|
|
#pod |
69
|
|
|
|
|
|
|
#pod ClientSession which the command was ran with, if any |
70
|
|
|
|
|
|
|
#pod |
71
|
|
|
|
|
|
|
#pod =cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
has session => ( |
74
|
|
|
|
|
|
|
is => 'ro', |
75
|
|
|
|
|
|
|
required => 0, |
76
|
|
|
|
|
|
|
isa => Maybe[ClientSession], |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#pod =method last_code |
80
|
|
|
|
|
|
|
#pod |
81
|
|
|
|
|
|
|
#pod Error code (if any) or 0 if there was no error. |
82
|
|
|
|
|
|
|
#pod |
83
|
|
|
|
|
|
|
#pod =cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub last_code { |
86
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
87
|
0
|
|
|
|
|
|
my $output = $self->output; |
88
|
0
|
0
|
|
|
|
|
if ( $output->{code} ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return $output->{code}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
elsif ( $output->{lastErrorObject} ) { |
92
|
0
|
|
0
|
|
|
|
return $output->{lastErrorObject}{code} || 0; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif ( $output->{writeConcernError} ) { |
95
|
0
|
|
0
|
|
|
|
return $output->{writeConcernError}{code} || 0; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else { |
98
|
0
|
|
|
|
|
|
return 0; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#pod =method last_errmsg |
103
|
|
|
|
|
|
|
#pod |
104
|
|
|
|
|
|
|
#pod Error string (if any) or the empty string if there was no error. |
105
|
|
|
|
|
|
|
#pod |
106
|
|
|
|
|
|
|
#pod =cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub last_errmsg { |
109
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
110
|
0
|
|
|
|
|
|
my $output = $self->output; |
111
|
0
|
|
|
|
|
|
for my $err_key (qw/$err err errmsg/) { |
112
|
0
|
0
|
|
|
|
|
return $output->{$err_key} if exists $output->{$err_key}; |
113
|
|
|
|
|
|
|
} |
114
|
0
|
0
|
|
|
|
|
if ( exists $output->{writeConcernError} ) { |
115
|
|
|
|
|
|
|
return $output->{writeConcernError}{errmsg} |
116
|
0
|
|
|
|
|
|
} |
117
|
0
|
|
|
|
|
|
return ""; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
#pod =method last_wtimeout |
121
|
|
|
|
|
|
|
#pod |
122
|
|
|
|
|
|
|
#pod True if a write concern error or timeout occurred or false otherwise. |
123
|
|
|
|
|
|
|
#pod |
124
|
|
|
|
|
|
|
#pod =cut |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub last_wtimeout { |
127
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
128
|
|
|
|
|
|
|
return !!( exists $self->output->{wtimeout} |
129
|
0
|
|
0
|
|
|
|
|| exists $self->output->{writeConcernError} ); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
#pod =method last_error_labels |
133
|
|
|
|
|
|
|
#pod |
134
|
|
|
|
|
|
|
#pod Returns an array of error labels from the command, or an empty array if there |
135
|
|
|
|
|
|
|
#pod are none |
136
|
|
|
|
|
|
|
#pod |
137
|
|
|
|
|
|
|
#pod =cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub last_error_labels { |
140
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
141
|
0
|
|
0
|
|
|
|
return $self->output->{errorLabels} || []; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
#pod =method assert |
145
|
|
|
|
|
|
|
#pod |
146
|
|
|
|
|
|
|
#pod Throws an exception if the command failed. |
147
|
|
|
|
|
|
|
#pod |
148
|
|
|
|
|
|
|
#pod =cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub assert { |
151
|
0
|
|
|
0
|
1
|
|
my ($self, $default_class) = @_; |
152
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
if ( ! $self->output->{ok} ) { |
154
|
0
|
0
|
|
|
|
|
$self->session->_maybe_unpin_address( $self->last_error_labels ) |
155
|
|
|
|
|
|
|
if defined $self->session; |
156
|
0
|
|
|
|
|
|
$self->_throw_database_error( $default_class ); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
return 1; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
#pod =method assert_no_write_concern_error |
163
|
|
|
|
|
|
|
#pod |
164
|
|
|
|
|
|
|
#pod Throws an exception if a write concern error occurred |
165
|
|
|
|
|
|
|
#pod |
166
|
|
|
|
|
|
|
#pod =cut |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub assert_no_write_concern_error { |
169
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
170
|
|
|
|
|
|
|
|
171
|
0
|
0
|
|
|
|
|
$self->_throw_database_error( "MongoDB::WriteConcernError" ) |
172
|
|
|
|
|
|
|
if $self->last_wtimeout; |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
return 1; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
__END__ |