| 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
|
59
|
|
|
59
|
|
127862
|
use strict; |
|
|
59
|
|
|
|
|
163
|
|
|
|
59
|
|
|
|
|
2063
|
|
|
16
|
59
|
|
|
59
|
|
342
|
use warnings; |
|
|
59
|
|
|
|
|
139
|
|
|
|
59
|
|
|
|
|
2760
|
|
|
17
|
|
|
|
|
|
|
package MongoDB::Role::_InsertPreEncoder; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# MongoDB interface for pre-encoding and validating docs to insert |
|
20
|
|
|
|
|
|
|
|
|
21
|
59
|
|
|
59
|
|
362
|
use version; |
|
|
59
|
|
|
|
|
148
|
|
|
|
59
|
|
|
|
|
394
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = 'v2.2.0'; |
|
23
|
|
|
|
|
|
|
|
|
24
|
59
|
|
|
59
|
|
4940
|
use Moo::Role; |
|
|
59
|
|
|
|
|
149
|
|
|
|
59
|
|
|
|
|
404
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
59
|
|
|
59
|
|
20470
|
use BSON::Raw; |
|
|
59
|
|
|
|
|
162
|
|
|
|
59
|
|
|
|
|
1579
|
|
|
27
|
59
|
|
|
59
|
|
334
|
use BSON::OID; |
|
|
59
|
|
|
|
|
136
|
|
|
|
59
|
|
|
|
|
1489
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
59
|
|
|
59
|
|
366
|
use namespace::clean; |
|
|
59
|
|
|
|
|
133
|
|
|
|
59
|
|
|
|
|
414
|
|
|
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
|
|
10830
|
my ( $self, $max_bson_size, $doc, $invalid_chars ) = @_; |
|
37
|
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
7
|
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
|
|
|
|
|
182
|
$decoded_doc->{_id}; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
: $doc->{_id} # hashlike? |
|
56
|
2
|
50
|
33
|
|
|
19
|
); |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
57
|
2
|
100
|
|
|
|
22
|
if ( ! defined $id ) { |
|
58
|
1
|
|
|
|
|
7
|
my $creator = $self->bson_codec->can("create_oid"); |
|
59
|
1
|
50
|
|
|
|
6
|
$id = $creator ? $creator->() : BSON::OID->new(); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
2
|
|
|
|
|
1160
|
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
|
|
|
|
|
73
|
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: |