line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
8
|
|
|
8
|
|
89
|
use 5.006; |
|
8
|
|
|
|
|
46
|
|
2
|
8
|
|
|
8
|
|
23
|
use strict; |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
111
|
|
3
|
8
|
|
|
8
|
|
27
|
use warnings; |
|
8
|
|
|
|
|
5
|
|
|
8
|
|
|
|
|
270
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
EJS::Template::Executor - Executes JavaScript generated by EJS::Template |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package EJS::Template::Executor; |
12
|
8
|
|
|
8
|
|
22
|
use base qw(EJS::Template::Base EJS::Template::IO); |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
2654
|
|
13
|
|
|
|
|
|
|
|
14
|
8
|
|
|
8
|
|
2440
|
use EJS::Template::JSAdapter; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
156
|
|
15
|
8
|
|
|
8
|
|
2545
|
use EJS::Template::Runtime; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
1757
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 Methods |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 execute |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Executes JavaScript code. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$executor->execute($input, $variables, $output); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
The C<$input> is used as the JavaScript source code, C<$variables> is a hash |
26
|
|
|
|
|
|
|
ref of variables for JavaScript, and C<$output> is the output destination |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub execute { |
31
|
63
|
|
|
63
|
1
|
81
|
my ($self, $input, $variables, $output) = @_; |
32
|
|
|
|
|
|
|
|
33
|
63
|
|
|
|
|
54
|
my $js; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->input($input, sub { |
36
|
63
|
|
|
63
|
|
66
|
my ($in) = @_; |
37
|
63
|
|
|
|
|
157
|
local $/; |
38
|
63
|
|
|
|
|
229
|
$js = <$in>; |
39
|
63
|
|
|
|
|
309
|
}); |
40
|
|
|
|
|
|
|
|
41
|
63
|
|
|
|
|
409
|
my $ret; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->output($output, sub { |
44
|
63
|
|
|
63
|
|
72
|
my ($out) = @_; |
45
|
|
|
|
|
|
|
|
46
|
63
|
|
|
|
|
286
|
my $runtime = EJS::Template::Runtime->new($self); |
47
|
63
|
|
|
|
|
120
|
my $adapter = $self->adapter; |
48
|
63
|
|
|
|
|
382
|
$adapter->bind({print => sub { print $out @_ }}); |
|
160
|
|
|
|
|
151530
|
|
49
|
63
|
|
|
|
|
259
|
$adapter->bind({EJS => $runtime->make_map()}); |
50
|
63
|
|
|
|
|
191
|
$adapter->bind($variables); |
51
|
|
|
|
|
|
|
|
52
|
63
|
100
|
|
|
|
131
|
if (defined($js)) { |
53
|
62
|
|
|
|
|
213
|
$ret = $adapter->eval($js); |
54
|
62
|
50
|
|
|
|
5610
|
die $@ if $@; |
55
|
|
|
|
|
|
|
} else { |
56
|
1
|
|
|
|
|
19
|
$ret = 1; |
57
|
|
|
|
|
|
|
} |
58
|
63
|
|
|
|
|
329
|
}); |
59
|
|
|
|
|
|
|
|
60
|
63
|
|
|
|
|
268
|
return $ret; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 adapter |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Usage: |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Getter |
68
|
|
|
|
|
|
|
$executor->adapter; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Setter |
71
|
|
|
|
|
|
|
$executor->adapter(EJS::Template::JSAdapter->create('JE')); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Gets or sets an C object. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub adapter { |
78
|
69
|
|
|
69
|
1
|
74
|
my $self = shift; |
79
|
|
|
|
|
|
|
|
80
|
69
|
50
|
|
|
|
123
|
if (@_) { |
81
|
0
|
|
|
|
|
0
|
my $old = $self->{adapter}; |
82
|
0
|
|
|
|
|
0
|
$self->{adapter} = shift; |
83
|
0
|
|
|
|
|
0
|
return $old; |
84
|
|
|
|
|
|
|
} else { |
85
|
69
|
|
66
|
|
|
393
|
return $self->{adapter} ||= EJS::Template::JSAdapter->create($self->{config}{engine}); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 SEE ALSO |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=over 4 |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item * L |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=back |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
1; |