line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
20002
|
use 5.008003; |
|
1
|
|
|
|
|
6
|
|
2
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
62
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package JavaScript::Any; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
371
|
use Exporter::Shiny qw( jseval ); |
|
1
|
|
|
|
|
4170
|
|
|
1
|
|
|
|
|
9
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _generate_jseval { |
13
|
1
|
|
|
1
|
|
192
|
my $me = shift; |
14
|
1
|
|
|
|
|
4
|
my ($name, $args) = @_; |
15
|
|
|
|
|
|
|
return sub { |
16
|
1
|
|
|
1
|
|
7
|
my $code = shift; |
17
|
1
|
|
50
|
|
|
11
|
my $ctx = $me->new_context($args or {}); |
18
|
1
|
|
|
|
|
9
|
$ctx->eval($code); |
19
|
1
|
|
|
|
|
11
|
}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $IMPLEMENTATION; |
23
|
|
|
|
|
|
|
my @IMPLEMENTATIONS = qw( |
24
|
|
|
|
|
|
|
JavaScript::Any::Context::V8 |
25
|
|
|
|
|
|
|
JavaScript::Any::Context::Duktape |
26
|
|
|
|
|
|
|
JavaScript::Any::Context::JE |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new_context { |
30
|
2
|
|
|
2
|
1
|
13015
|
my $me = shift; |
31
|
2
|
100
|
|
|
|
10
|
my $args = ref($_[0]) eq 'HASH' ? $_[0] : +{ @_ }; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $impl = delete($args->{implementation}) |
34
|
2
|
|
33
|
|
|
16
|
|| ($IMPLEMENTATION ||= $me->implementation); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# ehhh, should probably load $impl. |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
11
|
$impl->new($args); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub implementation { |
42
|
1
|
50
|
|
1
|
0
|
3
|
return $IMPLEMENTATION if defined $IMPLEMENTATION; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
3
|
for my $try (@IMPLEMENTATIONS) { |
45
|
3
|
100
|
|
|
|
3803
|
eval "require $try" or next; |
46
|
1
|
|
|
|
|
9
|
return $try; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
require Carp; |
50
|
0
|
|
|
|
|
|
Carp::croak("No Javascript implementation available. Please install JavaScript::Duktape or JE"); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |