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