MongoDB/Op/_CreateIndexes.pm

filter: Statementstmt 60.3% 32 / 53 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 69.2% 9 / 13 Podpod 0.0% 0 / 2 totaltotal 50.6% 41 / 81 CC 6 SCAR 19.7
CC
6
Cov
50%
execute
20.0
_command_create_indexes
12.0
has_collation
2.0
CRAP 7.2
« MongoDB/Op/_BatchInsert.pm ↑ Summary MongoDB/QueryResult.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::_CreateIndexes;
18  
19 # Encapsulate index creation operations; returns a MongoDB::CommandResult
20 # or a MongoDB::InsertManyResult, depending on the server version
21  
22 59 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 59 our $VERSION = 'v2.2.2';
24  
25 59 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 59 ▶use MongoDB::Op::_Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 59 ▶use MongoDB::Op::_BatchInsert;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 59 ▶use Types::Standard qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
30 ArrayRef
31 HashRef
32 59 );
33 59 ▶use MongoDB::_Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
34 Numish
35 59 );
36  
37 59 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 59 has indexes => (
40 is => 'ro',
41 required => 1,
42 isa => ArrayRef [HashRef],
43 );
44  
45 59 has max_time_ms => (
46 is => 'ro',
47 isa => Numish,
48 );
49  
50 59 with $_ for qw(
51 MongoDB::Role::_PrivateConstructor
52 MongoDB::Role::_CollectionOp
53 MongoDB::Role::_WriteOp
54 );
55  
56 0 ▶sub has_collation {
Subroutine has_collation: not called CC=1 SCAR=6.9
Pod undocumented
57 0 return grep { defined $_->{collation} } @{ $_[0]->indexes };
58 }
59  
60 0 ▶sub execute {
Subroutine execute: not called CC=4 SCAR=30.0
Pod undocumented
61 0 my ( $self, $link ) = @_;
62  
63 0 ▶ if ( $self->has_collation && !$link->supports_collation ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_collation and not $link->supports_collation) 0 0 0
Condition0%0/3
$self->has_collation and not $link->supports_collation
!ll&&!rl&&r
000
MC/DC0%0/2
$self->has_collation and not $link->supports_collation
$self->has_collation not $link->supports_collation
Truth table0%0/3
A and not(B)
A= $self->has_collationB= not $link->supports_collation
ABresult
0X0
100
111
64 0 MongoDB::UsageError->throw(
65 "MongoDB host '" . $link->address . "' doesn't support collation" );
66 }
67  
68 0 ▶ my $res =
Branch: 1 branch
BranchTrueFalseTotal
$link->supports_write_commands ? : 0 0 0
69 $link->supports_write_commands
70 ? $self->_command_create_indexes($link)
71 : $self->_legacy_index_insert($link);
72  
73 0 return $res;
74 }
75  
76 0 ▶sub _command_create_indexes {
Subroutine _command_create_indexes: not called CC=3 SCAR=24.8
77 0 my ( $self, $link, $op_doc ) = @_;
78  
79 my $op = MongoDB::Op::_Command->_new(
80 db_name => $self->db_name,
81 query => [
82 createIndexes => $self->coll_name,
83 indexes => $self->indexes,
84 0 ▶ ( $link->supports_helper_write_concern ? ( @{ $self->write_concern->as_args } ) : () ),
Branch: 2 branches
BranchTrueFalseTotal
$link->supports_helper_write_concern ? : 0 0 0
defined $self->max_time_ms ? : 0 0 0
85 (defined($self->max_time_ms)
86 ? (maxTimeMS => $self->max_time_ms)
87 : ()
88 ),
89 ],
90 query_flags => {},
91 bson_codec => $self->bson_codec,
92 monitoring_callback => $self->monitoring_callback,
93 );
94  
95 0 my $res = $op->execute( $link );
96 0 $res->assert_no_write_concern_error;
97  
98 0 return $res;
99 }
100  
101 0 ▶sub _legacy_index_insert {
Subroutine _legacy_index_insert: not called CC=1 SCAR=6.9
102 0 my ( $self, $link, $op_doc ) = @_;
103  
104 # construct docs for an insert many op
105 0 my $ns = join( ".", $self->db_name, $self->coll_name );
106 my $indexes = [
107 map {
108 0 { %$_, ns => $ns }
109 0 } @{ $self->indexes }
110 ];
111  
112 0 my $op = MongoDB::Op::_BatchInsert->_new(
113 db_name => $self->db_name,
114 coll_name => "system.indexes",
115 full_name => ( join ".", $self->db_name, "system.indexes" ),
116 documents => $indexes,
117 write_concern => $self->write_concern,
118 bson_codec => $self->bson_codec,
119 check_keys => 0,
120 ordered => 1,
121 monitoring_callback => $self->monitoring_callback,
122 );
123  
124 0 return $op->execute($link);
125 }
126  
127 59 1;
« MongoDB/Op/_BatchInsert.pm ↑ Summary MongoDB/QueryResult.pm »