line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
20
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
EJS::Template::JSAdapter::JavaScript::SpiderMonkey |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package EJS::Template::JSAdapter::JavaScript::SpiderMonkey; |
12
|
1
|
|
|
1
|
|
7
|
use base 'EJS::Template::JSAdapter'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
77
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
7
|
use EJS::Template::Util qw(clean_text_ref); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
15
|
1
|
|
|
1
|
|
14
|
use Scalar::Util qw(reftype); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
873
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $ENCODE_UTF8 = 0; |
18
|
|
|
|
|
|
|
our $SANITIZE_UTF8 = 0; |
19
|
|
|
|
|
|
|
our $FORCE_UNTAINT = 0; |
20
|
|
|
|
|
|
|
our $PRESERVE_UTF8 = 0; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 Methods |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head2 new |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Creates an adapter object. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new { |
31
|
1
|
|
|
1
|
1
|
3
|
my ($class) = @_; |
32
|
1
|
|
|
1
|
|
149
|
eval 'use JavaScript::SpiderMonkey'; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
63
|
|
33
|
1
|
50
|
|
|
|
10
|
die $@ if $@; |
34
|
0
|
|
|
|
|
|
my $engine = JavaScript::SpiderMonkey->new; |
35
|
0
|
|
|
|
|
|
$engine->init(); |
36
|
0
|
|
|
|
|
|
return bless {engine => $engine}, $class; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 bind |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Implements the bind method. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub bind { |
46
|
0
|
|
|
0
|
1
|
|
my ($self, $variables) = @_; |
47
|
0
|
|
|
|
|
|
my $engine = $self->engine; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $assign_value; |
50
|
|
|
|
|
|
|
my $assign_hash; |
51
|
0
|
|
|
|
|
|
my $assign_array; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$assign_value = sub { |
54
|
0
|
|
|
0
|
|
|
my ($obj, $parent_path, $name, $source_ref, $in_array) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $reftype = reftype $$source_ref; |
57
|
0
|
0
|
|
|
|
|
my $path = $parent_path ne '' ? "$parent_path.$name" : $name; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if ($reftype) { |
60
|
0
|
0
|
|
|
|
|
if ($reftype eq 'HASH') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $new_obj = $engine->object_by_path($path); |
62
|
0
|
|
|
|
|
|
$assign_hash->($new_obj, $$source_ref, $path); |
63
|
|
|
|
|
|
|
} elsif ($reftype eq 'ARRAY') { |
64
|
0
|
|
|
|
|
|
my $new_obj = $engine->array_by_path($path); |
65
|
0
|
|
|
|
|
|
$assign_array->($new_obj, $$source_ref, $path); |
66
|
|
|
|
|
|
|
} elsif ($reftype eq 'CODE') { |
67
|
0
|
|
|
|
|
|
$engine->function_set($name, $$source_ref, $obj); |
68
|
|
|
|
|
|
|
} elsif ($reftype eq 'SCALAR') { |
69
|
0
|
|
|
|
|
|
$assign_array->($obj, $parent_path, $name, $$source_ref, $in_array); |
70
|
|
|
|
|
|
|
} else { |
71
|
|
|
|
|
|
|
# ignore? |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} else { |
74
|
0
|
|
|
|
|
|
my $text_ref = clean_text_ref($source_ref, $ENCODE_UTF8, $SANITIZE_UTF8, $FORCE_UNTAINT); |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
if ($in_array) { |
77
|
0
|
|
|
|
|
|
$engine->array_set_element($obj, $name, $$text_ref); |
78
|
|
|
|
|
|
|
} else { |
79
|
0
|
0
|
|
|
|
|
if ($parent_path) { |
80
|
0
|
|
|
|
|
|
$engine->property_by_path($path, $$text_ref); |
81
|
|
|
|
|
|
|
} else { |
82
|
|
|
|
|
|
|
JavaScript::SpiderMonkey::JS_DefineProperty( |
83
|
0
|
|
|
|
|
|
$engine->{context}, $obj, $name, $$text_ref); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$assign_hash = sub { |
90
|
0
|
|
|
0
|
|
|
my ($obj, $source, $parent_path) = @_; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
for my $name (keys %$source) { |
93
|
0
|
|
|
|
|
|
$assign_value->($obj, $parent_path, $name, \$source->{$name}); |
94
|
|
|
|
|
|
|
} |
95
|
0
|
|
|
|
|
|
}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$assign_array = sub { |
98
|
0
|
|
|
0
|
|
|
my ($obj, $source, $parent_path) = @_; |
99
|
0
|
|
|
|
|
|
my $len = scalar(@$source); |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
for (my $i = 0; $i < $len; $i++) { |
102
|
0
|
|
|
|
|
|
$assign_value->($obj, $parent_path, $i, \$source->[$i], 1); |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
$assign_hash->($engine->{global_object}, $variables, ''); |
107
|
0
|
|
|
|
|
|
return $engine; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub DESTROY { |
111
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
112
|
0
|
0
|
|
|
|
|
$self->{engine}->destroy() if $self->{engine}; |
113
|
0
|
|
|
|
|
|
delete $self->{engine}; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SEE ALSO |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=over 4 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * L |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * L |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * L |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |