class Foo {
has &.bar;
has @.quux is required;
method clone { nextwith :quux(@!quux.clone) };
# as per <https://docs.perl6.org/type/Mu#method_clone>
};
my $f = Foo.new(quux => []);
my $f-clone = $f.clone(bar => sub { die });
# Foo.new(bar => Callable, quux => [])
but should be
Foo.new(bar => sub { #`(Sub|94789546929784) ... }, quux => [])
Adding :bar(&!bar.clone) to the nextwith call does not help.
nextwith "calls the next matching candidate with arguments provided by users". You're only passing a :quux argument in the nextwith call.
Unless you add an explicit slurpy hash parameter (eg. *%foo), all methods have an implicit *%_ in their signature:
say .signature given method ($a, $b) {} # (Mu: $a, $b, *%_)
So by default all named arguments are slurped into %_. A common idiom is to pass these on:
method clone { nextwith :quux(@!quux.clone), |%_ }
The above will pass arguments provided to the $f.clone call onto the nextwith'd clone call.
Adding
:bar(&!bar.clone)to thenextwithcall does not help.
That will be instead of the :bar argument passed in the $f.clone call. The &!bar in the original object contains the Callable type object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With