Something that I might expect to work is to set @*ARGS
to the list of file names in the signature.
And then just use $*ARGFILES
.
sub MAIN( *@*ARGS, Bool :$debug, ... other named options ...) {
my $input = slurp; # implicitly calls $*ARGFILES.slurp()
... process $input ...
}
It doesn't work though.
You could get Rakudo to update $*ARGFILES
by nulling it with a low-level null before you use it.
sub MAIN( *@*ARGS, Bool :$debug, ... other named options ...) {
{ use nqp; $*ARGFILES := nqp::null }
my $input = slurp;
... process $input ...
}
But that is using an implementation detail that may change in the future.
A better way is to just directly create a new instance of IO::ArgFiles yourself.
You can even store it in $*ARGFILES
. Then slurp
on its own would slurp in all of the file contents.
sub MAIN( *@opt-files, Bool :$debug, ... other named options ...) {
my $*ARGFILES = IO::ArgFiles.new( @opt-files || $*IN );
my $input = slurp;
... process $input ...
}
Note that IO::ArgFiles is just an empty subclass of IO::CatHandle.
So you could write IO::CatHandle.new( @opt‑files || $*IN )
instead.