Any/Context/V8.pm

filter: Statementstmt 91.3% 21 / 23 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 93.5% 29 / 31 SCAR 0.0
CC
1
Cov
91%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Any/Context/Duktape.pm ↑ Summary
1 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package JavaScript::Any::Context::V8;
6  
7 our $AUTHORITY = 'cpan:TOBYINK';
8 our $VERSION = '0.001';
9  
10 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Class::Tiny qw( _context );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 with qw( JavaScript::Any::Context );
14  
15 1 use Ref::Util qw(
16 is_plain_arrayref is_plain_hashref is_ref
17 is_blessed_ref is_plain_coderef
18 1 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use JavaScript::V8 qw();
Subroutine BEGIN: called CC=1 SCAR=2.6
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  
« Any/Context/Duktape.pm ↑ Summary