Created
July 13, 2012 15:21
-
-
Save sirrobert/3105446 to your computer and use it in GitHub Desktop.
perl6: .can does not recognize fallback code
This file contains hidden or 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
| # Apparently the .can method doesn't recognize what's done with | |
| # fallback code. Is that intended? | |
| use v6; | |
| class A { | |
| INIT { | |
| $?PACKAGE.^add_fallback( | |
| # Only provide a fallback function for "foo" | |
| sub ($object, $name) { return ($name eq 'foo') ?? True !! False; }, | |
| sub ($object, $name) { return method () {'A can .foo'} } | |
| ); | |
| } | |
| } | |
| my $a = A.new(); | |
| say $a.foo; | |
| say $a.can('foo') ?? 'A can .foo' !! 'A cannot .foo'; | |
| # output: | |
| # | |
| # A can .foo | |
| # A cannot .foo | |
| # | |
| # Is this an error? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment