line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
8
|
|
|
8
|
|
90
|
use 5.006; |
|
8
|
|
|
|
|
44
|
|
2
|
8
|
|
|
8
|
|
22
|
use strict; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
110
|
|
3
|
8
|
|
|
8
|
|
21
|
use warnings; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
324
|
|
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
|
|
25
|
use base qw(EJS::Template::Base EJS::Template::IO); |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
2632
|
|
13
|
|
|
|
|
|
|
|
14
|
8
|
|
|
8
|
|
2467
|
use EJS::Template::JSAdapter; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
159
|
|
15
|
8
|
|
|
8
|
|
2426
|
use EJS::Template::Runtime; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
1813
|
|
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
|
62
|
|
|
62
|
1
|
72
|
my ($self, $input, $variables, $output) = @_; |
32
|
|
|
|
|
|
|
|
33
|
62
|
|
|
|
|
55
|
my $js; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$self->input($input, sub { |
36
|
62
|
|
|
62
|
|
77
|
my ($in) = @_; |
37
|
62
|
|
|
|
|
167
|
local $/; |
38
|
62
|
|
|
|
|
149
|
$js = <$in>; |
39
|
62
|
|
|
|
|
308
|
}); |
40
|
|
|
|
|
|
|
|
41
|
62
|
|
|
|
|
409
|
my $ret; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->output($output, sub { |
44
|
62
|
|
|
62
|
|
69
|
my ($out) = @_; |
45
|
|
|
|
|
|
|
|
46
|
62
|
|
|
|
|
280
|
my $runtime = EJS::Template::Runtime->new($self); |
47
|
62
|
|
|
|
|
134
|
my $adapter = $self->adapter; |
48
|
62
|
|
|
|
|
431
|
$adapter->bind({print => sub { $self->print(@_) }}); |
|
159
|
|
|
|
|
156410
|
|
49
|
62
|
|
|
|
|
309
|
$adapter->bind({EJS => $runtime->make_map()}); |
50
|
62
|
|
|
|
|
220
|
$adapter->bind($variables); |
51
|
|
|
|
|
|
|
|
52
|
62
|
100
|
|
|
|
161
|
if (defined($js)) { |
53
|
61
|
|
|
|
|
226
|
$ret = $adapter->eval($js); |
54
|
61
|
50
|
|
|
|
5854
|
die $@ if $@; |
55
|
|
|
|
|
|
|
} else { |
56
|
1
|
|
|
|
|
13
|
$ret = 1; |
57
|
|
|
|
|
|
|
} |
58
|
62
|
|
|
|
|
333
|
}); |
59
|
|
|
|
|
|
|
|
60
|
62
|
|
|
|
|
556
|
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
|
68
|
|
|
68
|
1
|
73
|
my $self = shift; |
79
|
|
|
|
|
|
|
|
80
|
68
|
50
|
|
|
|
127
|
if (@_) { |
81
|
0
|
|
|
|
|
0
|
my $old = $self->{adapter}; |
82
|
0
|
|
|
|
|
0
|
$self->{adapter} = shift; |
83
|
0
|
|
|
|
|
0
|
return $old; |
84
|
|
|
|
|
|
|
} else { |
85
|
68
|
|
66
|
|
|
448
|
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; |