| 1 | package Lox::Callable; | ||||||||||
| 2 | 260 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 260 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 260 | ▶ | use Lox::Bool; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | use overload | ||||||||||
| 6 | 2 | ▶ | '""' => sub { '<native fn>' }, | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 0 | ▶ | '!' => sub { $False }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 8 | 0 | ▶ | 'bool' => sub { $True }, # only false and nil are untrue in Lox | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 9 | 260 | fallback => 0; | |||||||||
| 10 | |||||||||||
| 11 | 260 | our $VERSION = 0.02; | |||||||||
| 12 | |||||||||||
| 13 | 260 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 14 | 260 | my ($class, $args) = @_; | |||||||||
| 15 | 260 | return bless { %$args }, $class; | |||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub arity { $_[0]->{arity} } | ||||||||
|
Subroutine
arity: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub call { | ||||||||
|
Subroutine
call: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 21 | 0 | my ($self, $interpreter, @args) = @_; | |||||||||
| 22 | 0 | ▶ | my $sub = sub { $self->{call}->($interpreter, @args) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 23 | 0 | return $self->call_catch_return($interpreter, $sub); | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 436 | ▶ | sub call_catch_return { | ||||||||
|
Subroutine
call_catch_return: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||
| 27 | 436 | my ($self, $interpreter, $sub) = @_; | |||||||||
| 28 | 436 | my $retval = eval { $sub->() }; | |||||||||
| 29 | 430 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 348 | ▶ | if ($@ =~ /^return/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 348 | return delete $interpreter->{returning}; | |||||||||
| 32 | } | ||||||||||
| 33 | else { | ||||||||||
| 34 | 0 | die $@; # we don't handle this exception | |||||||||
| 35 | } | ||||||||||
| 36 | } | ||||||||||
| 37 | 82 | return $retval; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 260 | 1; | |||||||||