重写方法调用运算符或其他方法来捕获方法名称解析错误

问题描述 投票:7回答:1

[我正在尝试为X::NYI类编写示例作为对X::NYI的响应。我想出了这样的东西:

this issue

试图重新实现class Nothing { sub postfix:<.&>( $sub, **@args) { die X::NYI.new( feature => $sub, did-you-mean => "nothing", workaround => "Implement it yourself" ); } } my $let's-see = Nothing.newish; 以对所调用的任何东西引发异常。这不起作用:

the method call postfix operator

在NYI.p6第13行的方框中

事实上,文档中说:

从技术上讲,不是真正的运营商;它是编译器中特例的语法。

最有可能意味着它不能被覆盖。这也意味着做我想做的事情意味着与No such method 'newish' for invocant of type 'Nothing' 交互以拦截类解析方法。但是我真的不知道如何做到这一点。 Rakudo源代码中的大多数示例,例如metamodel,都会在调用具体函数(实际上是this one)时引发异常。

那么重写the exception we see is thrown by the dispatch method at the Mu level是执行这种操作的正确方法吗?还是其他完全不同的东西?

oop perl6 dispatch
1个回答
8
投票
对我来说你想要dispatch
© www.soinside.com 2019 - 2024. All rights reserved.