Created
November 2, 2015 13:02
-
-
Save jonathanstowe/8a7fb59bdcb0586b5027 to your computer and use it in GitHub Desktop.
Use a multi STORE on a proxy
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
class MetaVersion is Version { | |
multi method new(Str() $ver where * ~~ /^v\d+/) { | |
my $v = $ver; $v ~~ s/^v//; self.new($v) | |
} | |
multi method new(Version $ver) { | |
self.new(parts => $ver.parts); | |
} | |
}; | |
my MetaVersion $v; | |
multi sub store($, Str $ver) { | |
$v = MetaVersion.new($ver); | |
} | |
multi sub store($, Version $ver) { | |
$v = MetaVersion.new($ver); | |
} | |
multi sub store($, $ver) { | |
$v = $ver; | |
} | |
my MetaVersion $a := Proxy.new(FETCH => sub ($) { $v }, STORE => &store); | |
$a = "v0.0.1"; | |
say $a; | |
$a = v0.0.1; | |
say $a; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment