Skip to content

Instantly share code, notes, and snippets.

SAD.pm:
use SAD::Special;
class SAD {
has $!nothing;
}
SAD/Special.pm:
role SAD::Special {
@ChoHag
ChoHag / gist:adc790bc7ca00b245c62
Created July 6, 2014 06:13
moar role/class attributes
role foo {
my @.bar;
method addbar (*@new) { @.bar.push(@new) }
}
class bar does foo {
method BUILD { self.addbar('bar') }
}
class baz does foo {
class fakehash {
has $.keys handles 'push';
has $.calculator = { $^a };
has $.null;
method postbrace ($lookup) {
$lookup ~~ $.keys.any ?? $!calculator($lookup) !! $.null;
}
}
sub postcircumfix:<{ }> (fakehash $bar, $lookup) {
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);
require 'pp'
module Xen
class VM < Base
# Creates a new VM with a certain name set and a amount of memory
# (in bytes) on a cluster
def self.create(template = nil, name = nil, memory = 32 * MB,
cluster = nil, varch = :hvm, boot_loader = nil,