Created
June 25, 2014 17:22
-
-
Save ChoHag/e1a910d6ac454aadb7b3 to your computer and use it in GitHub Desktop.
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 SomeTrait { | |
method apply_handles($attr: Mu $pkg) { | |
say "apply_handles"; | |
my $name = $attr.name; | |
my $accessor = $name.subst(/^../, ''); | |
my $r = sub ($obj, |args) is rw { | |
say "$name accessor"; | |
nextsame; | |
}; | |
$pkg.HOW.find_method($pkg, $accessor).wrap($r); | |
} | |
method foo { say "fooing" } | |
} | |
multi trait_mod:<is>(Attribute $var, :$wtf!) { | |
die "Must have accessor" unless $var.has-accessor; | |
$var.set_rw; | |
say "456"; | |
say $var; | |
$var does SomeTrait; | |
$var.foo; | |
} | |
class foo { | |
has $.x is wtf; | |
} | |
say "begin"; | |
my $foo = foo.new;#(x => 32); | |
my $bar = foo.new(x => 32); | |
say $foo.x; | |
say $bar.x; | |
say "---"; | |
$foo.x = 64; | |
say "..."; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dies with: