| 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 | |||||||||||||||||||||||||||||
| 18 | package MongoDB::Op::_ListIndexes; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # Encapsulate index list operation; returns array ref of index documents | ||||||||||||||||||||||||||||
| 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::Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 59 | ▶ | use MongoDB::Op::_Command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 59 | ▶ | use MongoDB::Op::_Query; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 59 | ▶ | use MongoDB::ReadConcern; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 59 | ▶ | use MongoDB::ReadPreference; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 59 | ▶ | use Types::Standard qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | InstanceOf | ||||||||||||||||||||||||||||
| 34 | 59 | ); | |||||||||||||||||||||||||||
| 35 | 59 | ▶ | use Tie::IxHash; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 59 | ▶ | use Safe::Isa; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 59 | ▶ | use MongoDB::_Types qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | ReadPreference | ||||||||||||||||||||||||||||
| 39 | 59 | ); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 59 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 59 | has client => ( | |||||||||||||||||||||||||||
| 44 | is => 'ro', | ||||||||||||||||||||||||||||
| 45 | required => 1, | ||||||||||||||||||||||||||||
| 46 | isa => InstanceOf ['MongoDB::MongoClient'], | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 59 | has read_preference => ( | |||||||||||||||||||||||||||
| 50 | is => 'rw', # rw for Op::_Query which can be modified by Cursor | ||||||||||||||||||||||||||||
| 51 | required => 1, | ||||||||||||||||||||||||||||
| 52 | isa => ReadPreference, | ||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 59 | with $_ for qw( | |||||||||||||||||||||||||||
| 56 | MongoDB::Role::_PrivateConstructor | ||||||||||||||||||||||||||||
| 57 | MongoDB::Role::_CollectionOp | ||||||||||||||||||||||||||||
| 58 | MongoDB::Role::_CommandCursorOp | ||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 0 | my ( $self, $link, $topology ) = @_; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $res = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | $link->supports_list_commands | ||||||||||||||||||||||||||||
| 66 | ? $self->_command_list_indexes( $link, $topology ) | ||||||||||||||||||||||||||||
| 67 | : $self->_legacy_list_indexes( $link, $topology ); | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | return $res; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub _command_list_indexes { | ||||||||||||||||||||||||||
|
Subroutine
_command_list_indexes: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 73 | 0 | my ( $self, $link, $topology ) = @_; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | my $op = MongoDB::Op::_Command->_new( | |||||||||||||||||||||||||||
| 76 | db_name => $self->db_name, | ||||||||||||||||||||||||||||
| 77 | query => Tie::IxHash->new( listIndexes => $self->coll_name, cursor => {} ), | ||||||||||||||||||||||||||||
| 78 | query_flags => {}, | ||||||||||||||||||||||||||||
| 79 | bson_codec => $self->bson_codec, | ||||||||||||||||||||||||||||
| 80 | monitoring_callback => $self->monitoring_callback, | ||||||||||||||||||||||||||||
| 81 | read_preference => $self->read_preference, | ||||||||||||||||||||||||||||
| 82 | session => $self->session, | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | my $res = eval { | ||||||||||||||||||||||||||||
| 86 | 0 | $op->execute( $link, $topology ); | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $error = $@ || "Unknown error"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'Unknown error'
MC/DC0%0/1
$@ || 'Unknown error'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | unless ( $error->$_isa("MongoDB::DatabaseError") and $error->code == NAMESPACE_NOT_FOUND()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$error->$MongoDB::Op::_ListIndexes::_isa("MongoDB::DatabaseError") and $error->code == 26
MC/DC0%0/2
$error->$MongoDB::Op::_ListIndexes::_isa("MongoDB::DatabaseError") and $error->code == 26
$error->$MongoDB::Op::_ListIndexes::_isa("MongoDB::DatabaseError")
$error->code == 26
Truth table0%0/3
A and B
A= $error->$MongoDB::Op::_ListIndexes::_isa("MongoDB::DatabaseError")B= $error->code == 26
| |||||||||||||||||||||||||||||
| 90 | 0 | die $error; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 0 | undef; | |||||||||||||||||||||||||||
| 93 | }; | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | return $res | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | ? $self->_build_result_from_cursor($res) | ||||||||||||||||||||||||||||
| 97 | : $self->_empty_query_result($link); | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub _legacy_list_indexes { | ||||||||||||||||||||||||||
|
Subroutine
_legacy_list_indexes: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 101 | 0 | my ( $self, $link, $topology ) = @_; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | my $ns = $self->db_name . "." . $self->coll_name; | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | my $op = MongoDB::Op::_Query->_new( | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->read_preference || 'MongoDB::ReadPreference'->new
MC/DC0%0/2
$self->read_preference || 'MongoDB::ReadPreference'->new
$self->read_preference
'MongoDB::ReadPreference'->new
Truth table0%0/3
A || B
A= $self->read_preferenceB= 'MongoDB::ReadPreference'->new
| |||||||||||||||||||||||||||||
| 105 | filter => Tie::IxHash->new( ns => $ns ), | ||||||||||||||||||||||||||||
| 106 | options => MongoDB::Op::_Query->precondition_options({}), | ||||||||||||||||||||||||||||
| 107 | bson_codec => $self->bson_codec, | ||||||||||||||||||||||||||||
| 108 | client => $self->client, | ||||||||||||||||||||||||||||
| 109 | coll_name => 'system.indexes', | ||||||||||||||||||||||||||||
| 110 | db_name => $self->db_name, | ||||||||||||||||||||||||||||
| 111 | full_name => $self->db_name . '.system.indexes', | ||||||||||||||||||||||||||||
| 112 | read_concern => MongoDB::ReadConcern->new, | ||||||||||||||||||||||||||||
| 113 | read_preference => $self->read_preference || MongoDB::ReadPreference->new, | ||||||||||||||||||||||||||||
| 114 | monitoring_callback => $self->monitoring_callback, | ||||||||||||||||||||||||||||
| 115 | ); | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | return $op->execute( $link, $topology ); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 59 | 1; | |||||||||||||||||||||||||||