According to p6doc 5to6-perlfunc
:
FILE
Replaced by
$?FILE
which is slightly different from__FILE__
in that it is always an absolute path, rather than a relative one in the Perl 5 case.
and according to p6doc CallFrame
:
With no arguments the
callframe
will give you frame information for the line callingcallframe
. The file and line annotations will be identical to those in$?FILE
and$?LINE
.
But when I tested this, the file
attribute gives a relative path name:
./p.p6:
use v6;
use Data::Dump::Tree;
use lib '.';
use MyModule;
say 'Main script: package path name : ', $?FILE;
say 'Main script: $*PROGRAM-NAME : ', $*PROGRAM-NAME;
MyModule::func();
./MyModule.pm6:
unit module MyModule;
our sub func() {
say "func: This package path name : ", $?FILE;
my $frame = callframe 1;
say "func: Calling package's file name: ", $frame.file;
}
Output:
Main script: package path name : /home/hakon/test/perl6/./p.p6
Main script: $*PROGRAM-NAME : ./p.p6
func: This package path name : /home/hakon/test/perl6/MyModule.pm6 (MyModule)
func: Calling package's file name: ./p.p6
How can I get the absolute path name of the compilation unit of the caller?
Have you looked at the absolute method from IO::Path?
say "func: Calling package's file name: ", $frame.file.IO.absolute;
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