Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Implement absolute path lookup in ModuleLoader.

  • Loading branch information...
commit efac451801f3d685b02e2daddb89b99bf4e08d48 1 parent 69c3cce
authored September 12, 2013
15  src/Perl6/ModuleLoader.nqp
@@ -10,6 +10,8 @@ sub DEBUG(*@strs) {
10 10
 class Perl6::ModuleLoader does Perl6::ModuleLoaderVMConfig {
11 11
     my %modules_loaded;
12 12
     my %settings_loaded;
  13
+    my $absolute_path_func;
  14
+    
13 15
     my %language_module_loaders := nqp::hash(
14 16
         'NQP', nqp::gethllsym('nqp', 'ModuleLoader'),
15 17
     ); 
@@ -20,12 +22,21 @@ class Perl6::ModuleLoader does Perl6::ModuleLoaderVMConfig {
20 22
         %language_module_loaders{$lang} := $loader;
21 23
     }
22 24
     
  25
+    method register_absolute_path_func($func) {
  26
+        $absolute_path_func := $func;
  27
+    }
  28
+    
  29
+    method absolute_path($path) {
  30
+        $absolute_path_func ?? $absolute_path_func($path) !! $path;
  31
+    }
  32
+    
  33
+
23 34
     method ctxsave() {
24 35
         $*MAIN_CTX := nqp::ctxcaller(nqp::ctx());
25 36
         $*CTXSAVE := 0;
26 37
     }
27 38
     
28  
-    method search_path() {
  39
+    method search_path() {        
29 40
         # See if we have an @*INC set up, and if so just use that.
30 41
         my $PROCESS := nqp::gethllsym('perl6', 'PROCESS');
31 42
         if !nqp::isnull($PROCESS) && nqp::existskey($PROCESS.WHO, '@INC') {
@@ -37,7 +48,7 @@ class Perl6::ModuleLoader does Perl6::ModuleLoaderVMConfig {
37 48
                 }
38 49
             }
39 50
         }
40  
-        
  51
+
41 52
         # Too early to have @*INC; probably no setting yet loaded to provide
42 53
         # the PROCESS initialization.
43 54
         my @search_paths;
4  src/core/IO/Spec.pm
@@ -61,3 +61,7 @@ my class IO::Spec {
61 61
     method abs2rel( |c )               { $SPEC.abs2rel( |c )               }
62 62
     method rel2abs( |c )               { $SPEC.rel2abs( |c )               }
63 63
 }
  64
+
  65
+nqp::gethllsym('perl6', 'ModuleLoader').register_absolute_path_func(
  66
+    sub ($path) { return IO::Spec.rel2abs($path); }
  67
+);
17  src/vm/jvm/ModuleLoaderVMConfig.nqp
@@ -9,23 +9,20 @@ role Perl6::ModuleLoaderVMConfig {
9 9
     
10 10
     # Locates files we could potentially load for this module.
11 11
     method locate_candidates($module_name, @prefixes, :$file?) {
12  
-        my $PROCESS := nqp::gethllsym('perl6', 'PROCESS');
13  
-        my $curdir := !nqp::isnull($PROCESS) && nqp::existskey($PROCESS.WHO, '$CWD')
14  
-                    ?? nqp::atkey($PROCESS.WHO, '$CWD') ~ '/'
15  
-                    !! '';
16 12
         # If its name contains a slash or dot treat is as a path rather than a package name.
17 13
         my @candidates;
18 14
         if nqp::defined($file) {
19  
-            if nqp::stat($curdir ~ $file, 0) {
  15
+            $file := nqp::gethllsym('perl6', 'ModuleLoader').absolute_path($file);
  16
+            if nqp::stat($file, 0) {
20 17
                 my %cand;
21  
-                %cand<key> := $curdir ~ $file;
  18
+                %cand<key> := $file;
22 19
                 my $dot := nqp::rindex($file, '.');
23 20
                 my $ext := $dot >= 0 ?? nqp::substr($file, $dot, nqp::chars($file) - $dot) !! '';
24 21
                 if $ext eq 'class' || $ext eq 'jar' {
25  
-                    %cand<load> := $curdir ~ $file;
  22
+                    %cand<load> := $file;
26 23
                 }
27 24
                 else {
28  
-                    %cand<pm> := $curdir ~ $file;
  25
+                    %cand<pm> := $file;
29 26
                 }
30 27
                 @candidates.push(%cand);
31 28
             }
@@ -40,7 +37,7 @@ role Perl6::ModuleLoaderVMConfig {
40 37
             
41 38
             # Go through the prefixes and build a candidate list.
42 39
             for @prefixes -> $prefix {
43  
-                $prefix := ~$prefix;
  40
+                $prefix := nqp::gethllsym('perl6', 'ModuleLoader').absolute_path(~$prefix);
44 41
                 my $have_pm    := nqp::stat("$prefix/$pm_path", 0);
45 42
                 my $have_pm6   := nqp::stat("$prefix/$pm6_path", 0);
46 43
                 my $have_class := nqp::stat("$prefix/$class_path", 0);
@@ -82,7 +79,7 @@ role Perl6::ModuleLoaderVMConfig {
82 79
         my $path := "$setting_name.setting.jar";
83 80
         my @prefixes := self.search_path();
84 81
         for @prefixes -> $prefix {
85  
-            $prefix := ~$prefix;
  82
+            $prefix := nqp::gethllsym('perl6', 'ModuleLoader').absolute_path(~$prefix);
86 83
             if nqp::stat("$prefix/$path", 0) {
87 84
                 $path := "$prefix/$path";
88 85
                 last;
17  src/vm/parrot/ModuleLoaderVMConfig.nqp
@@ -12,23 +12,20 @@ role Perl6::ModuleLoaderVMConfig {
12 12
     
13 13
     # Locates files we could potentially load for this module.
14 14
     method locate_candidates($module_name, @prefixes, :$file?) {
15  
-        my $PROCESS := nqp::gethllsym('perl6', 'PROCESS');
16  
-        my $curdir := !nqp::isnull($PROCESS) && nqp::existskey($PROCESS.WHO, '$CWD')
17  
-                    ?? nqp::atkey($PROCESS.WHO, '$CWD') ~ '/'
18  
-                    !! '';
19 15
         # If its name contains a slash or dot treat is as a path rather than a package name.
20 16
         my @candidates;
21 17
         if nqp::defined($file) {
22  
-            if nqp::stat($curdir ~ $file, 0) {
  18
+            $file := nqp::gethllsym('perl6', 'ModuleLoader').absolute_path($file);
  19
+            if nqp::stat($file, 0) {
23 20
                 my %cand;
24  
-                %cand<key> := $curdir ~ $file;
  21
+                %cand<key> := $file;
25 22
                 my $dot := nqp::rindex($file, '.');
26 23
                 my $ext := $dot >= 0 ?? nqp::substr($file, $dot, nqp::chars($file) - $dot) !! '';
27 24
                 if $ext eq 'pbc' || $ext eq 'pir' {
28  
-                    %cand<load> := $curdir ~ $file;
  25
+                    %cand<load> := $file;
29 26
                 }
30 27
                 else {
31  
-                    %cand<pm> := $curdir ~ $file;
  28
+                    %cand<pm> := $file;
32 29
                 }
33 30
                 @candidates.push(%cand);
34 31
             }
@@ -43,7 +40,7 @@ role Perl6::ModuleLoaderVMConfig {
43 40
             
44 41
             # Go through the prefixes and build a candidate list.
45 42
             for @prefixes -> $prefix {
46  
-                $prefix := ~$prefix;
  43
+                $prefix := nqp::gethllsym('perl6', 'ModuleLoader').absolute_path(~$prefix);
47 44
                 my $have_pm  := nqp::stat("$prefix/$pm_path", 0);
48 45
                 my $have_pm6 := nqp::stat("$prefix/$pm6_path", 0);
49 46
                 my $have_pir := nqp::stat("$prefix/$pir_path", 0);
@@ -93,7 +90,7 @@ last; # temporary, until we actually don't do just @candidates[0]
93 90
         my $path := "$setting_name.setting.pbc";
94 91
         my @prefixes := self.search_path();
95 92
         for @prefixes -> $prefix {
96  
-            $prefix := ~$prefix;
  93
+            $prefix := nqp::gethllsym('perl6', 'ModuleLoader').absolute_path(~$prefix);
97 94
             if nqp::stat("$prefix/$path", 0) {
98 95
                 $path := "$prefix/$path";
99 96
                 last;

0 notes on commit efac451

Please sign in to comment.
Something went wrong with that request. Please try again.