Skip to content

Instantly share code, notes, and snippets.

@LLFourn
Last active May 29, 2016 17:07
Show Gist options
  • Save LLFourn/df95c23e884b7c1a9dd0e52580431c15 to your computer and use it in GitHub Desktop.
Save LLFourn/df95c23e884b7c1a9dd0e52580431c15 to your computer and use it in GitHub Desktop.
Visitor Pattern package relationships in Perl 6
# 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