blib/lib/JavaScript/QuickJS/Function.pm

filter: Statementstmt 100% 13 / 13 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 18 / 18 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« quickjs/quickjs.h ↑ Summary easyxs/easyxs_structref.h »
1 package JavaScript::QuickJS::Function;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =encoding utf-8
7  
8 =head1 NAME
9  
10 JavaScript::QuickJS::Function
11  
12 =head1 SYNOPSIS
13  
14 my $func = JavaScript::QuickJS->new()->eval("() => 123");
15  
16 print $func->(); # prints “123”; note overloading :)
17  
18 =head1 DESCRIPTION
19  
20 This class represents a JavaScript
21 L<Function|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function>
22 instance in Perl.
23  
24 This class is not instantiated directly.
25  
26 =head1 OVERLOADING
27  
28 For convenience, instances of this class are callable as Perl code references.
29 This is equivalent to a C<call()> with $this_sv (see below) set to undef.
30  
31 See the L</SYNOPSIS> above for an example.
32  
33 =head1 INVOCATION METHODS
34  
35 =head2 $ret = I<OBJ>->call( $this_sv, @arguments )
36  
37 Like JavaScript’s method of the same name.
38  
39 =head1 ACCESSOR METHODS
40  
41 The following methods return their corresponding JS property:
42  
43 =over
44  
45 =item * C<length()>
46  
47 =item * C<name()>
48  
49 =back
50  
51 =cut
52  
53 #----------------------------------------------------------------------
54  
55 sub _as_coderef;
56  
57 use overload (
58 4 '&{}' => \&_as_coderef,
59 nomethod => \&_give_self, # xsub
60 4 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 sub _as_coderef {
63 9 ▶ my ($self) = @_;
Subroutine _as_coderef: called CC=1 SCAR=0.0
64  
65 9 ▶ return sub { $self->call(undef, @_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
66 }
67  
68 4 1;
« quickjs/quickjs.h ↑ Summary easyxs/easyxs_structref.h »