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
|
|
397
|
use strict; |
|
59
|
|
|
|
|
151
|
|
|
59
|
|
|
|
|
1710
|
|
16
|
59
|
|
|
59
|
|
310
|
use warnings; |
|
59
|
|
|
|
|
119
|
|
|
59
|
|
|
|
|
2002
|
|
17
|
|
|
|
|
|
|
package MongoDB::CommandResult; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# ABSTRACT: MongoDB generic command result document |
20
|
|
|
|
|
|
|
|
21
|
59
|
|
|
59
|
|
577
|
use version; |
|
59
|
|
|
|
|
123
|
|
|
59
|
|
|
|
|
2559
|
|
22
|
|
|
|
|
|
|
our $VERSION = 'v2.2.1'; |
23
|
|
|
|
|
|
|
|
24
|
59
|
|
|
59
|
|
4318
|
use Moo; |
|
59
|
|
|
|
|
151
|
|
|
59
|
|
|
|
|
422
|
|
25
|
59
|
|
|
59
|
|
22701
|
use MongoDB::Error; |
|
59
|
|
|
|
|
179
|
|
|
59
|
|
|
|
|
7841
|
|
26
|
59
|
|
|
59
|
|
432
|
use MongoDB::_Constants; |
|
59
|
|
|
|
|
157
|
|
|
59
|
|
|
|
|
7718
|
|
27
|
59
|
|
|
|
|
625
|
use MongoDB::_Types qw( |
28
|
|
|
|
|
|
|
HostAddress |
29
|
|
|
|
|
|
|
ClientSession |
30
|
59
|
|
|
59
|
|
480
|
); |
|
59
|
|
|
|
|
114
|
|
31
|
59
|
|
|
|
|
441
|
use Types::Standard qw( |
32
|
|
|
|
|
|
|
HashRef |
33
|
|
|
|
|
|
|
Maybe |
34
|
59
|
|
|
59
|
|
79916
|
); |
|
59
|
|
|
|
|
131
|
|
35
|
59
|
|
|
59
|
|
49068
|
use namespace::clean; |
|
59
|
|
|
|
|
128
|
|
|
59
|
|
|
|
|
539
|
|
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__ |