| 1 | package Lox::Class; | ||||||||||||||
| 2 | 260 | ▶ | use Lox::Bool; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 260 | ▶ | use overload ( | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 13 | ▶ | '""' => sub { $_[0]->name }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 95 | ▶ | 'bool' => sub { $True }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 1 | ▶ | '!' => sub { $False }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 260 | fallback => 0, | |||||||||||||
| 8 | 260 | ); | |||||||||||||
| 9 | 260 | ▶ | use parent 'Lox::Callable'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 260 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 260 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 260 | ▶ | use Lox::Instance; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 260 | our $VERSION = 0.02; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 85 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 16 | 85 | my ($class, $args) = @_; | |||||||||||||
| 17 | 85 | return bless { %$args }, $class; | |||||||||||||
| 18 | } | ||||||||||||||
| 19 | |||||||||||||||
| 20 | 189 | ▶ | sub superclass { $_[0]->{superclass} } | ||||||||||||
|
Subroutine
superclass: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 21 | 230 | ▶ | sub methods { $_[0]->{methods} } | ||||||||||||
|
Subroutine
methods: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 22 | 21 | ▶ | sub name { $_[0]->{name} } | ||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 23 | |||||||||||||||
| 24 | 51 | ▶ | sub call { | ||||||||||||
|
Subroutine
call: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 25 | 51 | my ($self, $interpreter, @args) = @_; | |||||||||||||
| 26 | 51 | my $instance = Lox::Instance->new({ klass => $self, fields => {} }); | |||||||||||||
| 27 | 51 | my $initializer = $self->find_method('init'); | |||||||||||||
| 28 | 51 | ▶ | if ($initializer) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 29 | 8 | $initializer->bind($instance)->call($interpreter, @args); | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | 51 | return $instance; | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 57 | ▶ | sub arity { | ||||||||||||
|
Subroutine
arity: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 35 | 57 | my $self = shift; | |||||||||||||
| 36 | 57 | my $initializer = $self->find_method('init'); | |||||||||||||
| 37 | 57 | ▶ | return $initializer ? $initializer->arity : 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 230 | ▶ | sub find_method { | ||||||||||||
|
Subroutine
find_method: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||
| 41 | 230 | my ($self, $lexeme) = @_; | |||||||||||||
| 42 | 230 | ▶ | if (my $method = $self->methods->{$lexeme}) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 43 | 90 | return $method; | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | elsif ($self->superclass) { | ||||||||||||||
| 46 | 49 | return $self->superclass->find_method($lexeme); | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | 91 | return undef; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 260 | 1; | |||||||||||||