| 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::_InsertOne; | ||||||||||
| 18 | |||||||||||
| 19 | # Encapsulate a single-document insert operation; returns a | ||||||||||
| 20 | # MongoDB::InsertOneResult | ||||||||||
| 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::InsertOneResult; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 59 | ▶ | use MongoDB::_Protocol; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 59 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | 59 | has document => ( | |||||||||
| 34 | is => 'ro', | ||||||||||
| 35 | required => 1, | ||||||||||
| 36 | ); | ||||||||||
| 37 | |||||||||||
| 38 | # this starts undef and gets initialized during processing | ||||||||||
| 39 | 59 | has _doc_id => ( | |||||||||
| 40 | is => 'ro', | ||||||||||
| 41 | init_arg => undef, | ||||||||||
| 42 | writer => '_set_doc_id', | ||||||||||
| 43 | ); | ||||||||||
| 44 | |||||||||||
| 45 | 59 | with $_ for qw( | |||||||||
| 46 | MongoDB::Role::_PrivateConstructor | ||||||||||
| 47 | MongoDB::Role::_CollectionOp | ||||||||||
| 48 | MongoDB::Role::_SingleBatchDocWrite | ||||||||||
| 49 | MongoDB::Role::_InsertPreEncoder | ||||||||||
| 50 | MongoDB::Role::_BypassValidation | ||||||||||
| 51 | ); | ||||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 54 | 0 | my ( $self, $link ) = @_; | |||||||||
| 55 | 0 | my ( $orig_doc, $insert_doc ) = ( $self->document ); | |||||||||
| 56 | |||||||||||
| 57 | ( $insert_doc = $self->_pre_encode_insert( $link->max_bson_object_size, $orig_doc, '.' ) ), | ||||||||||
| 58 | 0 | ( $self->_set_doc_id( $insert_doc->{metadata}{_id} ) ); | |||||||||
| 59 | |||||||||||
| 60 | return $self->_send_legacy_op_noreply( $link, | ||||||||||
| 61 | 0 | ▶ | MongoDB::_Protocol::write_insert( $self->full_name, $insert_doc->{bson} ), | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | $orig_doc, "MongoDB::UnacknowledgedResult", "insert" ) | ||||||||||
| 63 | if ! $self->_should_use_acknowledged_write; | ||||||||||
| 64 | |||||||||||
| 65 | return $self->_send_write_command( | ||||||||||
| 66 | $link, | ||||||||||
| 67 | $self->_maybe_bypass( | ||||||||||
| 68 | $link->supports_document_validation, | ||||||||||
| 69 | [ | ||||||||||
| 70 | insert => $self->coll_name, | ||||||||||
| 71 | documents => [$insert_doc], | ||||||||||
| 72 | 0 | ▶ | @{ $self->write_concern->as_args }, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | ] | ||||||||||
| 74 | ), | ||||||||||
| 75 | $orig_doc, | ||||||||||
| 76 | "MongoDB::InsertOneResult" | ||||||||||
| 77 | )->assert | ||||||||||
| 78 | if $link->supports_write_commands; | ||||||||||
| 79 | |||||||||||
| 80 | return $self->_send_legacy_op_with_gle( $link, | ||||||||||
| 81 | 0 | MongoDB::_Protocol::write_insert( $self->full_name, $insert_doc->{bson} ), | |||||||||
| 82 | $orig_doc, "MongoDB::InsertOneResult", "insert" )->assert; | ||||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | 0 | ▶ | sub _parse_cmd { | ||||||||
|
Subroutine
_parse_cmd: not called CC=2 SCAR=17.9
| |||||||||||
| 86 | 0 | my ( $self, $res ) = @_; | |||||||||
| 87 | 0 | ▶ | return ( $res->{ok} ? ( inserted_id => $self->_doc_id ) : () ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 59 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 91 | 59 | ▶ | no warnings 'once'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 92 | 59 | *_parse_gle = \&_parse_cmd; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 59 | 1; | |||||||||