Skip to content

Perl Porting to SPVM

Yuki Kimoto edited this page Feb 23, 2024 · 1 revision

Getter/Setter method

Perl:

# Getter/Setter method for the foo field of string
sub foo {
  my $self = shift;

  if (@_) {
    $sefl->{foo} = $_[0];
    return;
  }

  return $self->{foo}
}

SPVM:

# Field
has foo : rw string;

or

method foo : string () {
  return $self->{foo};
}

method set_foo : void ($foo : string) {
  $sefl->{foo} = $foo;
}

The void return type is recommned for setter methods in SPVM.

Clone this wiki locally