Skip to content

Instantly share code, notes, and snippets.

@alabamenhu
Last active January 7, 2021 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alabamenhu/c3ccebdfdb964699a6fba55ab33a9a66 to your computer and use it in GitHub Desktop.
Save alabamenhu/c3ccebdfdb964699a6fba55ab33a9a66 to your computer and use it in GitHub Desktop.
Hash attribute access that's writable
role IOMeta {
my Hash %stash;
method metadata {
return-rw %stash{self.path} //= Hash.new
}
}
my $a = "foo".IO does IOMeta;
my $b = "foo".IO.add("bar") does IOMeta;
$a.metadata<test> = 'test';
say $a.metadata;
$b.parent.metadata = %( t => 'test2');
say $a.metadata;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment