I'm trying to understand why an attribute value is a Str (or whatever) outside of Proxy.new, but becomes Method inside of Proxy.new. I golfed my code down to this:
#!/usr/bin/env raku
class Foo does Associative {
has Str $.string;
multi method AT-KEY (::?CLASS:D: Str $key) is rw {
say "\nOutside of Proxy: { $!string.raku }";
say "Outside of Proxy: { $!string.^name }";
Proxy.new(
FETCH => method () {
say "FETCH: { $!string.raku }";
say "FETCH: { $!string.^name }";
},
STORE => method ($value) {
say "STORE: { $!string.raku }";
say "STORE: { $!string.^name }";
}
);
}
}
my $string = 'foobar';
my %foo := Foo.new: :$string;
%foo<bar> = 'baz';
say %foo<bar>;
This is the output:
$ ./proxy.raku
Outside of Proxy: "foobar"
Outside of Proxy: Str
STORE: method <anon> (Mu: *%_) { #`(Method|94229743999472) ... }
STORE: Method
Outside of Proxy: "foobar"
Outside of Proxy: Str
FETCH: method <anon> (Mu: *%_) { #`(Method|94229743999616) ... }
FETCH: Method
FETCH: method <anon> (Mu: *%_) { #`(Method|94229743999616) ... }
FETCH: Method
FETCH: method <anon> (Mu: *%_) { #`(Method|94229743999616) ... }
FETCH: Method
FETCH: method <anon> (Mu: *%_) { #`(Method|94229743999616) ... }
FETCH: Method
FETCH: method <anon> (Mu: *%_) { #`(Method|94229743999616) ... }
FETCH: Method
FETCH: method <anon> (Mu: *%_) { #`(Method|94229743999616) ... }
FETCH: Method
FETCH: method <anon> (Mu: *%_) { #`(Method|94229743999616) ... }
FETCH: Method
FETCH: method <anon> (Mu: *%_) { #`(Method|94229743999616) ... }
FETCH: Method
FETCH: method <anon> (Mu: *%_) { #`(Method|94229743999616) ... }
FETCH: Method
True
Can anyone explain what's going on here? Thanks!