-
-
Save alabamenhu/c3ccebdfdb964699a6fba55ab33a9a66 to your computer and use it in GitHub Desktop.
Hash attribute access that's writable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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