MongoDB/CommandResult.pm

filter: Statementstmt 55.9% 33 / 59 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 60.0% 9 / 15 Podpod 100% 6 / 6 totaltotal 43.6% 48 / 110 CC 14 SCAR 26.9
CC
14
Cov
39%
last_code
42.0
last_errmsg
20.0
assert
12.0
CRAP 14.8
« MongoDB/Role/_InsertPreEncoder.pm ↑ Summary MongoDB/Op/_Count.pm »
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 ▶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::CommandResult;
18  
19 # ABSTRACT: MongoDB generic command result document
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 59 ▶use MongoDB::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 59 ▶use MongoDB::_Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 59 ▶use MongoDB::_Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
28 HostAddress
29 ClientSession
30 59 );
31 59 ▶use Types::Standard qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
32 HashRef
33 Maybe
34 59 );
35 59 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 59 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 59 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 59 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 59 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 0 ▶sub last_code {
Subroutine last_code: not called CC=6 SCAR=37.4
Pod documented
86 0 my ($self) = @_;
87 0 my $output = $self->output;
88 0 ▶ if ( $output->{code} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($output->{'code'}) { } 0 0 0
elsif ($output->{'lastErrorObject'}) { } 0 0 0
elsif ($output->{'writeConcernError'}) { } 0 0 0
89 0 return $output->{code};
90 }
91 elsif ( $output->{lastErrorObject} ) {
92 0 ▶ return $output->{lastErrorObject}{code} || 0;
Condition0%0/2
$output->{'lastErrorObject'}{'code'} || 0
l!l
00
MC/DC0%0/1
$output->{'lastErrorObject'}{'code'} || 0
$output->{'lastErrorObject'}{'code'}
Truth table0%0/2
A
A= $output->{'lastErrorObject'}{'code'}
Aresult
11
00
93 }
94 elsif ( $output->{writeConcernError} ) {
95 0 ▶ return $output->{writeConcernError}{code} || 0;
Condition0%0/2
$output->{'writeConcernError'}{'code'} || 0
l!l
00
MC/DC0%0/1
$output->{'writeConcernError'}{'code'} || 0
$output->{'writeConcernError'}{'code'}
Truth table0%0/2
A
A= $output->{'writeConcernError'}{'code'}
Aresult
11
00
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 0 ▶sub last_errmsg {
Subroutine last_errmsg: not called CC=4 SCAR=30.0
Pod documented
109 0 my ($self) = @_;
110 0 my $output = $self->output;
111 0 for my $err_key (qw/$err err errmsg/) {
112 0 ▶ return $output->{$err_key} if exists $output->{$err_key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $output->{$err_key} 0 0 0
113 }
114 0 ▶ if ( exists $output->{writeConcernError} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $output->{"writeConcernError"}) 0 0 0
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 0 ▶sub last_wtimeout {
Subroutine last_wtimeout: not called CC=2 SCAR=17.9
Pod documented
127 0 my ($self) = @_;
128 return !!( exists $self->output->{wtimeout}
129 0 ▶ || exists $self->output->{writeConcernError} );
Condition0%0/3
exists $self->output->{'wtimeout'} || exists $self->output->{'writeConcernError'}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $self->output->{'wtimeout'} || exists $self->output->{'writeConcernError'}
exists $self->output->{'wtimeout'} exists $self->output->{'writeConcernError'}
Truth table0%0/3
A || B
A= exists $self->output->{'wtimeout'}B= exists $self->output->{'writeConcernError'}
ABresult
1X1
011
000
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 0 ▶sub last_error_labels {
Subroutine last_error_labels: not called CC=2 SCAR=17.9
Pod documented
140 0 my ( $self ) = @_;
141 0 ▶ return $self->output->{errorLabels} || [];
Condition0%0/2
$self->output->{'errorLabels'} || []
l!l
00
MC/DC0%0/1
$self->output->{'errorLabels'} || []
$self->output->{'errorLabels'}
Truth table0%0/2
A
A= $self->output->{'errorLabels'}
Aresult
11
00
142 }
143  
144 #pod =method assert
145 #pod
146 #pod Throws an exception if the command failed.
147 #pod
148 #pod =cut
149  
150 0 ▶sub assert {
Subroutine assert: not called CC=3 SCAR=24.8
Pod documented
151 0 my ($self, $default_class) = @_;
152  
153 0 ▶ if ( ! $self->output->{ok} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->output->{"ok"}) 0 0 0
154 0 ▶ $self->session->_maybe_unpin_address( $self->last_error_labels )
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->session 0 0 0
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 0 ▶sub assert_no_write_concern_error {
Subroutine assert_no_write_concern_error: not called CC=2 SCAR=17.9
Pod documented
169 0 my ($self) = @_;
170  
171 0 ▶ $self->_throw_database_error( "MongoDB::WriteConcernError" )
Branch: 1 branch
BranchTrueFalseTotal
if $self->last_wtimeout 0 0 0
172 if $self->last_wtimeout;
173  
174 0 return 1;
175 }
176  
177 59 1;
178  
179 __END__
« MongoDB/Role/_InsertPreEncoder.pm ↑ Summary MongoDB/Op/_Count.pm »