为混合角色的属性分配值

jjm*_*elo 7 mixins perl6

我正在尝试使用EnumerationPerl 6中角色的一个示例(作为修复文档问题的一部分,枚举角色未记录).我想出了这个简单的例子:

class DNA does Enumeration {
    my $DNAindex = 0;
    my %pairings = %( A => "T",
                      T => "A",
                      C => "G",
                      G => "T" );

    method new( $base-pair where "A" | "C" | "G" | "T" )  {
        self.bless( key => $base-pair,
                    value => %pairings{$base-pair},
                    index => 33);
    }

    multi method gist(::?CLASS:D:) {
        return "$!key -> $!value with $!index";
    }

}

for <A C G T>.roll( 16 ) -> $letter {
    my DNA $base = DNA.new( $letter );
    say "Pairs ", $base.pair,  " with ", $base.gist;
}
Run Code Online (Sandbox Code Playgroud)

从理论上讲,Enumeration has $!index和与index => 33我尝试值分配给它; 然而,它返回的就像是

 Pairs T => A with T -> A with 0
Run Code Online (Sandbox Code Playgroud)

任何其他方式直接为$!index赋值,并且我得到"无法分配给我在另一个问题中得到的不可变值.根据其中一个答案,这可能是一个错误;在这种情况下,我会想知道是否有一些解决方法.

rai*_*iph 3

这是一个错误无法更改消费类的本机角色属性(与您链接的答案中提到的无关)。

我不知道解决方法。