Skip to content

Instantly share code, notes, and snippets.

Created May 3, 2015 10:29
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 anonymous/08896f0615a976d6caa1 to your computer and use it in GitHub Desktop.
Save anonymous/08896f0615a976d6caa1 to your computer and use it in GitHub Desktop.
multi trait_mod:<will>(Attribute:D $attr, $block, :$lazy!) {
$attr does role {
method compose(|) {
callsame();
$attr.package.^method_table{$attr.name.substr(2)}.wrap(-> \self {
callsame() // $attr.set_value(self, $block())
});
}
}
}
class A {
has $.a will lazy { say 'omg now'; 42 }
}
my $a = A.new;
say 'not yet';
say $a.a;
say $a.a;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment