| 1 | # Copyright 2015 - 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::_Distinct; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # Encapsulate distinct operation; return MongoDB::QueryResult | ||||||||||||||||||||||||||||
| 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::Op::_Command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 59 | ▶ | use MongoDB::_Types qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | Document | ||||||||||||||||||||||||||||
| 29 | 59 | ); | |||||||||||||||||||||||||||
| 30 | 59 | ▶ | use Types::Standard qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | InstanceOf | ||||||||||||||||||||||||||||
| 32 | HashRef | ||||||||||||||||||||||||||||
| 33 | Str | ||||||||||||||||||||||||||||
| 34 | 59 | ); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 59 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 59 | has client => ( | |||||||||||||||||||||||||||
| 39 | is => 'ro', | ||||||||||||||||||||||||||||
| 40 | required => 1, | ||||||||||||||||||||||||||||
| 41 | isa => InstanceOf ['MongoDB::MongoClient'], | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 59 | has fieldname=> ( | |||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||
| 46 | required => 1, | ||||||||||||||||||||||||||||
| 47 | isa => Str, | ||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 59 | has filter => ( | |||||||||||||||||||||||||||
| 51 | is => 'ro', | ||||||||||||||||||||||||||||
| 52 | required => 1, | ||||||||||||||||||||||||||||
| 53 | isa => Document, | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 59 | has options => ( | |||||||||||||||||||||||||||
| 57 | is => 'ro', | ||||||||||||||||||||||||||||
| 58 | required => 1, | ||||||||||||||||||||||||||||
| 59 | isa => HashRef, | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 59 | with $_ for qw( | |||||||||||||||||||||||||||
| 63 | MongoDB::Role::_PrivateConstructor | ||||||||||||||||||||||||||||
| 64 | MongoDB::Role::_CollectionOp | ||||||||||||||||||||||||||||
| 65 | MongoDB::Role::_ReadOp | ||||||||||||||||||||||||||||
| 66 | MongoDB::Role::_CommandCursorOp | ||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 70 | 0 | my ( $self, $link, $topology ) = @_; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | my $options = $self->options; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( defined $options->{collation} and !$link->supports_collation ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $options->{"collation"} and not $link->supports_collation
MC/DC0%0/2
defined $options->{"collation"} and not $link->supports_collation
defined $options->{"collation"}
not $link->supports_collation
Truth table0%0/3
A and not(B)
A= defined $options->{"collation"}B= not $link->supports_collation
| |||||||||||||||||||||||||||||
| 75 | 0 | MongoDB::UsageError->throw( | |||||||||||||||||||||||||||
| 76 | "MongoDB host '" . $link->address . "' doesn't support collation" ); | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | my $filter = | ||||||||||||||||||||||||||||
| 80 | ref( $self->filter ) eq 'ARRAY' | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | ? { @{ $self->filter } } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | : $self->filter; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | my @command = ( | ||||||||||||||||||||||||||||
| 85 | distinct => $self->coll_name, | ||||||||||||||||||||||||||||
| 86 | key => $self->fieldname, | ||||||||||||||||||||||||||||
| 87 | query => $filter, | ||||||||||||||||||||||||||||
| 88 | ($link->supports_read_concern ? | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | @{ $self->read_concern->as_args( $self->session) } : ()), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | %$options | ||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | my $op = MongoDB::Op::_Command->_new( | |||||||||||||||||||||||||||
| 94 | db_name => $self->db_name, | ||||||||||||||||||||||||||||
| 95 | query => Tie::IxHash->new(@command), | ||||||||||||||||||||||||||||
| 96 | query_flags => {}, | ||||||||||||||||||||||||||||
| 97 | read_preference => $self->read_preference, | ||||||||||||||||||||||||||||
| 98 | bson_codec => $self->bson_codec, | ||||||||||||||||||||||||||||
| 99 | session => $self->session, | ||||||||||||||||||||||||||||
| 100 | monitoring_callback => $self->monitoring_callback, | ||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | my $res = $op->execute( $link, $topology ); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | $res->output->{cursor} = { | ||||||||||||||||||||||||||||
| 106 | ns => '', | ||||||||||||||||||||||||||||
| 107 | id => 0, | ||||||||||||||||||||||||||||
| 108 | 0 | ▶ | firstBatch => ( delete $res->output->{values} ) || [], | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $res->output->{'values'} || []
MC/DC0%0/1
delete $res->output->{'values'} || []
delete $res->output->{'values'}
Truth table0%0/2
A
A= delete $res->output->{'values'}
| |||||||||||||||||||||||||||||
| 109 | }; | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | return $self->_build_result_from_cursor($res); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 59 | 1; | |||||||||||||||||||||||||||