Hi Liz, I tried to use the code you suggested:
sub trait_mod:<is>(Attribute:D \attribute, :&proxy!) { attribute.package.^add_method(attribute.name, my method () { proxy($_) }) } class A { has $!a is proxy({ $^a * 2 }); has $!b is proxy({ $^a * 3 }); } my A $a .= new; $a.a = 21; # <-- No such method 'a' for invocant of type 'A' say $a.a; $a.b = 21; say $a.b; But I got an error on the first assignment. What am I doing wrong? On Fri, Nov 17, 2017 at 1:27 AM, Elizabeth Mattijsen <l...@dijkmat.nl> wrote: > Oops, > > > On 17 Nov 2017, at 01:24, Elizabeth Mattijsen <l...@dijkmat.nl> wrote: > > sub trait_mod:<is>(\attribute, :&proxy!) is export { > > sub trait_mod:<is>(Attribute:D \attribute, :&proxy!) is export { > > so that the trait can only be used on Attribute objects. > > > > Liz > -- Fernando Santagata