Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created January 17, 2016 08:32
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 gfldex/57bb505e41eb7649b1ba to your computer and use it in GitHub Desktop.
Save gfldex/57bb505e41eb7649b1ba to your computer and use it in GitHub Desktop.
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