Skip to content

Instantly share code, notes, and snippets.

@ugexe
Created June 3, 2016 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugexe/017672ef39723ff6e33744d08a854872 to your computer and use it in GitHub Desktop.
Save ugexe/017672ef39723ff6e33744d08a854872 to your computer and use it in GitHub Desktop.
has %!known; # cache `provides` of META6 when available
method !matching-file(CompUnit::DependencySpecification $spec) {
if $spec.from eq 'Perl6' {
my $name = $spec.short-name;
return %!loaded{$name} if %!loaded{$name}:exists;
my $base := $!prefix.child($name.subst(:g, "::", $*SPEC.dir-sep) ~ '.').Str;
return $base if %seen{$base}:exists;
my $meta = $!prefix.child('META6.json');
%!known //= try {
Rakudo::Internals::JSON.from-json($meta.slurp).hash<provides>;
CATCH {
when JSONException {
fail "Invalid JSON found in META6.json";
}
}
};
my $found = %!known{$name}:exists && %!known{$name}.IO.f
?? %!known{$name}.IO
!! %extensions<Perl6>.map({ $base ~ $extension }).first(*.IO.e).IO;
return $base, $found if $found;
}
False
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment