为什么Perl的SUPER调用不使用arrow方法? [英] Why doesn't Perl's SUPER call use the arrow method?

查看:96
本文介绍了为什么Perl的SUPER调用不使用arrow方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,当您调用超类的方法时,您需要执行以下操作:

I noticed that when you call a superclass's methods, you need to do something like this :

my $self = $class->SUPER::new();

为什么不是这样?

my $self = $class->SUPER->new();

推荐答案

我怀疑是因为$class->SUPER->new()通常与$class->SUPER()->new()相同.但是没有$class->SUPER()函数,并且不清楚返回什么.

I suspect because $class->SUPER->new() would normally be the same as $class->SUPER()->new(). But there isn't a $class->SUPER() function, and its not clear what that would return.

另一方面,$class->Foo::Bar一直是直接用全名直接调用方法的有效方法,因此制作类似包的特殊东西-SUPER-更合适. (我怀疑您实际上可以将SUPER作为一个程序包实现,也许从历史上看,我不知道)

On the other hand, $class->Foo::Bar has always been a valid way to call a method directly by full name, so making a special package-like thing — SUPER — fits in better. (I suspect that you could actually implement SUPER as a package, and maybe it historically was, I don't know)

PS:看一下mro软件包和$self->next::method.另外,如果您打算在Perl中进行认真的OO工作,请看看Moose.

PS: Take a look at the mro package, and $self->next::method. Also, take a look at Moose if you're going to do serious OO work in Perl.

这篇关于为什么Perl的SUPER调用不使用arrow方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆