使用多个源文件包装一个方法
Wrapping a method using several source files
我正在尝试了解包装在 perl6 中的工作原理。我正在使用此代码:
第一个文件(test.pl6):
use v6;
use lib '.';
use TestClass;
my TestClass $t .= new;
$t.wrapped(1, 7);
第二个文件(TestClass.pm6):
multi sub trait_mod:<is>(Routine:D \r, :$dummy!)
{
r.wrap(sub (|)
{
say 'Dummy';
callsame;
});
}
unit class TestClass;
method wrapped($a, $b) is dummy
{
say "Wrapped ($a, $b)";
}
执行test.pl6时,我得到:
Cannot invoke this object (REPR: Null; VMNull)
in sub at TestClass.pm6 (TestClass) line 5
in any enter at gen/moar/Metamodel.nqp line 3999
in block <unit> at test.pl6 line 7
当上面的所有代码都在同一个文件中时,它会工作并首先打印 Dummy 然后 Wrapped (1, 7) .
我做错了什么?
根据 RT 问题 #129096,这是一个错误:“[BUG] sub wrapped with mod_trait:当导出时产生神秘的错误消息,在同一单元中工作正常”。在 2016 年 8 月 26 日的评论中,此错误列出了记者认为相关的一系列其他错误,因为它们代表了一个 "outer context lost with compile time closure" 错误。
在相关错误列表中有一个 a comment dated 10 April 2016 说:
I'm actually surprised there are as few "Cannot invoke this object"
tickets:
A cursory survey of those would suggest that they all fall in a wider
category of "code attribute of some type not surviving precompilation"
我没有审查所有明显相关的错误,也没有在#perl6-dev 上询问开发人员对它们的看法。
我正在尝试了解包装在 perl6 中的工作原理。我正在使用此代码:
第一个文件(test.pl6):
use v6;
use lib '.';
use TestClass;
my TestClass $t .= new;
$t.wrapped(1, 7);
第二个文件(TestClass.pm6):
multi sub trait_mod:<is>(Routine:D \r, :$dummy!)
{
r.wrap(sub (|)
{
say 'Dummy';
callsame;
});
}
unit class TestClass;
method wrapped($a, $b) is dummy
{
say "Wrapped ($a, $b)";
}
执行test.pl6时,我得到:
Cannot invoke this object (REPR: Null; VMNull)
in sub at TestClass.pm6 (TestClass) line 5
in any enter at gen/moar/Metamodel.nqp line 3999
in block <unit> at test.pl6 line 7
当上面的所有代码都在同一个文件中时,它会工作并首先打印 Dummy 然后 Wrapped (1, 7) .
我做错了什么?
根据 RT 问题 #129096,这是一个错误:“[BUG] sub wrapped with mod_trait:当导出时产生神秘的错误消息,在同一单元中工作正常”。在 2016 年 8 月 26 日的评论中,此错误列出了记者认为相关的一系列其他错误,因为它们代表了一个 "outer context lost with compile time closure" 错误。
在相关错误列表中有一个 a comment dated 10 April 2016 说:
I'm actually surprised there are as few "Cannot invoke this object" tickets:
A cursory survey of those would suggest that they all fall in a wider category of "code attribute of some type not surviving precompilation"
我没有审查所有明显相关的错误,也没有在#perl6-dev 上询问开发人员对它们的看法。