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
|
|
132857
|
use strict; |
|
60
|
|
|
|
|
136
|
|
|
60
|
|
|
|
|
1938
|
|
16
|
60
|
|
|
60
|
|
305
|
use warnings; |
|
60
|
|
|
|
|
118
|
|
|
60
|
|
|
|
|
2285
|
|
17
|
|
|
|
|
|
|
package MongoDB::Role::_InsertPreEncoder; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# MongoDB interface for pre-encoding and validating docs to insert |
20
|
|
|
|
|
|
|
|
21
|
60
|
|
|
60
|
|
296
|
use version; |
|
60
|
|
|
|
|
130
|
|
|
60
|
|
|
|
|
407
|
|
22
|
|
|
|
|
|
|
our $VERSION = 'v2.2.2'; |
23
|
|
|
|
|
|
|
|
24
|
60
|
|
|
60
|
|
4429
|
use Moo::Role; |
|
60
|
|
|
|
|
125
|
|
|
60
|
|
|
|
|
367
|
|
25
|
|
|
|
|
|
|
|
26
|
60
|
|
|
60
|
|
18099
|
use BSON::Raw; |
|
60
|
|
|
|
|
125
|
|
|
60
|
|
|
|
|
1309
|
|
27
|
60
|
|
|
60
|
|
308
|
use BSON::OID; |
|
60
|
|
|
|
|
137
|
|
|
60
|
|
|
|
|
1289
|
|
28
|
|
|
|
|
|
|
|
29
|
60
|
|
|
60
|
|
347
|
use namespace::clean; |
|
60
|
|
|
|
|
128
|
|
|
60
|
|
|
|
|
427
|
|
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
|
|
9359
|
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
|
|
|
|
|
14
|
my $decoded_doc = $self->bson_codec->decode_one( |
50
|
|
|
|
|
|
|
$doc->bson, |
51
|
|
|
|
|
|
|
{ ordered => 1 } |
52
|
|
|
|
|
|
|
); |
53
|
2
|
|
|
|
|
182
|
$decoded_doc->{_id}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
: $doc->{_id} # hashlike? |
56
|
2
|
50
|
33
|
|
|
18
|
); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
57
|
2
|
100
|
|
|
|
20
|
if ( ! defined $id ) { |
58
|
1
|
|
|
|
|
6
|
my $creator = $self->bson_codec->can("create_oid"); |
59
|
1
|
50
|
|
|
|
4
|
$id = $creator ? $creator->() : BSON::OID->new(); |
60
|
|
|
|
|
|
|
} |
61
|
2
|
|
|
|
|
1021
|
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
|
|
|
|
|
59
|
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: |