我有一个带有子类X的类Y。 X有一个calculate()我想Y用一些额外的行为覆盖的方法if,如果它失败,调用的语句X.calculate()。在 Python 中,这将通过以下方式完成:
class X(object):
def calculate(self, my_arg):
return "Hello!"
class Y(X):
def calculate(self, my_arg):
if type(my_arg) is int and my_arg > 5:
return "Goodbye!"
return super(Y, self).calculate(my_arg)
如何在 Perl 中使用该Moo模块执行此操作?