Fix XSLoader to recognize drive letters
authorFather Chrysostomos <[email protected]>
Mon, 4 Jul 2016 15:48:57 +0000 (08:48 -0700)
committerFather Chrysostomos <[email protected]>
Mon, 4 Jul 2016 19:48:10 +0000 (12:48 -0700)
Commit 08e3451d made XSLoader confirm that the file path it got
from (caller)[2] was in @INC if it looked like a relative path.
Not taking drive letters into account, it made that @INC search
mandatory on Windows and some other systems.  It still worked, but
was slightly slower.

dist/XSLoader/XSLoader_pm.PL

index 7e24b83..2efb99e 100644 (file)
@@ -91,8 +91,20 @@ print OUT <<'EOT';
     my $modpname = join('/',@modparts);
     my $c = () = split(/::/,$caller,-1);
     $modlibname =~ s,[\\/][^\\/]+$,, while $c--;    # Q&D basename
+EOT
+
+my $to_print = <<'EOT';
     # Does this look like a relative path?
-    if ($modlibname !~ m|^[\\/]|) {
+    if ($modlibname !~ m{regexp}) {
+EOT
+
+$to_print =~ s~regexp~
+    $^O eq 'MSWin32' || $^O eq 'os2' || $^O eq 'cygwin' || $^O eq 'amigaos'
+        ? '^(?:[A-Za-z]:)?[\\\/]' # Optional drive letter
+        : '^/'
+~e;
+
+print OUT $to_print, <<'EOT';
         # Someone may have a #line directive that changes the file name, or
         # may be calling XSLoader::load from inside a string eval.  We cer-
         # tainly do not want to go loading some code that is not in @INC,