lib/JavaScript/Duktape.pm

filter: Statementstmt 81.4% 224 / 275 Branchbran 70.0% 56 / 80 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 94.3% 50 / 53 Podpod 33.3% 3 / 9 totaltotal 79.6% 337 / 423 CC 43 SCAR 17.0
CC
43
Cov
79%
to_perl
17.1
push_perl
12.0
set
9.0
CRAP 5.5
« blib/lib/JavaScript/Duktape.pm ↑ Summary blib/lib/JavaScript/Duktape/C/FunctionsMap.pl »
1 package JavaScript::Duktape;
2 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 30 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 30 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 30 ▶use Scalar::Util 'looks_like_number';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 30 our $VERSION = '0.0.2_1';
9  
10 30 ▶use base qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 30 our @EXPORT = qw (
12 DUK_TYPE_NONE
13 DUK_TYPE_UNDEFINED
14 DUK_TYPE_NULL
15 DUK_TYPE_BOOLEAN
16 DUK_TYPE_NUMBER
17 DUK_TYPE_STRING
18 DUK_TYPE_OBJECT
19 DUK_TYPE_BUFFER
20 DUK_TYPE_POINTER
21 DUK_TYPE_LIGHTFUNC
22 DUK_ENUM_INCLUDE_NONENUMERABLE
23 DUK_ENUM_INCLUDE_INTERNAL
24 DUK_ENUM_OWN_PROPERTIES_ONLY
25 DUK_ENUM_ARRAY_INDICES_ONLY
26 DUK_ENUM_SORT_ARRAY_INDICES
27 DUK_ENUM_NO_PROXY_BEHAVIOR
28 DUK_TYPE_MASK_NONE
29 DUK_TYPE_MASK_UNDEFINED
30 DUK_TYPE_MASK_NULL
31 DUK_TYPE_MASK_BOOLEAN
32 DUK_TYPE_MASK_NUMBER
33 DUK_TYPE_MASK_STRING
34 DUK_TYPE_MASK_OBJECT
35 DUK_TYPE_MASK_BUFFER
36 DUK_TYPE_MASK_POINTER
37 DUK_TYPE_MASK_LIGHTFUNC
38 DUK_TYPE_MASK_THROW
39 DUK_COMPILE_EVAL
40 DUK_COMPILE_FUNCTION
41 DUK_COMPILE_STRICT
42 DUK_COMPILE_SAFE
43 DUK_COMPILE_NORESULT
44 DUK_COMPILE_NOSOURCE
45 DUK_COMPILE_STRLEN
46 DUK_DEFPROP_WRITABLE
47 DUK_DEFPROP_ENUMERABLE
48 DUK_DEFPROP_CONFIGURABLE
49 DUK_DEFPROP_HAVE_WRITABLE
50 DUK_DEFPROP_HAVE_ENUMERABLE
51 DUK_DEFPROP_HAVE_CONFIGURABLE
52 DUK_DEFPROP_HAVE_VALUE
53 DUK_DEFPROP_HAVE_GETTER
54 DUK_DEFPROP_HAVE_SETTER
55 DUK_DEFPROP_FORCE
56 DUK_VARARGS
57 null
58 true
59 false
60 );
61  
62 ##constants
63 use constant {
64 30 DUK_TYPE_NONE => 0,
65 DUK_TYPE_UNDEFINED => 1,
66 DUK_TYPE_NULL => 2,
67 DUK_TYPE_BOOLEAN => 3,
68 DUK_TYPE_NUMBER => 4,
69 DUK_TYPE_STRING => 5,
70 DUK_TYPE_OBJECT => 6,
71 DUK_TYPE_BUFFER => 7,
72 DUK_TYPE_POINTER => 8,
73 DUK_TYPE_LIGHTFUNC => 9,
74  
75 DUK_TYPE_MASK_NONE => (1 << 0),
76 DUK_TYPE_MASK_UNDEFINED => (1 << 1),
77 DUK_TYPE_MASK_NULL => (1 << 2),
78 DUK_TYPE_MASK_BOOLEAN => (1 << 3),
79 DUK_TYPE_MASK_NUMBER => (1 << 4),
80 DUK_TYPE_MASK_STRING => (1 << 5),
81 DUK_TYPE_MASK_OBJECT => (1 << 6),
82 DUK_TYPE_MASK_BUFFER => (1 << 7),
83 DUK_TYPE_MASK_POINTER => (1 << 8),
84 DUK_TYPE_MASK_LIGHTFUNC => (1 << 9),
85 DUK_TYPE_MASK_THROW => (1 << 10),
86  
87 # Enumeration flags for duk_enum()
88 DUK_ENUM_INCLUDE_NONENUMERABLE => (1 << 0),
89 DUK_ENUM_INCLUDE_INTERNAL => (1 << 1),
90 DUK_ENUM_OWN_PROPERTIES_ONLY => (1 << 2),
91 DUK_ENUM_ARRAY_INDICES_ONLY => (1 << 3),
92 DUK_ENUM_SORT_ARRAY_INDICES => (1 << 4),
93 DUK_ENUM_NO_PROXY_BEHAVIOR => (1 << 5),
94  
95 DUK_COMPILE_EVAL => (1 << 0),
96 DUK_COMPILE_FUNCTION => (1 << 1),
97 DUK_COMPILE_STRICT => (1 << 2),
98 DUK_COMPILE_SAFE => (1 << 3),
99 DUK_COMPILE_NORESULT => (1 << 4),
100 DUK_COMPILE_NOSOURCE => (1 << 5),
101 DUK_COMPILE_STRLEN => (1 << 6),
102  
103 #Flags for duk_def_prop() and its variants
104 DUK_DEFPROP_WRITABLE => (1 << 0),
105 DUK_DEFPROP_ENUMERABLE => (1 << 1),
106 DUK_DEFPROP_CONFIGURABLE => (1 << 2),
107 DUK_DEFPROP_HAVE_WRITABLE => (1 << 3),
108 DUK_DEFPROP_HAVE_ENUMERABLE => (1 << 4),
109 DUK_DEFPROP_HAVE_CONFIGURABLE => (1 << 5),
110 DUK_DEFPROP_HAVE_VALUE => (1 << 6),
111 DUK_DEFPROP_HAVE_GETTER => (1 << 7),
112 DUK_DEFPROP_HAVE_SETTER => (1 << 8),
113 DUK_DEFPROP_FORCE => (1 << 9),
114 DUK_VARARGS => -1
115 30 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
116  
117 sub new {
118 30 ▶ my $class= shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
119 30 my $self = bless {}, $class;
120 30 $self->{duk} = JavaScript::Duktape::Vm->new();
121 30 $self->{pid} = $$;
122 30 return $self;
123 }
124  
125 2 ▶sub null { $JavaScript::Duktape::Data::null; }
Subroutine null: called CC=1 SCAR=0.0
Pod undocumented
126 2 ▶sub true { $JavaScript::Duktape::Bool::true; }
Subroutine true: called CC=1 SCAR=0.0
Pod undocumented
127 3 ▶sub false { $JavaScript::Duktape::Bool::false }
Subroutine false: called CC=1 SCAR=0.0
Pod undocumented
128  
129 sub set {
130 2 ▶ my $self = shift;
Subroutine set: called CC=4 SCAR=22.0
Pod documented
131 2 my $name = shift;
132 2 my $val = shift;
133 2 my $duk = $self->vm;
134  
135 2 ▶ if ($name =~ /\./){
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\./) 0 2 2
136  
137 0 my @props = split /\./, $name;
138 0 my $last = pop @props;
139 0 my $others = join '.', @props;
140  
141 0 my $err = $duk->peval_string($others);
142 0 ▶ if ($err){ die $others . " is not a javascript object " }
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
143
144 0 my $type = $duk->get_type(-1);
145 0 ▶ if ($type != DUK_TYPE_OBJECT){
Branch: 1 branch
BranchTrueFalseTotal
if ($type != 6) 0 0 0
146 0 die $others . " isn't an object";
147 }
148  
149 0 $duk->push_string($last);
150 0 $duk->push_perl($val);
151 0 $duk->put_prop(-3);
152 0 $duk->pop();
153 0 return 1;
154 }
155  
156 2 $duk->push_perl($val);
157 2 $duk->put_global_string($name);
158 2 return 1;
159 }
160  
161 sub get {
162 0 ▶ my $self = shift;
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
163 0 my $name = shift;
164 0 my $duk = $self->vm;
165 0 $duk->push_string($name);
166 0 my $err = $duk->peval();
167 0 ▶ if ($err){
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
168 0 my $error = $duk->safe_to_string(-1);
169 0 croak $error;
170 }
171  
172 0 my $ret = $duk->to_perl(-1);
173 0 $duk->pop();
174 0 return $ret;
175 }
176  
177 sub eval {
178 0 ▶ my $self = shift;
Subroutine eval: not called CC=2 SCAR=17.9
Pod documented
179 0 my $string = shift;
180 0 my $duk = $self->duk;
181  
182 0 my $err = $duk->peval_string($string);
183
184 0 ▶ if ($err){
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
185 0 my $error_string = $duk->safe_to_string(-1);
186 0 croak $error_string;
187 }
188  
189 0 return $duk->to_perl(-1);
190 }
191  
192 2 ▶sub vm { shift->{duk}; }
Subroutine vm: called CC=1 SCAR=0.0
Pod undocumented
193 59 ▶sub duk { shift->{duk}; }
Subroutine duk: called CC=1 SCAR=0.0
Pod undocumented
194  
195 sub DESTROY {
196 30 ▶ my $self = shift;
Subroutine DESTROY: called CC=2 SCAR=7.0
197 30 my $duk = $self->duk;
198 30 ▶ if ($self->{pid} == $$){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pid"} == $$) 30 0 30
199 30 $duk->destroy_heap();
200 }
201 }
202  
203 package JavaScript::Duktape::Vm;
204 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
205 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
206 30 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
207 30 ▶use Scalar::Util 'looks_like_number';
Subroutine BEGIN: called CC=1 SCAR=0.0
208 30 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
209 30 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
210 30 ▶use JavaScript::Duktape::C::libPath;
Subroutine BEGIN: called CC=1 SCAR=0.0
211  
212 30 my $Duklib;
213  
214 BEGIN {
215 30 ▶ my $FunctionsMap = JavaScript::Duktape::C::libPath::getPath("FunctionsMap.pl");
Subroutine BEGIN: called CC=2 SCAR=7.1
216 30 require $FunctionsMap;
217  
218 30 ▶ $Duklib = $^O eq 'MSWin32' ?
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 30 30
219 JavaScript::Duktape::C::libPath::getPath('duktape.dll') :
220 JavaScript::Duktape::C::libPath::getPath('duktape.so');
221 };
222  
223 30 use Inline C => config =>
224 typemaps => JavaScript::Duktape::C::libPath::getPath('typemap'),
225 30 ▶ INC => '-I' . JavaScript::Duktape::C::libPath::getPath('../C');
Subroutine BEGIN: called CC=1 SCAR=0.0
226 # myextlib => $Duklib,
227 # LIBS => '-L'. JavaScript::Duktape::C::libPath::getPath('../C') . ' -lduktape';
228  
229 30 ▶use Inline C => JavaScript::Duktape::C::libPath::getPath('duktape_wrap.c');
Subroutine BEGIN: called CC=1 SCAR=0.0
230  
231 30 my $SUB = 0;
232 30 my $Functions = {};
233  
234 sub push_perl {
235 16 ▶ my $self = shift;
Subroutine push_perl: called CC=12 SCAR=24.8
236 16 my $val = shift;
237  
238 16 my $ref = ref $val;
239 16 ▶ if ($ref){
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) { } 9 7 16
240 9 ▶ if ($ref eq 'JavaScript::Duktape::Data'){
Branch: 5 branches
BranchTrueFalseTotal
if ($ref eq 'JavaScript::Duktape::Data') { } 1 8 9
elsif ($ref eq 'JavaScript::Duktape::Bool') { } 2 6 8
elsif ($ref eq 'ARRAY') { } 1 5 6
elsif ($ref eq 'HASH') { } 2 3 5
elsif ($ref eq 'CODE') { } 3 0 3
241 1 $self->push_null();
242 } elsif ($ref eq 'JavaScript::Duktape::Bool'){
243 2 ▶ if ($val){
Branch: 1 branch
BranchTrueFalseTotal
if ($val) { } 1 1 2
244 1 $self->push_true();
245 } else {
246 1 $self->push_false();
247 }
248 } elsif ($ref eq 'ARRAY'){
249 1 my $arr_idx = $self->push_array();
250 1 my $len = scalar @{$val};
251 1 ▶ for (my $idx = 0; $idx < $len; $idx++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < $len) 3 1 4
252 3 $self->push_perl($val->[$idx]);
253 3 $self->put_prop_index($arr_idx, $idx);
254 }
255 } elsif ($ref eq 'HASH'){
256 2 $self->push_object();
257 2 ▶ while (my ($k, $v) = each %{$val}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$val;}) 8 2 10
258 8 $self->push_string($k);
259 8 $self->push_perl($v);
260 8 $self->put_prop(-3);
261 }
262 } elsif ($ref eq 'CODE') {
263 $self->push_function( sub {
264 4 ▶ my $top = $self->get_top();
Subroutine __ANON__: called CC=2 SCAR=6.9
265 4 my @args = ($self);
266 4 ▶ for (my $i = 0; $i < $top; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $top) 7 4 11
267 7 push @args, $self->to_perl($i);
268 }
269 4 my $ret = $val->(@args);
270 2 $self->push_perl($ret);
271 2 return 1;
272 3 });
273 }
274 } else {
275 7 ▶ if (!defined $val){
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $val) { } 1 6 7
elsif (&looks_like_number($val)) { } 5 1 6
276 1 $self->push_undefined();
277 } elsif (looks_like_number( $val )){
278 5 $self->push_number($val);
279 } else {
280 1 $self->push_string($val);
281 }
282 }
283 }
284  
285 sub to_perl {
286 8 ▶ my $self = shift;
Subroutine to_perl: called CC=12 SCAR=28.4
287 8 my $index = shift;
288 8 my $ret;
289
290 8 my $type = $self->get_type($index);
291  
292 8 ▶ if ($type == JavaScript::Duktape::DUK_TYPE_STRING){
Branch: 6 branches
BranchTrueFalseTotal
if ($type == 5) { } 2 6 8
elsif ($type == 4) { } 1 5 6
elsif ($type == 6) { } 1 4 5
elsif ($type == 3) { } 2 2 4
elsif ($type == 2) { } 1 1 2
elsif ($type == 8) { } 0 1 1
293 2 $ret = $self->get_string($index);
294 }
295  
296 elsif ($type == JavaScript::Duktape::DUK_TYPE_NUMBER){
297 1 $ret = $self->get_number($index) + 0;
298 }
299  
300 elsif ($type == JavaScript::Duktape::DUK_TYPE_OBJECT){
301  
302 1 ▶ if ($self->is_function($index)){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_function($index)) 1 0 1
303 1 my $ptr = $self->get_heapptr($index);
304 return sub {
305 1 ▶ $self->push_heapptr($ptr);
Subroutine __ANON__: called CC=2 SCAR=6.9
306 1 my $len = 0+@_;
307 1 ▶ for (my $i = 0; $i < $len; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 1 1 2
308 1 $self->push_perl($_[$i]);
309 }
310 1 $self->call($len);
311 1 my $ret = $self->to_perl(-1);
312 1 $self->pop();
313 1 return $ret;
314 1 };
315 }
316  
317 0 my $isArray = $self->is_array($index);
318 0 ▶ $ret = $isArray ? [] : {};
Branch: 1 branch
BranchTrueFalseTotal
$isArray ? : 0 0 0
319 0 $self->enum($index, JavaScript::Duktape::DUK_ENUM_OWN_PROPERTIES_ONLY);
320  
321 0 ▶ while ($self->next(-1, 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->next(-1, 1)) 0 0 0
322 0 my $key = $self->to_perl(-2);
323 0 my $val = $self->to_perl(-1);
324
325 0 $self->pop_n(2);
326  
327 0 ▶ if ($isArray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isArray) { } 0 0 0
328 0 $ret->[$key] = $val;
329 } else {
330 0 $ret->{$key} = $val;
331 }
332 }
333 0 $self->pop();
334 }
335  
336 elsif ($type == JavaScript::Duktape::DUK_TYPE_BOOLEAN){
337 2 my $bool = $self->get_boolean($index);
338 2 ▶ if ($bool == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($bool == 1) { } 1 1 2
339 1 $ret = JavaScript::Duktape::Bool::true();
340 } else {
341 1 $ret = JavaScript::Duktape::Bool::false();
342 }
343 }
344  
345 elsif ($type == JavaScript::Duktape::DUK_TYPE_NULL){
346 1 $ret = JavaScript::Duktape::Data::null();
347 }
348  
349 ##XXX to do
350 elsif ($type == JavaScript::Duktape::DUK_TYPE_POINTER){
351 0 $ret = "pointer";
352 }
353  
354 else {
355 1 $ret = undef;
356 }
357
358 7 return $ret;
359 }
360  
361 ##############################################
362 # push functions
363 ##############################################
364 sub push_function {
365 21 ▶ my $self = shift;
Subroutine push_function: called CC=2 SCAR=6.9
366 21 my $sub = shift;
367 21 my $nargs = shift;
368 21 ▶ if (!defined $nargs){ $nargs = -1 }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nargs) 5 16 21
369  
370 21 $SUB++;
371 $Functions->{$SUB} = sub {
372 42 ▶ my $top = $self->get_top();
Subroutine __ANON__: called CC=1 SCAR=0.0
373 42 my $ret = 1;
374 $self->perl_duk_safe_call(sub {
375 42 ▶ eval { $ret = $sub->($self) };
Subroutine __ANON__: called CC=3 SCAR=11.0
376 42 my $error = $@;
377 42 ▶ if ($error){
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 12 30 42
378 12 ▶ if ($error =~ /^Duk::Error/){
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ /^Duk::Error/) { } 6 6 12
379 6 die $@;
380 } else {
381 6 $error =~ s/\n//g;
382 6 $error =~ s/\\/\\\\/g;
383 6 $self->eval_string("throw new Error('$error')");
384 }
385 }
386 30 return $ret;
387 42 }, $top, 1);
388 28 return $ret;
389 21 };
390  
391 21 $self->perl_push_function($Functions->{$SUB}, $nargs);
392 }
393  
394 30 *push_c_function = \&push_function;
395  
396 #####################################################################
397 # safe call
398 #####################################################################
399 sub safe_call {
400 50 ▶ my $self = shift;
Subroutine safe_call: called CC=4 SCAR=15.8
401 50 my $sub = shift;
402 my $safe = sub {
403 50 ▶ return $sub->($self);
Subroutine __ANON__: called CC=1 SCAR=0.0
404 50 };
405  
406 50 my $oldtop = $self->get_top();
407 50 eval { $self->perl_duk_safe_call($safe, @_) };
408 50 my $error = $@;
409 50 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 16 34 50
410 16 ▶ if ($error =~ /^Duk::Error/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ /^Duk::Error/i) { } 16 0 16
411 # error came from duktape do nothing;
412 } else {
413 #error from perl push error object
414 #and clear previous pushed stack
415 0 my $newtop = $self->get_top();
416 0 ▶ if ($newtop > $oldtop){
Branch: 1 branch
BranchTrueFalseTotal
if ($newtop > $oldtop) 0 0 0
417 0 $self->pop_n($newtop - $oldtop);
418 }
419 0 $error =~ s/\n//g;
420 0 $error =~ s/\\/\\\\/g;
421 0 $self->eval_string("var t = new Error('$error'); t;");
422 }
423 16 return 1;
424 }
425 34 return 0;
426 }
427  
428 ##############################################
429 # overridden functions
430 ##############################################
431 30 *require_context = \&perl_duk_require_context;
432  
433  
434 ##############################################
435 # helper functions
436 ##############################################
437 30 *reset_top = \&perl_duk_reset_top;
438  
439 sub dump {
440 3 ▶ my $self = shift;
Subroutine dump: called CC=4 SCAR=13.9
441 3 ▶ my $name = shift || "Duktape";
Condition100%2/2
shift() || 'Duktape'
l!l
21
MC/DC100%1/1
shift() || 'Duktape'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
442 3 ▶ my $fh = shift || \*STDOUT;
Condition50%1/2
shift() || \*STDOUT
l!l
03
MC/DC0%0/1
shift() || \*STDOUT
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
443 3 my $n = $self->get_top();
444 3 printf $fh "%s (top=%ld):", $name, $n;
445 3 ▶ for (my $i = 0; $i < $n; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $n) 3 3 6
446 3 printf $fh " ";
447 3 $self->dup($i);
448 3 printf $fh "%s", $self->safe_to_string(-1);
449 3 $self->pop();
450 }
451 3 printf $fh "\n";
452 }
453  
454 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
455  
456 package JavaScript::Duktape::Bool; {
457 30 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
458 30 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
459 30 our ($true, $false);
460 use overload
461 4 ▶ '""' => sub { ${$_[0]} },
Subroutine __ANON__: called CC=1 SCAR=0.0
462 7 ▶ 'bool' => sub { ${$_[0]} ? 1 : 0 },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
${$_[0];} ? : 3 4 7
463 30 ▶ fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
464  
465 BEGIN {
466 30 ▶ my $t = 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
467 30 my $f = 0;
468 30 $true = bless \$t, 'JavaScript::Duktape::Bool';
469 30 $false = bless \$f, 'JavaScript::Duktape::Bool';
470 }
471  
472 1 ▶ sub true { $true }
Subroutine true: called CC=1 SCAR=0.0
473 1 ▶ sub false { $false }
Subroutine false: called CC=1 SCAR=0.0
474 }
475  
476 30 package JavaScript::Duktape::Data; {
477 30 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
478 30 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
479 30 our ($null);
480 use overload
481 2 ▶ '""' => sub { ${$_[0]} },
Subroutine __ANON__: called CC=1 SCAR=0.0
482 1 ▶ 'bool' => sub { ${$_[0]} ? 1 : 0 },
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
${$_[0];} ? : 0 1 1
483 30 ▶ fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
484  
485 BEGIN {
486 30 ▶ my $n = '';
Subroutine BEGIN: called CC=1 SCAR=0.0
487 30 $null = bless \$n, 'JavaScript::Duktape::Data';
488 }
489  
490 1 ▶ sub null { $null }
Subroutine null: called CC=1 SCAR=0.0
491 }
492  
493 30 1;
494  
495 __END__
« blib/lib/JavaScript/Duktape.pm ↑ Summary blib/lib/JavaScript/Duktape/C/FunctionsMap.pl »