| 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::BulkWriteView; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # ABSTRACT: Bulk write operations against a query document | ||||||||||||||||||||||||||||
| 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::Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 59 | ▶ | use MongoDB::_Types qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | Boolish | ||||||||||||||||||||||||||||
| 29 | Document | ||||||||||||||||||||||||||||
| 30 | IxHash | ||||||||||||||||||||||||||||
| 31 | 59 | ); | |||||||||||||||||||||||||||
| 32 | 59 | ▶ | use Types::Standard qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | Maybe | ||||||||||||||||||||||||||||
| 34 | ArrayRef | ||||||||||||||||||||||||||||
| 35 | InstanceOf | ||||||||||||||||||||||||||||
| 36 | 59 | ); | |||||||||||||||||||||||||||
| 37 | 59 | ▶ | use boolean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 59 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # A hash reference containing a MongoDB query document | ||||||||||||||||||||||||||||
| 41 | 59 | has _query => ( | |||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||
| 43 | isa => IxHash, | ||||||||||||||||||||||||||||
| 44 | coerce => IxHash->coercion, | ||||||||||||||||||||||||||||
| 45 | required => 1 | ||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # Originating bulk write object for executing write operations. | ||||||||||||||||||||||||||||
| 49 | 59 | has _bulk => ( | |||||||||||||||||||||||||||
| 50 | is => 'ro', | ||||||||||||||||||||||||||||
| 51 | isa => InstanceOf['MongoDB::BulkWrite'], | ||||||||||||||||||||||||||||
| 52 | required => 1, | ||||||||||||||||||||||||||||
| 53 | handles => [qw/_enqueue_write/] | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 59 | has _collation => ( | |||||||||||||||||||||||||||
| 57 | is => 'ro', | ||||||||||||||||||||||||||||
| 58 | isa => Maybe [Document], | ||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 59 | has _array_filters => ( | |||||||||||||||||||||||||||
| 62 | is => 'ro', | ||||||||||||||||||||||||||||
| 63 | isa => Maybe [ArrayRef[Document]], | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 59 | has _upsert => ( | |||||||||||||||||||||||||||
| 67 | is => 'ro', | ||||||||||||||||||||||||||||
| 68 | isa => Boolish, | ||||||||||||||||||||||||||||
| 69 | default => 0, | ||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub collation { | ||||||||||||||||||||||||||
|
Subroutine
collation: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 0 | my ($self, $collation) = @_; | |||||||||||||||||||||||||||
| 74 | 0 | return $self->new( %$self, _collation => $collation ); | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub arrayFilters { | ||||||||||||||||||||||||||
|
Subroutine
arrayFilters: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 0 | my ( $self, $array_filters ) = @_; | |||||||||||||||||||||||||||
| 79 | 0 | return $self->new( %$self, _array_filters => $array_filters ); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub upsert { | ||||||||||||||||||||||||||
|
Subroutine
upsert: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | unless ( @_ == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | MongoDB::UsageError->throw("the upsert method takes no arguments"); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 0 | return $self->new( %$self, _upsert => true ); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub update_many { | ||||||||||||||||||||||||||
|
Subroutine
update_many: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 0 | push @_, "update_many"; | |||||||||||||||||||||||||||
| 92 | 0 | goto &_update; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub update_one { | ||||||||||||||||||||||||||
|
Subroutine
update_one: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 0 | push @_, "update_one"; | |||||||||||||||||||||||||||
| 97 | 0 | goto &_update; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub replace_one { | ||||||||||||||||||||||||||
|
Subroutine
replace_one: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | 0 | push @_, "replace_one"; | |||||||||||||||||||||||||||
| 102 | 0 | goto &_update; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub _update { | ||||||||||||||||||||||||||
|
Subroutine
_update: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 106 | 0 | my $method = pop @_; | |||||||||||||||||||||||||||
| 107 | 0 | my ( $self, $doc ) = @_; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | my $type = ref $doc; | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | unless ( @_ == 2 && grep { $type eq $_ } qw/HASH ARRAY Tie::IxHash BSON::Array/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 2 and grep {$type eq $_;} "HASH", "ARRAY", "Tie::IxHash", "BSON::Array"
MC/DC0%0/2
@_ == 2 and grep {$type eq $_;} "HASH", "ARRAY", "Tie::IxHash", "BSON::Array"
@_ == 2
grep {$type eq $_;} "HASH", "ARRAY", "Tie::IxHash", "BSON::Array"
Truth table0%0/3
A and B
A= @_ == 2B= grep {$type eq $_;} "HASH", "ARRAY", "Tie::IxHash", "BSON::Array"
| |||||||||||||||||||||||||||||
| 111 | 0 | MongoDB::UsageError->throw("argument to $method must be a single hashref, arrayref, Tie::IxHash or BSON::Array"); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ( ref $doc eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | MongoDB::UsageError->throw("array reference to $method must have key/value pairs") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | if @$doc % 2; | ||||||||||||||||||||||||||||
| 117 | 0 | $doc = Tie::IxHash->new(@$doc); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | elsif ( ref $doc eq 'HASH' ) { | ||||||||||||||||||||||||||||
| 120 | 0 | $doc = Tie::IxHash->new(%$doc); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $self->_bulk->_retryable( 0 ) if $method eq 'update_many'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | my $update = { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 126 | q => $self->_query, | ||||||||||||||||||||||||||||
| 127 | u => $doc, | ||||||||||||||||||||||||||||
| 128 | multi => $method eq 'update_many' ? true : false, | ||||||||||||||||||||||||||||
| 129 | upsert => boolean( $self->_upsert ), | ||||||||||||||||||||||||||||
| 130 | is_replace => $method eq 'replace_one', | ||||||||||||||||||||||||||||
| 131 | (defined $self->_collation ? (collation => $self->_collation) : ()), | ||||||||||||||||||||||||||||
| 132 | (defined $self->_array_filters ? (arrayFilters => $self->_array_filters) : ()), | ||||||||||||||||||||||||||||
| 133 | }; | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | $self->_enqueue_write( [ update => $update ] ); | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | return; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub delete_many { | ||||||||||||||||||||||||||
|
Subroutine
delete_many: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 142 | 0 | $self->_bulk->_retryable( 0 ); | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | $self->_enqueue_write( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 144 | [ | ||||||||||||||||||||||||||||
| 145 | delete => { | ||||||||||||||||||||||||||||
| 146 | q => $self->_query, | ||||||||||||||||||||||||||||
| 147 | limit => 0, | ||||||||||||||||||||||||||||
| 148 | ( defined $self->_collation ? ( collation => $self->_collation ) : () ), | ||||||||||||||||||||||||||||
| 149 | (defined $self->_array_filters ? (arrayFilters => $self->_array_filters) : ()), | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | ] | ||||||||||||||||||||||||||||
| 152 | ); | ||||||||||||||||||||||||||||
| 153 | 0 | return; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub delete_one { | ||||||||||||||||||||||||||
|
Subroutine
delete_one: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 158 | 0 | ▶ | $self->_enqueue_write( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 159 | [ | ||||||||||||||||||||||||||||
| 160 | delete => { | ||||||||||||||||||||||||||||
| 161 | q => $self->_query, | ||||||||||||||||||||||||||||
| 162 | limit => 1, | ||||||||||||||||||||||||||||
| 163 | ( defined $self->_collation ? ( collation => $self->_collation ) : () ), | ||||||||||||||||||||||||||||
| 164 | (defined $self->_array_filters ? (arrayFilters => $self->_array_filters) : ()), | ||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | ] | ||||||||||||||||||||||||||||
| 167 | ); | ||||||||||||||||||||||||||||
| 168 | 0 | return; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 59 | 1; | |||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | __END__ | ||||||||||||||||||||||||||||