Perl Porting to SPVM - yuki-kimoto/SPVM GitHub Wiki

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.