Permalink
Browse files

Implement absolute path lookup in ModuleLoader.

  • Loading branch information...
1 parent 69c3cce commit efac451801f3d685b02e2daddb89b99bf4e08d48 @donaldh donaldh committed Sep 12, 2013
Showing with 31 additions and 22 deletions.
  1. +13 −2 src/Perl6/ModuleLoader.nqp
  2. +4 −0 src/core/IO/Spec.pm
  3. +7 −10 src/vm/jvm/ModuleLoaderVMConfig.nqp
  4. +7 −10 src/vm/parrot/ModuleLoaderVMConfig.nqp
View
@@ -10,6 +10,8 @@ sub DEBUG(*@strs) {
class Perl6::ModuleLoader does Perl6::ModuleLoaderVMConfig {
my %modules_loaded;
my %settings_loaded;
+ my $absolute_path_func;
+
my %language_module_loaders := nqp::hash(
'NQP', nqp::gethllsym('nqp', 'ModuleLoader'),
);
@@ -20,12 +22,21 @@ class Perl6::ModuleLoader does Perl6::ModuleLoaderVMConfig {
%language_module_loaders{$lang} := $loader;
}
+ method register_absolute_path_func($func) {
+ $absolute_path_func := $func;
+ }
+
+ method absolute_path($path) {
+ $absolute_path_func ?? $absolute_path_func($path) !! $path;
+ }
+
+
method ctxsave() {
$*MAIN_CTX := nqp::ctxcaller(nqp::ctx());
$*CTXSAVE := 0;
}
- method search_path() {
+ method search_path() {
# See if we have an @*INC set up, and if so just use that.
my $PROCESS := nqp::gethllsym('perl6', 'PROCESS');
if !nqp::isnull($PROCESS) && nqp::existskey($PROCESS.WHO, '@INC') {
@@ -37,7 +48,7 @@ class Perl6::ModuleLoader does Perl6::ModuleLoaderVMConfig {
}
}
}
-
+
# Too early to have @*INC; probably no setting yet loaded to provide
# the PROCESS initialization.
my @search_paths;
View
@@ -61,3 +61,7 @@ my class IO::Spec {
method abs2rel( |c ) { $SPEC.abs2rel( |c ) }
method rel2abs( |c ) { $SPEC.rel2abs( |c ) }
}
+
+nqp::gethllsym('perl6', 'ModuleLoader').register_absolute_path_func(
+ sub ($path) { return IO::Spec.rel2abs($path); }
+);
@@ -9,23 +9,20 @@ role Perl6::ModuleLoaderVMConfig {
# Locates files we could potentially load for this module.
method locate_candidates($module_name, @prefixes, :$file?) {
- my $PROCESS := nqp::gethllsym('perl6', 'PROCESS');
- my $curdir := !nqp::isnull($PROCESS) && nqp::existskey($PROCESS.WHO, '$CWD')
- ?? nqp::atkey($PROCESS.WHO, '$CWD') ~ '/'
- !! '';
# If its name contains a slash or dot treat is as a path rather than a package name.
my @candidates;
if nqp::defined($file) {
- if nqp::stat($curdir ~ $file, 0) {
+ $file := nqp::gethllsym('perl6', 'ModuleLoader').absolute_path($file);
+ if nqp::stat($file, 0) {
my %cand;
- %cand<key> := $curdir ~ $file;
+ %cand<key> := $file;
my $dot := nqp::rindex($file, '.');
my $ext := $dot >= 0 ?? nqp::substr($file, $dot, nqp::chars($file) - $dot) !! '';
if $ext eq 'class' || $ext eq 'jar' {
- %cand<load> := $curdir ~ $file;
+ %cand<load> := $file;
}
else {
- %cand<pm> := $curdir ~ $file;
+ %cand<pm> := $file;
}
@candidates.push(%cand);
}
@@ -40,7 +37,7 @@ role Perl6::ModuleLoaderVMConfig {
# Go through the prefixes and build a candidate list.
for @prefixes -> $prefix {
- $prefix := ~$prefix;
+ $prefix := nqp::gethllsym('perl6', 'ModuleLoader').absolute_path(~$prefix);
my $have_pm := nqp::stat("$prefix/$pm_path", 0);
my $have_pm6 := nqp::stat("$prefix/$pm6_path", 0);
my $have_class := nqp::stat("$prefix/$class_path", 0);
@@ -82,7 +79,7 @@ role Perl6::ModuleLoaderVMConfig {
my $path := "$setting_name.setting.jar";
my @prefixes := self.search_path();
for @prefixes -> $prefix {
- $prefix := ~$prefix;
+ $prefix := nqp::gethllsym('perl6', 'ModuleLoader').absolute_path(~$prefix);
if nqp::stat("$prefix/$path", 0) {
$path := "$prefix/$path";
last;
@@ -12,23 +12,20 @@ role Perl6::ModuleLoaderVMConfig {
# Locates files we could potentially load for this module.
method locate_candidates($module_name, @prefixes, :$file?) {
- my $PROCESS := nqp::gethllsym('perl6', 'PROCESS');
- my $curdir := !nqp::isnull($PROCESS) && nqp::existskey($PROCESS.WHO, '$CWD')
- ?? nqp::atkey($PROCESS.WHO, '$CWD') ~ '/'
- !! '';
# If its name contains a slash or dot treat is as a path rather than a package name.
my @candidates;
if nqp::defined($file) {
- if nqp::stat($curdir ~ $file, 0) {
+ $file := nqp::gethllsym('perl6', 'ModuleLoader').absolute_path($file);
+ if nqp::stat($file, 0) {
my %cand;
- %cand<key> := $curdir ~ $file;
+ %cand<key> := $file;
my $dot := nqp::rindex($file, '.');
my $ext := $dot >= 0 ?? nqp::substr($file, $dot, nqp::chars($file) - $dot) !! '';
if $ext eq 'pbc' || $ext eq 'pir' {
- %cand<load> := $curdir ~ $file;
+ %cand<load> := $file;
}
else {
- %cand<pm> := $curdir ~ $file;
+ %cand<pm> := $file;
}
@candidates.push(%cand);
}
@@ -43,7 +40,7 @@ role Perl6::ModuleLoaderVMConfig {
# Go through the prefixes and build a candidate list.
for @prefixes -> $prefix {
- $prefix := ~$prefix;
+ $prefix := nqp::gethllsym('perl6', 'ModuleLoader').absolute_path(~$prefix);
my $have_pm := nqp::stat("$prefix/$pm_path", 0);
my $have_pm6 := nqp::stat("$prefix/$pm6_path", 0);
my $have_pir := nqp::stat("$prefix/$pir_path", 0);
@@ -93,7 +90,7 @@ last; # temporary, until we actually don't do just @candidates[0]
my $path := "$setting_name.setting.pbc";
my @prefixes := self.search_path();
for @prefixes -> $prefix {
- $prefix := ~$prefix;
+ $prefix := nqp::gethllsym('perl6', 'ModuleLoader').absolute_path(~$prefix);
if nqp::stat("$prefix/$path", 0) {
$path := "$prefix/$path";
last;

0 comments on commit efac451

Please sign in to comment.