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

前端之家收集整理的这篇文章主要介绍了在Perl 6中调用类中的私有方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我不能在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)

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

解决方法

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

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

应该管用.

猜你在找的Perl相关文章