| 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
|
|
259054
|
use strict; |
|
|
60
|
|
|
|
|
197
|
|
|
|
60
|
|
|
|
|
1977
|
|
|
16
|
60
|
|
|
60
|
|
349
|
use warnings; |
|
|
60
|
|
|
|
|
194
|
|
|
|
60
|
|
|
|
|
2473
|
|
|
17
|
|
|
|
|
|
|
package MongoDB::Role::_UpdatePreEncoder; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# MongoDB interface for pre-encoding and validating update/replace docs |
|
20
|
|
|
|
|
|
|
|
|
21
|
60
|
|
|
60
|
|
348
|
use version; |
|
|
60
|
|
|
|
|
129
|
|
|
|
60
|
|
|
|
|
391
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = 'v2.2.1'; |
|
23
|
|
|
|
|
|
|
|
|
24
|
60
|
|
|
60
|
|
5201
|
use Moo::Role; |
|
|
60
|
|
|
|
|
167
|
|
|
|
60
|
|
|
|
|
419
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
60
|
|
|
60
|
|
20966
|
use BSON::Raw; |
|
|
60
|
|
|
|
|
195
|
|
|
|
60
|
|
|
|
|
1971
|
|
|
27
|
60
|
|
|
60
|
|
431
|
use BSON::Types 'bson_array'; |
|
|
60
|
|
|
|
|
167
|
|
|
|
60
|
|
|
|
|
5433
|
|
|
28
|
60
|
|
|
60
|
|
1034
|
use MongoDB::Error; |
|
|
60
|
|
|
|
|
198
|
|
|
|
60
|
|
|
|
|
6808
|
|
|
29
|
60
|
|
|
60
|
|
456
|
use MongoDB::_Constants; |
|
|
60
|
|
|
|
|
143
|
|
|
|
60
|
|
|
|
|
6929
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
60
|
|
|
60
|
|
474
|
use namespace::clean; |
|
|
60
|
|
|
|
|
149
|
|
|
|
60
|
|
|
|
|
418
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
requires qw/bson_codec/; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _pre_encode_update { |
|
36
|
1
|
|
|
1
|
|
3403
|
my ( $self, $max_bson_object_size, $doc, $is_replace ) = @_; |
|
37
|
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
4
|
my $type = ref($doc); |
|
39
|
1
|
|
|
|
|
1
|
my $bson_doc; |
|
40
|
|
|
|
|
|
|
|
|
41
|
1
|
50
|
33
|
|
|
7
|
if ( $type eq 'BSON::Raw' ) { |
|
|
|
50
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
$bson_doc = $doc->bson; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
elsif ($type eq 'BSON::Array' && !$is_replace) { |
|
45
|
0
|
|
|
|
|
0
|
return $doc; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
else { |
|
48
|
1
|
50
|
50
|
|
|
4
|
if ($type eq 'ARRAY' && scalar(@$doc) && ref($doc->[0]) && !$is_replace) { |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
return bson_array(@$doc); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
else { |
|
52
|
1
|
50
|
|
|
|
8
|
$bson_doc = $self->bson_codec->encode_one( |
|
|
|
50
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$doc, |
|
54
|
|
|
|
|
|
|
{ |
|
55
|
|
|
|
|
|
|
invalid_chars => $is_replace ? '.' : '', |
|
56
|
|
|
|
|
|
|
max_length => $is_replace ? $max_bson_object_size : undef, |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# must check if first character of first key is valid for replace/update; |
|
63
|
|
|
|
|
|
|
# do this from BSON to get key *after* op_char replacment; |
|
64
|
|
|
|
|
|
|
# only need to validate if length is enough for a document with a key |
|
65
|
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
94
|
my ( $len, undef, $first_char ) = unpack( P_INT32 . "CZ", $bson_doc ); |
|
67
|
1
|
50
|
|
|
|
7
|
if ( $len >= MIN_KEYED_DOC_LENGTH ) { |
|
|
|
0
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
2
|
my $err; |
|
69
|
1
|
50
|
|
|
|
3
|
if ($is_replace) { |
|
70
|
0
|
0
|
|
|
|
0
|
$err = "replacement document must not contain update operators" |
|
71
|
|
|
|
|
|
|
if $first_char eq '$'; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
else { |
|
74
|
1
|
50
|
|
|
|
6
|
$err = "update document must only contain update operators" |
|
75
|
|
|
|
|
|
|
if $first_char ne '$'; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
1
|
50
|
|
|
|
5
|
MongoDB::DocumentError->throw( |
|
79
|
|
|
|
|
|
|
message => $err, |
|
80
|
|
|
|
|
|
|
document => $doc, |
|
81
|
|
|
|
|
|
|
) if $err; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
elsif ( ! $is_replace ) { |
|
84
|
0
|
|
|
|
|
0
|
MongoDB::DocumentError->throw( |
|
85
|
|
|
|
|
|
|
message => "Update document was empty!", |
|
86
|
|
|
|
|
|
|
document => $doc, |
|
87
|
|
|
|
|
|
|
); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
1
|
50
|
|
|
|
3
|
return $doc if $type eq 'BSON::Raw'; |
|
91
|
|
|
|
|
|
|
# manually bless for speed |
|
92
|
1
|
|
|
|
|
5
|
return bless { bson => $bson_doc, metadata => {} }, "BSON::Raw"; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# vim: set ts=4 sts=4 sw=4 et tw=75: |