Created
January 17, 2016 08:32
-
-
Save gfldex/57bb505e41eb7649b1ba 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; | |
# Let's prefix &say with the line number it's called from | |
module BaseLib { | |
role BaseRole[::T] is export { | |
has T $.attr is rw; | |
} | |
class BaseClass does BaseRole[Str] is export { | |
} | |
} | |
module UsingLib { | |
import BaseLib; | |
class UsingClass is BaseClass is export(:MANDATORY) { | |
} | |
sub consumer(BaseClass $c) is export(:consumer) { | |
say "$?LINE: consuming: ", $c.^name; | |
} | |
} | |
{ # scope for UsingLib | |
import BaseLib; | |
import UsingLib :consumer; | |
consumer(UsingClass.new); | |
} | |
module ParametrisedLib { | |
import BaseLib; | |
sub EXPORT(::T = BaseClass, %h?) { | |
say "%?LINE: EXPORT: ", T.^name; | |
{ # anon Hash to be returned by &EXPORT | |
'&consumer' => sub (T $c) is export(:consumer) { | |
say "$?LINE: consuming: ", $c.^name; | |
T.new; | |
} if %h<consumer>:exists, | |
} | |
} | |
} | |
{ # scope for ParametrisedLib | |
import BaseLib; | |
class NewBaseClass is BaseClass does BaseRole[Int] { | |
} | |
import ParametrisedLib NewBaseClass, {:consumer}; | |
consumer(NewBaseClass.new); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment