移相器特性何时运行? [英] When are phaser traits run?

查看:27
本文介绍了移相器特性何时运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

will移相器特征示例显示此代码:

The will phaser trait examples show this code:

our $h will enter { .rememberit() } will undo { .forgetit() };

这要么被误解,要么根本不是真正的用例.如果它被误解了,我会说它 enter s 块,它被分配了一个变量.如果它不是一个真正的用例,它会调用一个未定义变量的方法.这似乎是发生了什么:

Which is either misunderstood or simply not a real use case. If it's misunderstood, I would say it enters the block with it's assigned a variable. If it's not a real use case, it calls a method on an undefined variable. This is what seems to happen:

our &doing-good will enter {
    say( "running" );
        if Backtrace.new.grep: { .subname  ~~ /bad/ } {
            fail("Not authorized to call this");
        }
};

这个只是在定义的时候运行,也就是具体什么时候输入?MAIN 作用域?这可能是文档错误.很有可能 phaser trait 不能真正应用于变量,但上面,当它实际上是一个块时,它并没有真正运行;移相器"当完全独立于 value 的变量定义的事情发生时运行,至少在这种情况下是这样.有什么想法吗?

This is simply run when the definition is made, that is, when what exactly is entered? The MAIN scope? This is probably the documentation fault. It's very likely that phaser traits can't really be applied to variables, but above, when it's actually a block, it's not really run; the "phaser" is run when something that's totally independent of the variable definition of value happens, at least in this case. Any idea?

推荐答案

移相器特性"当你调用它们时,将与同名的其他移相器同时运行.

The "phaser traits" as you call them, will be run at the same time as other phasers of the same name.

变量上的 will 特征基本上在其周围范围内设置移相器,变量作为唯一的位置参数传递.所以

The will trait on a variable basically sets up phasers in its surrounding scope, with the variable passed as the only positional parameter. So

my $h will enter { dd $_ };

在功能上等同于:

my $h;
ENTER { dd $h }

在您的示例中:

our &doing-good will enter { ... }

您正在定义一个变量 &doing-good,它将传递给指定的块.在您的示例中,我没有看到该变量被初始化,因此该块将接收一个 Callable 类型对象(因为如果它是 &doing-good 将包含的内容)未初始化).

you are defining a variable &doing-good that will be passed to the block that is specified. In your example, I do not see that variable getting initialized, so the block will receive a Callable type object (because that is what &doing-good will contain if it is not initialized).

这篇关于移相器特性何时运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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