Skip to content

Instantly share code, notes, and snippets.

@jonathanstowe
Created November 2, 2015 13:02
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 jonathanstowe/8a7fb59bdcb0586b5027 to your computer and use it in GitHub Desktop.
Save jonathanstowe/8a7fb59bdcb0586b5027 to your computer and use it in GitHub Desktop.
Use a multi STORE on a proxy
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