Skip to content

Instantly share code, notes, and snippets.

@teodozjan
Forked from moritz/meta.pl
Last active August 29, 2015 14:01
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 teodozjan/b7183c81c966cfeee3bd to your computer and use it in GitHub Desktop.
Save teodozjan/b7183c81c966cfeee3bd to your computer and use it in GitHub Desktop.
use v6;
multi sub trait_mod:<is>(Method $m, :$must!){
note "trait only if stub is present in base class activated"
}
multi sub trait_mod:<is>(Method $m, :$override!){
note "trait only if method overrides activated";
}
#multi trait_mod:<is>(Any $type, :$OverrideContractedClass!) {
# die $type;
#}
my class OverrideContractedClassHOW is Metamodel::ClassHOW {
method new_type(:$name, :$repr, :$ver, :$auth){
die "new type";
}
method add_method($obj, $name, $code){
note "add_method";
nextsame;
}
method add_parent(Mu $obj, Mu $parent){
note "add_parent";
nextsame;
}
method add_role(Mu $obj, Mu $role ){
note "??DSAd";
}
}
my module EXPORTHOW {}
EXPORTHOW.WHO.<class> = OverrideContractedClassHOW;
role Incomplete {
method bar {...}
method foo {"bar"}
}
class Complete does Incomplete {
method bar is must { 42}
method foo is override { "42" }
}
#say Incomplete.^methods;
my Complete $cl = Complete.new;
say $cl.bar;
say $cl.^roles;
use v6;
multi trait_mod:<is>(Method:D $c, :$must!) {
# my $name = $c.name;
die $c.invocant;
#unless $declared-in.^can($name) {
#die "Method $name claims to be declared in {$declared-in.^name}, but there's no such method in {$declared-in.^name}!\n";
#}
}
role R {
method m1() { 42 };
method m2() { ... };
}
class C does R {
method m1() {
# all fine here
}
method m2() is must {
# should bomb
}
}
===SORRY!=== Error while compiling meta.pl
Method 'm1' must be implemented by R because it is required by a role
at meta.pl:15
------>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment