Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created Jan 17, 2016
Embed
What would you like to do?
use v6;
role BaseRole[::T] is export {
has T $.attr is rw;
}
class BaseClass does BaseRole[Str] is export {
}
use v6;
{ # scope for UsingLib
use BaseLib;
use UsingLib :consumer;
consumer(UsingClass.new);
}
{ # scope for ParameterisedLib
use BaseLib;
class NewBaseClass is BaseClass does BaseRole[Int] {
}
use ParameterisedLib NewBaseClass, {:consumer};
consumer(NewBaseClass.new);
amulti(NewBaseClass.new);
MixedClass.new.amulti(NewBaseClass.new);
}
use v6;
use BaseLib;
role ParameterisedRole[::T] {
multi method amulti(T $t) { say "$?FILE:$?LINE: amulti(T): ", $t.^name }
multi method amulti(BaseClass $t) { say "$?FILE:$?LINE: amulti(BaseClass): ", $t.^name }
multi method amulti(BaseRole $t) { say "$?FILE:$?LINE: amulti(BaseRole): ", $t.^name }
}
sub EXPORT(::T = BaseClass, %h?) {
say "$?FILE:$?LINE: EXPORT: ", T.^name;
my $T = T;
multi sub amulti($t where * ~~ $T) { say "$?FILE:$?LINE: amulti(T): ", $t.^name }
multi sub amulti($t where * ~~ BaseClass) { say "$?FILE:$?LINE: amulti(BaseClass): ", $t.^name }
multi sub amulti($t where * ~~ BaseRole) { say "$?FILE:$?LINE: amulti(BaseRole): ", $t.^name }
my $MixedClass = class :: {} but ParameterisedRole.^parameterize(T);
{ # anon Hash to be returned by &EXPORT
'&consumer' => sub (T $c) is export(:consumer) {
say "$?FILE:$?LINE: consuming: ", $c.^name;
T.new;
},
'&amulti' => &amulti,
'MixedClass' => $MixedClass,
}
}
use v6;
use BaseLib;
class UsingClass is BaseClass is export(:MANDATORY) {
}
sub consumer(BaseClass $c) is export(:consumer) {
say "$?FILE:$?LINE: consuming: ", $c.^name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment