Skip to content

Commit

Permalink
Streamline CompUnit::Repository::Perl5
Browse files Browse the repository at this point in the history
- tighten signatures
- fewer repeated method calls
- tighten signatures
- move CATCH block to start of applicable scope
- only create Perl 5 dependency specifications once in a process
  • Loading branch information
lizmat committed Apr 15, 2022
1 parent 0fe4893 commit 04c8fc9
Showing 1 changed file with 40 additions and 35 deletions.
75 changes: 40 additions & 35 deletions src/core.c/CompUnit/Repository/Perl5.pm6
@@ -1,51 +1,56 @@
class CompUnit::Repository::Perl5 does CompUnit::Repository {
method need(
CompUnit::DependencySpecification $spec,
CompUnit::PrecompilationRepository $precomp = self.precomp-repository(),
--> CompUnit:D)
{
my $perl5-dependency :=
CompUnit::DependencySpecification.new(:short-name<Inline::Perl5>);

method need(CompUnit::Repository::Perl5:D:
CompUnit::DependencySpecification $spec,
CompUnit::PrecompilationRepository $precomp,
--> CompUnit:D) {
if $spec.from eq 'Perl5' {
my $compunit = $*REPO.need(CompUnit::DependencySpecification.new(:short-name<Inline::Perl5>));
my $perl5 := $compunit.handle.globalish-package<Inline>.WHO<Perl5>.default_perl5;
CATCH {
when X::CompUnit::UnsatisfiedDependency {
X::NYI::Available.new(
:available('Inline::Perl5'),
:feature('Perl 5')
).throw;
}
}

my $compunit := $*REPO.need($perl5-dependency);
my $perl5 := $compunit.handle.globalish-package<Inline>.WHO<Perl5>.default_perl5;

if $*RAKUDO_MODULE_DEBUG -> $RMD {
$RMD("Loading {$spec.short-name} via Inline::Perl5");
$RMD("Loading $spec.short-name() via Inline::Perl5");
}
my $short-name := $spec.short-name;
my $handle := $perl5.require(
$spec.short-name,
$spec.version-matcher !== True ?? $spec.version-matcher.Num !! Num,
:handle
);
return CompUnit.new(
:short-name($spec.short-name),
:$handle,
:repo(self),
:repo-id($spec.short-name),
:from($spec.from),
$short-name,
$spec.version-matcher !== True
?? $spec.version-matcher.Numi
!! Num,
:handle
);
CompUnit.new:
:$short-name,
:$handle,
:repo(self),
:repo-id($short-name),
:from<Perl5>;

CATCH {
when X::CompUnit::UnsatisfiedDependency {
X::NYI::Available.new(:available('Inline::Perl5'), :feature('Perl 5')).throw;
}
}
}

return self.next-repo.need($spec, $precomp) if self.next-repo;
X::CompUnit::UnsatisfiedDependency.new(:specification($spec)).throw;
elsif self.next-repo -> $repo {
$repo.need($spec, $precomp // self.precomp-repository)
}
else {
X::CompUnit::UnsatisfiedDependency.new(:specification($spec)).throw;
}
}

method loaded() {
[]
}
method loaded(--> Empty) { }

method id() {
'Perl5'
}
method id(--> Str:D) { 'Perl5' }

method path-spec() {
'perl5#'
}
method path-spec(--> Str:D) { 'perl5#' }

multi method gist(CompUnit::Repository::Perl5:D:) {
self.path-spec
Expand Down

0 comments on commit 04c8fc9

Please sign in to comment.