(1 2)
(1 (Any))
(1 42)
can't store value for unknown key
in block <unit> at native-demonstration.p6:17
Actually thrown at:
in block <unit> at native-demonstration.p6:17
By defining FALLBACK any class can handle undefined method calls. Since any class inherits plenty of methods from Any our magic object will be more of a novice conjurer then a master wizard proper.
class Magic { has %.hash; multi method FALLBACK($name, |c) is rw { # this will eat any extra parameters %.hash{$name} } multi method FALLBACK($name) is rw { %.hash{$name} }}my $magic = Magic.new;$magic.foo = 10;say $magic.foo;$magic.defined = False; # error
Output:
10
Cannot modify an immutable Bool
in block <unit> at native-demonstration.p6:15