MongoDB/Op/_Delete.pm

filter: Statementstmt 77.0% 37 / 48 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 84.6% 11 / 13 Podpod 0.0% 0 / 1 totaltotal 56.4% 48 / 85 CC 12 SCAR 41.2
CC
12
Cov
53%
execute
132.0
_parse_cmd
6.0
BEGIN
1.0
CRAP 61.5
« MongoDB/Role/_CommandCursorOp.pm ↑ Summary MongoDB/Role/_ReadPrefModifier.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::Op::_Delete;
18  
19 # Encapsulate a delete operation; returns a MongoDB::DeleteResult
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  
26 59 ▶use MongoDB::DeleteResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 59 ▶use MongoDB::_Protocol;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 59 ▶use MongoDB::_Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
29 Boolish
30 Document
31 59 );
32 59 ▶use Types::Standard qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
33 Maybe
34 59 );
35  
36 59 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 59 has filter => (
39 is => 'ro',
40 required => 1,
41 isa => Document,
42 );
43  
44 59 has just_one => (
45 is => 'ro',
46 required => 1,
47 isa => Boolish,
48 );
49  
50 59 has collation => (
51 is => 'ro',
52 isa => Maybe( [Document] ),
53 );
54  
55 59 with $_ for qw(
56 MongoDB::Role::_PrivateConstructor
57 MongoDB::Role::_CollectionOp
58 MongoDB::Role::_SingleBatchDocWrite
59 );
60  
61 0 ▶sub execute {
Subroutine execute: not called CC=11 SCAR=48.8
Pod undocumented
62 0 my ( $self, $link ) = @_;
63  
64 0 ▶ if ( defined $self->collation ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->collation) 0 0 0
65 0 ▶ MongoDB::UsageError->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $link->supports_collation 0 0 0
66 "MongoDB host '" . $link->address . "' doesn't support collation" )
67 if !$link->supports_collation;
68 0 ▶ MongoDB::UsageError->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_should_use_acknowledged_write 0 0 0
69 "Unacknowledged deletes that specify a collation are not allowed")
70 if ! $self->_should_use_acknowledged_write;
71 }
72  
73 my $filter =
74 ref( $self->filter ) eq 'ARRAY'
75 0 ▶ ? { @{ $self->filter } }
Branch: 1 branch
BranchTrueFalseTotal
ref $self->filter eq 'ARRAY' ? : 0 0 0
76 : $self->filter;
77  
78 0 ▶ my $op_doc = {
Branch: 2 branches
BranchTrueFalseTotal
$self->just_one ? : 0 0 0
defined $self->collation ? : 0 0 0
79 q => $filter,
80 limit => $self->just_one ? 1 : 0,
81 ( defined $self->collation ? ( collation => $self->collation ) : () ),
82 };
83  
84 return (
85 ! $self->_should_use_acknowledged_write
86 ? (
87 $self->_send_legacy_op_noreply(
88 $link,
89 MongoDB::_Protocol::write_delete(
90 $self->full_name,
91 $self->bson_codec->encode_one( $self->filter ),
92 { just_one => $self->just_one ? 1 : 0 }
93 ),
94 $op_doc,
95 "MongoDB::DeleteResult",
96 "delete",
97 )
98 )
99 : $link->supports_write_commands
100 ? (
101 $self->_send_write_command(
102 $link,
103 [
104 delete => $self->coll_name,
105 deletes => [$op_doc],
106 0 ▶ @{ $self->write_concern->as_args },
Branch: 4 branches
BranchTrueFalseTotal
!$self->_should_use_acknowledged_write ? : 0 0 0
$self->just_one ? : 0 0 0
$link->supports_write_commands ? : 0 0 0
$self->just_one ? : 0 0 0
107 ],
108 $op_doc,
109 "MongoDB::DeleteResult"
110 )->assert
111 )
112 : (
113 $self->_send_legacy_op_with_gle(
114 $link,
115 MongoDB::_Protocol::write_delete(
116 $self->full_name,
117 $self->bson_codec->encode_one( $self->filter ),
118 { just_one => $self->just_one ? 1 : 0 }
119 ),
120 $op_doc,
121 "MongoDB::DeleteResult",
122 "delete",
123 )->assert
124 )
125 );
126 }
127  
128 0 ▶sub _parse_cmd {
Subroutine _parse_cmd: not called CC=2 SCAR=17.9
129 0 my ( $self, $res ) = @_;
130 0 ▶ return ( deleted_count => $res->{n} || 0 );
Condition0%0/2
$res->{'n'} || 0
l!l
00
MC/DC0%0/1
$res->{'n'} || 0
$res->{'n'}
Truth table0%0/2
A
A= $res->{'n'}
Aresult
11
00
131 }
132  
133 59 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
134 59 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
135 59 *_parse_gle = \&_parse_cmd;
136 }
137  
138 59 1;
« MongoDB/Role/_CommandCursorOp.pm ↑ Summary MongoDB/Role/_ReadPrefModifier.pm »