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