Last active
May 29, 2016 17:07
-
-
Save LLFourn/df95c23e884b7c1a9dd0e52580431c15 to your computer and use it in GitHub Desktop.
Visitor Pattern package relationships in Perl 6
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
# this is a .gist to explain my solution wrt https://rt.perl.org/Public/Bug/Display.html?id=128275 | |
# VisitorRoles.pm6 | |
role Visitor { | |
method visit {...} | |
} | |
role Node { | |
method accept {...} | |
} | |
# MyNode.pm6 | |
use VisitorRoles; | |
class MyNode does Node { | |
has $.payload = "Perl6"; | |
method accept(Visitor:D $b) { | |
$b.visit(self); | |
} | |
} | |
# MyVisitor.pm6 | |
use VisitorRoles; | |
class MyVisitor does Visitor { | |
method visit(Node:D $a) { | |
$a.payload; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment