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