【发布时间】:2018-09-14 13:44:48
【问题描述】:
我正在阅读一个寻找不同结构的电子表格。当我使用 Moose 尝试以下操作时,它似乎做了我想做的事。我可以创建不同类型的对象,将其分配给找到的成员 并转储 Cell 实例以供审核。
package Cell
{
use Moose;
use Moose::Util::TypeConstraints;
use namespace::autoclean;
has 'str_val' => ( is => 'ro', isa => 'Str', required => 1 );
has 'x_id' => ( is => 'ro', isa => 'Str', ); # later required => 1 );
has 'color' => ( is => 'ro', isa => 'Str', );
has 'border' => ( is => 'ro', isa => 'Str', );
has 'found' => ( is => 'rw', isa => 'Sch_Symbol|Chip_Symbol|Net', );
1;
}
如果我尝试在 Perl 6 中做同样的事情,它将无法编译。
class Cell {
has Str $.str_val is required;
has Str $.x_id is required;
has Str $.color;
has Str $.border;
has Sch_Symbol|Chip_Symbol|Net $.found is rw
}
Malformed has at C:\Users\Johan\Documents/moose_sch_3.pl6:38 ------> has Sch_Symbol'<'HERE'>'|Chip_Symbol|Net $.found is rw
如何在 Perl 6 中做到这一点?
【问题讨论】:
标签: raku