Quick actions

cmd+k|ctrl+k

Navigation

Languages

Meta-attribute trait

Snippet info

Language

Raku

Visibility

public

Author

smonff

Created

2017-10-13T20:29:08Z

Updated

2017-10-13T20:29:08Z

use v6;
use Test;

plan 1;

role crud {
    has Bool $.crud is default(True);
}

multi trait_mod:<is>(Attribute $a, crud, $arg) {
    $a.container.VAR does crud($arg);

}

class Foo {
    has $.bar is rw;
    has $.baz is rw is crud(True);
}

# Ok pass
my $foo = Foo.new();
is $foo.baz.crud, True, 'Trait meta-attribute is properly set';

# No problem on this one since it doesn't "crud"
$foo.bar = 123456789;
say $foo;

# Cannot modify an immutable Scalar+{crud} (Scalar+{crud}.new(crud => Bool::True))
#   in block <unit> at t/08-attribute-trait.t line 33
$foo.baz = 'so what?';
INFO