MongoDB/Op/_ListCollections.pm

filter: Statementstmt 63.8% 46 / 72 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 76.4% 13 / 17 Podpod 0.0% 0 / 1 totaltotal 54.6% 59 / 108 CC 7 SCAR 17.2
CC
7
Cov
53%
_command_list_colls
20.0
execute
6.0
_legacy_list_colls
6.0
CRAP 5.6
« MongoDB/Role/_TopologyMonitoring.pm ↑ Summary MongoDB/Op/_GetMore.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::_ListCollections;
18  
19 # Encapsulate collection list operations; returns arrayref of collection
20 # names
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::_Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 59 ▶use MongoDB::ReadConcern;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 59 ▶use MongoDB::ReadPreference;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 59 ▶use MongoDB::_Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
32 Document
33 ReadPreference
34 59 );
35 59 ▶use Types::Standard qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
36 HashRef
37 InstanceOf
38 Str
39 59 );
40 59 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 59 ▶use boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 59 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 59 has client => (
46 is => 'ro',
47 required => 1,
48 isa => InstanceOf['MongoDB::MongoClient'],
49 );
50  
51 59 has filter => (
52 is => 'ro',
53 required => 1,
54 isa => Document,
55 );
56  
57 59 has options => (
58 is => 'ro',
59 required => 1,
60 isa => HashRef,
61 );
62  
63 59 has read_preference => (
64 is => 'rw', # rw for Op::_Query which can be modified by Cursor
65 required => 1,
66 isa => ReadPreference,
67 );
68  
69 59 with $_ for qw(
70 MongoDB::Role::_PrivateConstructor
71 MongoDB::Role::_DatabaseOp
72 MongoDB::Role::_CommandCursorOp
73 );
74  
75 0 ▶sub execute {
Subroutine execute: not called CC=2 SCAR=17.9
Pod undocumented
76 0 my ( $self, $link, $topology ) = @_;
77  
78 0 ▶ my $res =
Branch: 1 branch
BranchTrueFalseTotal
$link->supports_list_commands ? : 0 0 0
79 $link->supports_list_commands
80 ? $self->_command_list_colls( $link, $topology )
81 : $self->_legacy_list_colls( $link, $topology );
82  
83 0 return $res;
84 }
85  
86 0 ▶sub _command_list_colls {
Subroutine _command_list_colls: not called CC=4 SCAR=30.0
87 0 my ( $self, $link, $topology ) = @_;
88  
89 0 my $options = $self->options;
90  
91 # batchSize is not a command parameter itself like other options
92 0 my $batchSize = delete $options->{batchSize};
93  
94 0 ▶ if ( defined $batchSize ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $batchSize) { } 0 0 0
95 0 $options->{cursor} = { batchSize => $batchSize };
96 }
97 else {
98 0 $options->{cursor} = {};
99 }
100  
101 # Normalize or delete 'nameOnly'
102 0 ▶ if ($options->{nameOnly}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{'nameOnly'}) { } 0 0 0
103 0 $options->{nameOnly} = true;
104 }
105 else {
106 0 delete $options->{nameOnly};
107 }
108  
109 my $filter =
110 ref( $self->filter ) eq 'ARRAY'
111 0 ▶ ? { @{ $self->filter } }
Branch: 1 branch
BranchTrueFalseTotal
ref $self->filter eq 'ARRAY' ? : 0 0 0
112 : $self->filter;
113  
114 my $cmd = Tie::IxHash->new(
115 listCollections => 1,
116 filter => $filter,
117 nameOnly => false,
118 0 %{$self->options},
119 );
120  
121 0 my $op = MongoDB::Op::_Command->_new(
122 db_name => $self->db_name,
123 query => $cmd,
124 query_flags => {},
125 bson_codec => $self->bson_codec,
126 session => $self->session,
127 monitoring_callback => $self->monitoring_callback,
128 read_preference => $self->read_preference,
129 );
130  
131 0 my $res = $op->execute( $link, $topology );
132  
133 0 return $self->_build_result_from_cursor( $res );
134 }
135  
136 0 ▶sub _legacy_list_colls {
Subroutine _legacy_list_colls: not called CC=2 SCAR=17.9
137 0 my ( $self, $link, $topology ) = @_;
138  
139 0 ▶ my $op = MongoDB::Op::_Query->_new(
Condition0%0/3
$self->read_preference || 'MongoDB::ReadPreference'->new
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
140 filter => $self->filter,
141 options => MongoDB::Op::_Query->precondition_options($self->options),
142 db_name => $self->db_name,
143 coll_name => 'system.namespaces',
144 full_name => $self->db_name . ".system.namespaces",
145 bson_codec => $self->bson_codec,
146 client => $self->client,
147 read_preference => $self->read_preference || MongoDB::ReadPreference->new,
148 read_concern => MongoDB::ReadConcern->new,
149 post_filter => \&__filter_legacy_names,
150 monitoring_callback => $self->monitoring_callback,
151 );
152  
153 0 return $op->execute( $link, $topology );
154 }
155  
156 # exclude names with '$' except oplog.$
157 # XXX why do we include oplog.$?
158 0 ▶sub __filter_legacy_names {
Subroutine __filter_legacy_names: not called CC=2 SCAR=17.9
159 0 my $doc = shift;
160 # remove leading database name for compatibility with listCollections
161 0 $doc->{name} =~ s/^[^.]+\.//;
162 0 my $name = $doc->{name};
163 0 ▶ return !( index( $name, '$' ) >= 0 && index( $name, '.oplog.$' ) < 0 );
Condition0%0/3
index($name, '$') != -1 && index($name, '.oplog.$') == -1
!ll&&!rl&&r
000
MC/DC0%0/2
index($name, '$') != -1 && index($name, '.oplog.$') == -1
index($name, '$') != -1 index($name, '.oplog.$') == -1
Truth table0%0/3
A && B
A= index($name, '$') != -1B= index($name, '.oplog.$') == -1
ABresult
0X0
100
111
164 }
165  
166 59 1;
« MongoDB/Role/_TopologyMonitoring.pm ↑ Summary MongoDB/Op/_GetMore.pm »