line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
16
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package JavaScript::Any::Context::V8; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
382
|
use namespace::autoclean; |
|
1
|
|
|
|
|
13850
|
|
|
1
|
|
|
|
|
4
|
|
11
|
1
|
|
|
1
|
|
475
|
use Class::Tiny qw( _context ); |
|
1
|
|
|
|
|
2197
|
|
|
1
|
|
|
|
|
5
|
|
12
|
1
|
|
|
1
|
|
603
|
use Role::Tiny::With; |
|
1
|
|
|
|
|
3659
|
|
|
1
|
|
|
|
|
62
|
|
13
|
|
|
|
|
|
|
with qw( JavaScript::Any::Context ); |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
62
|
use Ref::Util qw( |
16
|
|
|
|
|
|
|
is_plain_arrayref is_plain_hashref is_ref |
17
|
|
|
|
|
|
|
is_blessed_ref is_plain_coderef |
18
|
1
|
|
|
1
|
|
388
|
); |
|
1
|
|
|
|
|
1286
|
|
19
|
1
|
|
|
1
|
|
222
|
use JavaScript::V8 qw(); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub BUILD { |
22
|
|
|
|
|
|
|
my $self = shift; |
23
|
|
|
|
|
|
|
my ($args) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$self->_context("JavaScript::V8::Context"->new( |
26
|
|
|
|
|
|
|
time_limit => $args->{timeout}, |
27
|
|
|
|
|
|
|
)); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
return; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# delegated methods |
33
|
|
|
|
|
|
|
sub eval { shift->_context->eval(@_) } |
34
|
|
|
|
|
|
|
sub timeout { shift->_context->time_limit(@_) } |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub define { |
37
|
|
|
|
|
|
|
my $self = shift; |
38
|
|
|
|
|
|
|
my ($name, $value) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$self->_throw_if_bad_name($name); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# XXX |
43
|
|
|
|
|
|
|
# need to install a wrapper |
44
|
|
|
|
|
|
|
# to process params and return values |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
if (is_plain_coderef($value)) { |
47
|
|
|
|
|
|
|
$self->_context->bind($name, $value); |
48
|
|
|
|
|
|
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
if (is_plain_hashref($value)) { |
52
|
|
|
|
|
|
|
$self->_context->bind($name, $value); |
53
|
|
|
|
|
|
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
if (is_plain_arrayref($value)) { |
57
|
|
|
|
|
|
|
$self->_context->bind($name, $value); |
58
|
|
|
|
|
|
|
return; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
if (is_blessed_ref($value)) { |
62
|
|
|
|
|
|
|
$self->_context->bind($name, $value); |
63
|
|
|
|
|
|
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
if ($self->is_true($value)) { |
67
|
|
|
|
|
|
|
$self->_context->eval("$name = true;"); # UGLY |
68
|
|
|
|
|
|
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
if ($self->is_false($value)) { |
72
|
|
|
|
|
|
|
$self->_context->eval("$name = false;"); # UGLY |
73
|
|
|
|
|
|
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
if ($self->is_null($value)) { |
77
|
|
|
|
|
|
|
$self->_context->eval("$name = null;"); # UGLY |
78
|
|
|
|
|
|
|
return; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
if (not is_ref($value)) { |
82
|
|
|
|
|
|
|
$self->_context->bind($name, $value); |
83
|
|
|
|
|
|
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$self->_throw_because_bad_value($value); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|