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
| #!perl6 | |
| role EnterValidator {} | |
| role Blobject { } | |
| class ObjectOne does Blobject { | |
| } | |
| class ObjectTwo does Blobject { | |
| } | |
| multi sub trait_mod:<is> ( Method $m, :$enter-validator! ) { | |
| $m does EnterValidator; | |
| } | |
| class Foo { | |
| method any(Blobject $blob) returns Bool is enter-validator { say "any";} | |
| method one(ObjectOne $blob) returns Bool is enter-validator { say "one"; } | |
| method two(ObjectTwo $blob) returns Bool is enter-validator { say "two"; } | |
| method run-em(Blobject $object) { | |
| for self.^methods.grep(EnterValidator) -> $meth { | |
| if $object.WHAT ~~ $meth.signature.params[1].type { | |
| self.$meth($object); | |
| } | |
| } | |
| } | |
| } | |
| my $foo = Foo.new; | |
| say "running one"; | |
| $foo.run-em(ObjectOne.new); | |
| say "running two"; | |
| $foo.run-em(ObjectTwo.new); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment