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
|
|
234252
|
use strict; |
|
60
|
|
|
|
|
159
|
|
|
60
|
|
|
|
|
1756
|
|
16
|
60
|
|
|
60
|
|
298
|
use warnings; |
|
60
|
|
|
|
|
117
|
|
|
60
|
|
|
|
|
2273
|
|
17
|
|
|
|
|
|
|
package MongoDB::Role::_UpdatePreEncoder; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# MongoDB interface for pre-encoding and validating update/replace docs |
20
|
|
|
|
|
|
|
|
21
|
60
|
|
|
60
|
|
309
|
use version; |
|
60
|
|
|
|
|
112
|
|
|
60
|
|
|
|
|
409
|
|
22
|
|
|
|
|
|
|
our $VERSION = 'v2.2.2'; |
23
|
|
|
|
|
|
|
|
24
|
60
|
|
|
60
|
|
4524
|
use Moo::Role; |
|
60
|
|
|
|
|
154
|
|
|
60
|
|
|
|
|
438
|
|
25
|
|
|
|
|
|
|
|
26
|
60
|
|
|
60
|
|
19348
|
use BSON::Raw; |
|
60
|
|
|
|
|
163
|
|
|
60
|
|
|
|
|
1833
|
|
27
|
60
|
|
|
60
|
|
372
|
use BSON::Types 'bson_array'; |
|
60
|
|
|
|
|
141
|
|
|
60
|
|
|
|
|
5358
|
|
28
|
60
|
|
|
60
|
|
842
|
use MongoDB::Error; |
|
60
|
|
|
|
|
125
|
|
|
60
|
|
|
|
|
6098
|
|
29
|
60
|
|
|
60
|
|
394
|
use MongoDB::_Constants; |
|
60
|
|
|
|
|
122
|
|
|
60
|
|
|
|
|
6518
|
|
30
|
|
|
|
|
|
|
|
31
|
60
|
|
|
60
|
|
410
|
use namespace::clean; |
|
60
|
|
|
|
|
129
|
|
|
60
|
|
|
|
|
631
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
requires qw/bson_codec/; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _pre_encode_update { |
36
|
1
|
|
|
1
|
|
3019
|
my ( $self, $max_bson_object_size, $doc, $is_replace ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
3
|
my $type = ref($doc); |
39
|
1
|
|
|
|
|
1
|
my $bson_doc; |
40
|
|
|
|
|
|
|
|
41
|
1
|
50
|
33
|
|
|
8
|
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
|
|
|
|
19
|
$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
|
|
|
|
|
85
|
my ( $len, undef, $first_char ) = unpack( P_INT32 . "CZ", $bson_doc ); |
67
|
1
|
50
|
|
|
|
7
|
if ( $len >= MIN_KEYED_DOC_LENGTH ) { |
|
|
0
|
|
|
|
|
|
68
|
1
|
|
|
|
|
3
|
my $err; |
69
|
1
|
50
|
|
|
|
2
|
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
|
|
|
|
4
|
$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
|
|
|
|
|
6
|
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: |