| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
71
|
|
|
71
|
|
28264
|
use 5.010001; |
|
|
71
|
|
|
|
|
248
|
|
|
2
|
71
|
|
|
71
|
|
337
|
use strict; |
|
|
71
|
|
|
|
|
115
|
|
|
|
71
|
|
|
|
|
1340
|
|
|
3
|
71
|
|
|
71
|
|
303
|
use warnings; |
|
|
71
|
|
|
|
|
115
|
|
|
|
71
|
|
|
|
|
2312
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package BSON::Code; |
|
6
|
|
|
|
|
|
|
# ABSTRACT: BSON type wrapper for Javascript code |
|
7
|
|
|
|
|
|
|
|
|
8
|
71
|
|
|
71
|
|
371
|
use version; |
|
|
71
|
|
|
|
|
156
|
|
|
|
71
|
|
|
|
|
325
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = 'v1.12.1'; |
|
10
|
|
|
|
|
|
|
|
|
11
|
71
|
|
|
71
|
|
5431
|
use Carp (); |
|
|
71
|
|
|
|
|
189
|
|
|
|
71
|
|
|
|
|
1319
|
|
|
12
|
71
|
|
|
71
|
|
333
|
use Tie::IxHash; |
|
|
71
|
|
|
|
|
128
|
|
|
|
71
|
|
|
|
|
1764
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
71
|
|
|
71
|
|
437
|
use Moo; |
|
|
71
|
|
|
|
|
196
|
|
|
|
71
|
|
|
|
|
407
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#pod =attr code |
|
17
|
|
|
|
|
|
|
#pod |
|
18
|
|
|
|
|
|
|
#pod A string containing Javascript code. Defaults to the empty string. |
|
19
|
|
|
|
|
|
|
#pod |
|
20
|
|
|
|
|
|
|
#pod =attr scope |
|
21
|
|
|
|
|
|
|
#pod |
|
22
|
|
|
|
|
|
|
#pod An optional hash reference containing variables in the scope of C. |
|
23
|
|
|
|
|
|
|
#pod Defaults to C. |
|
24
|
|
|
|
|
|
|
#pod |
|
25
|
|
|
|
|
|
|
#pod =cut |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has [ qw/code scope/ ] => ( |
|
28
|
|
|
|
|
|
|
is => 'ro' |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
|
|
31
|
71
|
|
|
71
|
|
23604
|
use namespace::clean -except => 'meta'; |
|
|
71
|
|
|
|
|
170
|
|
|
|
71
|
|
|
|
|
437
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#pod =method length |
|
34
|
|
|
|
|
|
|
#pod |
|
35
|
|
|
|
|
|
|
#pod Returns the length of the C attribute. |
|
36
|
|
|
|
|
|
|
#pod |
|
37
|
|
|
|
|
|
|
#pod =cut |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub length { |
|
40
|
0
|
|
|
0
|
1
|
0
|
length( $_[0]->code ); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Support legacy constructor shortcut |
|
44
|
|
|
|
|
|
|
sub BUILDARGS { |
|
45
|
18180
|
|
|
18180
|
0
|
474045
|
my ($class) = shift; |
|
46
|
|
|
|
|
|
|
|
|
47
|
18180
|
|
|
|
|
26095
|
my %args; |
|
48
|
18180
|
100
|
100
|
|
|
76549
|
if ( @_ && $_[0] !~ /^[c|s]/ ) { |
|
49
|
8836
|
|
|
|
|
21206
|
$args{code} = $_[0]; |
|
50
|
8836
|
100
|
|
|
|
20850
|
$args{scope} = $_[1] if defined $_[1]; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
else { |
|
53
|
9344
|
50
|
|
|
|
23673
|
Carp::croak( __PACKAGE__ . "::new called with an odd number of elements\n" ) |
|
54
|
|
|
|
|
|
|
unless @_ % 2 == 0; |
|
55
|
9344
|
|
|
|
|
26621
|
%args = @_; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
18180
|
|
|
|
|
296189
|
return \%args; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub BUILD { |
|
62
|
18180
|
|
|
18180
|
0
|
186594
|
my ($self) = @_; |
|
63
|
18180
|
100
|
|
|
|
39821
|
$self->{code} = '' unless defined $self->{code}; |
|
64
|
|
|
|
|
|
|
Carp::croak( __PACKAGE__ . " scope must be hash reference, not $self->{scope}") |
|
65
|
18180
|
50
|
66
|
|
|
64665
|
if exists($self->{scope}) && ref($self->{scope}) ne 'HASH'; |
|
66
|
18180
|
|
|
|
|
79212
|
return; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
#pod =method TO_JSON |
|
70
|
|
|
|
|
|
|
#pod |
|
71
|
|
|
|
|
|
|
#pod If the C option is true, returns a hashref compatible with |
|
72
|
|
|
|
|
|
|
#pod MongoDB's L |
|
73
|
|
|
|
|
|
|
#pod format, which represents it as a document as follows: |
|
74
|
|
|
|
|
|
|
#pod |
|
75
|
|
|
|
|
|
|
#pod {"$code" : ""} |
|
76
|
|
|
|
|
|
|
#pod {"$code" : "", "$scope" : { ... } } |
|
77
|
|
|
|
|
|
|
#pod |
|
78
|
|
|
|
|
|
|
#pod If the C option is false, an error is thrown, as this value |
|
79
|
|
|
|
|
|
|
#pod can't otherwise be represented in JSON. |
|
80
|
|
|
|
|
|
|
#pod |
|
81
|
|
|
|
|
|
|
#pod =cut |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub TO_JSON { |
|
84
|
23
|
|
|
23
|
1
|
266
|
require BSON; |
|
85
|
23
|
100
|
|
|
|
56
|
if ( $ENV{BSON_EXTJSON} ) { |
|
86
|
22
|
|
|
|
|
34
|
my %data; |
|
87
|
22
|
|
|
|
|
75
|
tie( %data, 'Tie::IxHash' ); |
|
88
|
22
|
|
|
|
|
353
|
$data{'$code'} = $_[0]->{code}; |
|
89
|
|
|
|
|
|
|
$data{'$scope'} = BSON->perl_to_extjson($_[0]->{scope}) |
|
90
|
22
|
100
|
|
|
|
366
|
if defined $_[0]->{scope}; |
|
91
|
22
|
|
|
|
|
213
|
return \%data; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
175
|
Carp::croak( "The value '$_[0]' is illegal in JSON" ); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=pod |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=encoding UTF-8 |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 NAME |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
BSON::Code - BSON type wrapper for Javascript code |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 VERSION |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
version v1.12.1 |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
use BSON::Types ':all'; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$code = bson_code( $javascript ); |
|
116
|
|
|
|
|
|
|
$code = bson_code( $javascript, $scope ); |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This module provides a BSON type wrapper for the "Javascript code" type |
|
121
|
|
|
|
|
|
|
and the "Javascript with Scope" BSON types. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 code |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
A string containing Javascript code. Defaults to the empty string. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 scope |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
An optional hash reference containing variables in the scope of C. |
|
132
|
|
|
|
|
|
|
Defaults to C. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 METHODS |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 length |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Returns the length of the C attribute. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 TO_JSON |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
If the C option is true, returns a hashref compatible with |
|
143
|
|
|
|
|
|
|
MongoDB's L |
|
144
|
|
|
|
|
|
|
format, which represents it as a document as follows: |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
{"$code" : ""} |
|
147
|
|
|
|
|
|
|
{"$code" : "", "$scope" : { ... } } |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
If the C option is false, an error is thrown, as this value |
|
150
|
|
|
|
|
|
|
can't otherwise be represented in JSON. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=for Pod::Coverage BUILD BUILDARGS |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 AUTHORS |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=over 4 |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
David Golden |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Stefan G. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=back |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This software is Copyright (c) 2019 by Stefan G. and MongoDB, Inc. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This is free software, licensed under: |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
__END__ |