line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
19417
|
use 5.008003; |
|
1
|
|
|
|
|
7
|
|
2
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
98
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package JavaScript::Any; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
566
|
use Exporter::Shiny qw( jseval ); |
|
1
|
|
|
|
|
4405
|
|
|
1
|
|
|
|
|
6
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _generate_jseval { |
13
|
1
|
|
|
1
|
|
124
|
my $me = shift; |
14
|
1
|
|
|
|
|
3
|
my ($name, $args) = @_; |
15
|
|
|
|
|
|
|
return sub { |
16
|
1
|
|
|
1
|
|
7
|
my $code = shift; |
17
|
1
|
|
50
|
|
|
10
|
my $ctx = $me->new_context($args or {}); |
18
|
1
|
|
|
|
|
10
|
$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
|
14596
|
my $me = shift; |
31
|
2
|
100
|
|
|
|
9
|
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
|
|
|
|
|
12
|
$impl->new($args); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub implementation { |
42
|
1
|
50
|
|
1
|
0
|
4
|
return $IMPLEMENTATION if defined $IMPLEMENTATION; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
2
|
for my $try (@IMPLEMENTATIONS) { |
45
|
3
|
100
|
|
|
|
2322
|
eval "require $try" or next; |
46
|
1
|
|
|
|
|
11
|
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__ |