line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
71
|
|
|
71
|
|
25158
|
use 5.010001; |
|
71
|
|
|
|
|
226
|
|
2
|
71
|
|
|
71
|
|
316
|
use strict; |
|
71
|
|
|
|
|
107
|
|
|
71
|
|
|
|
|
1238
|
|
3
|
71
|
|
|
71
|
|
286
|
use warnings; |
|
71
|
|
|
|
|
109
|
|
|
71
|
|
|
|
|
2159
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package BSON::Code; |
6
|
|
|
|
|
|
|
# ABSTRACT: BSON type wrapper for Javascript code |
7
|
|
|
|
|
|
|
|
8
|
71
|
|
|
71
|
|
389
|
use version; |
|
71
|
|
|
|
|
146
|
|
|
71
|
|
|
|
|
286
|
|
9
|
|
|
|
|
|
|
our $VERSION = 'v1.12.0'; |
10
|
|
|
|
|
|
|
|
11
|
71
|
|
|
71
|
|
4956
|
use Carp (); |
|
71
|
|
|
|
|
187
|
|
|
71
|
|
|
|
|
1229
|
|
12
|
71
|
|
|
71
|
|
313
|
use Tie::IxHash; |
|
71
|
|
|
|
|
139
|
|
|
71
|
|
|
|
|
1746
|
|
13
|
|
|
|
|
|
|
|
14
|
71
|
|
|
71
|
|
400
|
use Moo; |
|
71
|
|
|
|
|
150
|
|
|
71
|
|
|
|
|
350
|
|
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
|
|
22063
|
use namespace::clean -except => 'meta'; |
|
71
|
|
|
|
|
135
|
|
|
71
|
|
|
|
|
475
|
|
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
|
17232
|
|
|
17232
|
0
|
372089
|
my ($class) = shift; |
46
|
|
|
|
|
|
|
|
47
|
17232
|
|
|
|
|
19945
|
my %args; |
48
|
17232
|
100
|
100
|
|
|
62192
|
if ( @_ && $_[0] !~ /^[c|s]/ ) { |
49
|
8398
|
|
|
|
|
14109
|
$args{code} = $_[0]; |
50
|
8398
|
100
|
|
|
|
16926
|
$args{scope} = $_[1] if defined $_[1]; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
8834
|
50
|
|
|
|
17731
|
Carp::croak( __PACKAGE__ . "::new called with an odd number of elements\n" ) |
54
|
|
|
|
|
|
|
unless @_ % 2 == 0; |
55
|
8834
|
|
|
|
|
20322
|
%args = @_; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
17232
|
|
|
|
|
236216
|
return \%args; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub BUILD { |
62
|
17232
|
|
|
17232
|
0
|
142483
|
my ($self) = @_; |
63
|
17232
|
100
|
|
|
|
33526
|
$self->{code} = '' unless defined $self->{code}; |
64
|
|
|
|
|
|
|
Carp::croak( __PACKAGE__ . " scope must be hash reference, not $self->{scope}") |
65
|
17232
|
50
|
66
|
|
|
51191
|
if exists($self->{scope}) && ref($self->{scope}) ne 'HASH'; |
66
|
17232
|
|
|
|
|
60493
|
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
|
253
|
require BSON; |
85
|
23
|
100
|
|
|
|
53
|
if ( $ENV{BSON_EXTJSON} ) { |
86
|
22
|
|
|
|
|
28
|
my %data; |
87
|
22
|
|
|
|
|
66
|
tie( %data, 'Tie::IxHash' ); |
88
|
22
|
|
|
|
|
310
|
$data{'$code'} = $_[0]->{code}; |
89
|
|
|
|
|
|
|
$data{'$scope'} = BSON->perl_to_extjson($_[0]->{scope}) |
90
|
22
|
100
|
|
|
|
321
|
if defined $_[0]->{scope}; |
91
|
22
|
|
|
|
|
179
|
return \%data; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
160
|
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.0 |
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__ |