Is that one argument or none for a Perl 6 block?
As far as I know, the only way to know the number of parameters passed without an explicit signature, is to use @_
inside the body, which will generate a :(*@_)
signature.
my &block := { say "Got @_.elems() parameter(s)" };
block; # Got 0 parameter(s)
block 42; # Got 1 parameter(s)
dd block.signature; # :(*@_)
Yeah, the good old @_
is still there, if you want it :-)
{ put $_.perl }
Is sort of similar to this: (which doesn't work)
-> ;; $_? is raw = CALLERS::<$_> { put $_.perl }
Since the default is default
for $_
outside of the block is Any
, if you don't place anything into $_
before you call the function you get Any
.
To get something at all similar where you can tell the difference use a Capture :
my &foo = -> ;; |C ($_? is raw) {
unless C.elems {
# pretend it was defined like the first Block above
CALLER::<$_> := CALLER::CALLERS::<$_>
}
my $called-with-arguments := C.elems.Bool;
if $called-with-arguments {
say 'called with arguments';
} else {
say 'not called with arguments';
}
}