Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bring back require $file-name;
Added an extra method to CompUnit::Repository for loading a module from a given
file name. The exact use cases for this are unclear, but it's speced and it
feels like an appropriate low level tool for extreme situations.

In any case it's quite separate from normal module loading, so it can be removed
easily in case we decide that it has to go.
  • Loading branch information
niner committed Oct 30, 2015
1 parent 45f457f commit 8f0c099
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/core/CompUnit/Repository.pm
Expand Up @@ -11,6 +11,11 @@ role CompUnit::Repository {
returns CompUnit:D
{ ... }

# Just load the file and return a CompUnit object representing it.
method load(Str:D $file)
returns CompUnit:D
{ ... }

# Returns the CompUnit objects describing all of the compilation
# units that have been loaded by this repository in the current
# process.
Expand Down
24 changes: 16 additions & 8 deletions src/core/CompUnitRepo.pm
Expand Up @@ -77,14 +77,22 @@ RAKUDO_MODULE_DEBUG("Looking in $spec for $name")
}
}
else {
return $*REPO.need(
CompUnit::DependencySpecification.new(
:short-name($module_name),
:auth-matcher(%opts<auth>),
:version-matcher(%opts<ver>),
),
GLOBALish,
:$line,
return (
$file
?? $*REPO.load(
$file,
GLOBALish,
:$line
)
!! $*REPO.need(
CompUnit::DependencySpecification.new(
:short-name($module_name),
:auth-matcher(%opts<auth>),
:version-matcher(%opts<ver>),
),
GLOBALish,
:$line,
)
).unit;
}
# elsif $file {
Expand Down
16 changes: 15 additions & 1 deletion src/core/CompUnitRepo/Locally.pm
Expand Up @@ -40,7 +40,11 @@ role CompUnitRepo::Locally {
)
returns CompUnit:D
{
my @candidates = self.candidates($spec.short-name, :auth($spec.auth-matcher), :ver($spec.version-matcher));
my @candidates = self.candidates(
$spec.short-name,
:auth($spec.auth-matcher),
:ver($spec.version-matcher),
);
if @candidates {
@candidates[0].load(GLOBALish, :$line);
return @candidates[0];
Expand All @@ -49,6 +53,16 @@ role CompUnitRepo::Locally {
nqp::die("Could not find $spec in:\n" ~ $*REPO.repo-chain.map(*.Str).join("\n").indent(4));
}

method load(Str:D $file, \GLOBALish is raw = Any, :$line) returns CompUnit:D {
my @candidates = self.candidates($file, :file($file));
if @candidates {
@candidates[0].load(GLOBALish, :$line);
return @candidates[0];
}
return self.next-repo.load($file, :$line) if self.next-repo;
nqp::die("Could not find $file in:\n" ~ $*REPO.repo-chain.map(*.Str).join("\n").indent(4));
}

method loaded() returns Iterable {
return ();
}
Expand Down

0 comments on commit 8f0c099

Please sign in to comment.