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

4 perl perl6

我不能在Perl 6中的类中调用私有方法:

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)
Run Code Online (Sandbox Code Playgroud)

那我怎么打电话my-private-methodmy-method

fri*_*edo 7

您必须在实例对象上调用private方法.

my $my-var1 = self!my-private-method(123);
Run Code Online (Sandbox Code Playgroud)

应该管用.