I need access to self
, but can't get to it because I am stuck in the non-instanced
state to take advantage of
compile-time access. Is there a way to pull up self
, here?
Given:
sub buildAccessors(\O, @attributes) {
my $proxy = \attr -> {
method :: {
Proxy.new:
FETCH => $, { attr.get_value(O) },
STORE => $, \v { attr.set_value(O, v) };
}
}
for @attributes -> $k, \v {
next unless .name.substr(0, 2) eq <$! %! &! @!>.any;
O.^add_method(
.name.substr(2),
trait_mod:<is>($proxy($_), :rw) #= $proxy() returns Method
)
}
}
class EContactAddress is repr<CStruct> is export {
#! cw: Needs accessors!
has Str $!address_format; #= the two letter country code that determines the format/meaning of the following fields
has Str $!po;
has Str $!ext;
has Str $!street;
has Str $!locality;
has Str $!region;
has Str $!code;
has Str $!country;
buildAccessors(self, ::?CLASS.^attributes);
}
Any ideas, #raku?
Thanks
I'm not entirely sure what you're trying to do, but are you sure that you can't pass in
::?CLASS
instead ofself
?After all
.^add_method
is for adding methods to a class, not an instance.