Skip to content

Instantly share code, notes, and snippets.

@sirrobert
Created July 13, 2012 15:21
Show Gist options
  • Select an option

  • Save sirrobert/3105446 to your computer and use it in GitHub Desktop.

Select an option

Save sirrobert/3105446 to your computer and use it in GitHub Desktop.
perl6: .can does not recognize fallback code
# 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