在 Perl 6 中的 class 中调用私有方法

Calling a private method within a class in Perl 6

我无法在 Perl 6 的 class 中调用私有方法:

class MyClass {

  method !my-private-method($var1) {
    # ....
  }

  method my-method() {
    my $my-var1 = !my-private-method(123); # not found (Undeclared routines)
    my $my-var1 = $!my-private-method(123); # not found (Undeclared routines)
    my $my-var1 = $.my-private-method(123); # not found (Undeclared routines)
    my $my-var1 = my-private-method(123); # not found (Undeclared routines)

那么如何从 my-method 调用 my-private-method

您必须在您的实例对象上调用私有方法。

my $my-var1 = self!my-private-method(123);

应该可以。