+sub rel2abs ($$) {
+ my ($self, $p) = @_;
+ return $p if index($p, '/') == 0; # already absolute
+ my $pwd = $self->{env}->{PWD};
+ if (defined $pwd) {
+ my $cwd = $self->{3} // getcwd() // die "getcwd(PWD=$pwd): $!";
+ if (my @st_pwd = stat($pwd)) {
+ my @st_cwd = stat($cwd) or die "stat($cwd): $!";
+ "@st_pwd[1,0]" eq "@st_cwd[1,0]" or
+ $self->{env}->{PWD} = $pwd = $cwd;
+ } else { # PWD was invalid
+ delete $self->{env}->{PWD};
+ undef $pwd;
+ }
+ }
+ $pwd //= $self->{env}->{PWD} = getcwd() // die "getcwd(PWD=$pwd): $!";
+ File::Spec->rel2abs($p, $pwd);
+}
+