line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
60
|
|
|
60
|
|
131394
|
use strict; |
|
60
|
|
|
|
|
164
|
|
|
60
|
|
|
|
|
2036
|
|
16
|
60
|
|
|
60
|
|
360
|
use warnings; |
|
60
|
|
|
|
|
149
|
|
|
60
|
|
|
|
|
2349
|
|
17
|
|
|
|
|
|
|
package MongoDB::Role::_InsertPreEncoder; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# MongoDB interface for pre-encoding and validating docs to insert |
20
|
|
|
|
|
|
|
|
21
|
60
|
|
|
60
|
|
360
|
use version; |
|
60
|
|
|
|
|
165
|
|
|
60
|
|
|
|
|
393
|
|
22
|
|
|
|
|
|
|
our $VERSION = 'v2.2.1'; |
23
|
|
|
|
|
|
|
|
24
|
60
|
|
|
60
|
|
5130
|
use Moo::Role; |
|
60
|
|
|
|
|
147
|
|
|
60
|
|
|
|
|
408
|
|
25
|
|
|
|
|
|
|
|
26
|
60
|
|
|
60
|
|
19937
|
use BSON::Raw; |
|
60
|
|
|
|
|
161
|
|
|
60
|
|
|
|
|
1457
|
|
27
|
60
|
|
|
60
|
|
385
|
use BSON::OID; |
|
60
|
|
|
|
|
169
|
|
|
60
|
|
|
|
|
1394
|
|
28
|
|
|
|
|
|
|
|
29
|
60
|
|
|
60
|
|
348
|
use namespace::clean; |
|
60
|
|
|
|
|
142
|
|
|
60
|
|
|
|
|
403
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
requires qw/bson_codec/; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# takes MongoDB::_Link and ref of type Document; returns |
34
|
|
|
|
|
|
|
# blessed BSON encode doc and the original/generated _id |
35
|
|
|
|
|
|
|
sub _pre_encode_insert { |
36
|
2
|
|
|
2
|
|
12311
|
my ( $self, $max_bson_size, $doc, $invalid_chars ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
5
|
my $type = ref($doc); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $id = ( |
41
|
|
|
|
|
|
|
$type eq 'HASH' ? $doc->{_id} |
42
|
|
|
|
|
|
|
: $type eq 'ARRAY' || $type eq 'BSON::Doc' ? do { |
43
|
0
|
|
|
|
|
0
|
my $i; |
44
|
0
|
0
|
|
|
|
0
|
for ( $i = 0; $i < @$doc; $i++ ) { last if $doc->[$i] eq '_id' } |
|
0
|
|
|
|
|
0
|
|
45
|
0
|
0
|
|
|
|
0
|
$i < $#$doc ? $doc->[ $i + 1 ] : undef; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
: $type eq 'Tie::IxHash' ? $doc->FETCH('_id') |
48
|
|
|
|
|
|
|
: $type eq 'BSON::Raw' ? do { |
49
|
2
|
|
|
|
|
13
|
my $decoded_doc = $self->bson_codec->decode_one( |
50
|
|
|
|
|
|
|
$doc->bson, |
51
|
|
|
|
|
|
|
{ ordered => 1 } |
52
|
|
|
|
|
|
|
); |
53
|
2
|
|
|
|
|
214
|
$decoded_doc->{_id}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
: $doc->{_id} # hashlike? |
56
|
2
|
50
|
33
|
|
|
20
|
); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
57
|
2
|
100
|
|
|
|
22
|
if ( ! defined $id ) { |
58
|
1
|
|
|
|
|
6
|
my $creator = $self->bson_codec->can("create_oid"); |
59
|
1
|
50
|
|
|
|
8
|
$id = $creator ? $creator->() : BSON::OID->new(); |
60
|
|
|
|
|
|
|
} |
61
|
2
|
|
|
|
|
1326
|
my $bson_doc = $self->bson_codec->encode_one( |
62
|
|
|
|
|
|
|
$doc, |
63
|
|
|
|
|
|
|
{ |
64
|
|
|
|
|
|
|
invalid_chars => $invalid_chars, |
65
|
|
|
|
|
|
|
max_length => $max_bson_size, |
66
|
|
|
|
|
|
|
first_key => '_id', |
67
|
|
|
|
|
|
|
first_value => $id, |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# manually bless for speed |
72
|
2
|
|
|
|
|
72
|
return bless { bson => $bson_doc, metadata => { _id => $id } }, |
73
|
|
|
|
|
|
|
"BSON::Raw"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# vim: set ts=4 sts=4 sw=4 et tw=75: |