Created
January 17, 2016 13:45
-
-
Save gfldex/e0c398175941d094958a 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
use v6; | |
role BaseRole[::T] is export { | |
has T $.attr is rw; | |
} | |
class BaseClass does BaseRole[Str] is export { | |
} | |
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
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); | |
} |
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
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, | |
} | |
} | |
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
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