Skip to content

Instantly share code, notes, and snippets.

@xenoterracide xenoterracide/mixins.pl6 Secret
Last active Aug 29, 2015

Embed
What would you like to do?
mixins In Perl6
# mixins are called roles in perl 6 and also can behave as traits and interfaces
class ALogger { method debug( Str:D $message ) {...}}
class BLogger { method debug( Str:D $message ) {...}}
role Logger {
method log( Str:D $message ) { ... }
}
role LoggerInfo {
has $!log = ALogger.new();
}
role LoggerDebug {
has $!log = BLogger.new();
}
class MyLogger does Logger, LoggerDebug, LoggerInfo {
method log( Str:D $message ) {
$!log.debug($message);
}
}
class Handler { # Logger and UberLogger are valid
method logHelloWorld( Logger:D $log ) {
$log.log("hello world");
# could call error, can't call trace (or maybe you can but shouldn't)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.