Skip to content

Instantly share code, notes, and snippets.

@ugexe
Created August 6, 2017 21:25
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/c5d864f287b43f3ab3ed9a58657c655d to your computer and use it in GitHub Desktop.
Save ugexe/c5d864f287b43f3ab3ed9a58657c655d to your computer and use it in GitHub Desktop.
proto method candidates(|) {*}
multi method candidates(Str:D $name, :$auth, :$ver, :$api) {
return samewith(CompUnit::DependencySpecification.new(
short-name => $name,
auth-matcher => $auth // True,
version-matcher => $ver // True,
api-matcher => $api // True,
));
}
multi method candidates(CompUnit::DependencySpecification $spec) {
return Empty unless $spec.from eq 'Perl6';
$!distribution = $!prefix.add('META6.json').f
?? Distribution::Path.new($!prefix)
!! Distribution::Hash.new({
name => $spec.short-name,
ver => Version.new(0),
api => Version.new(0),
auth => '',
files => ($spec.short-name.contains('/')
?? %( $spec.short-name => $spec.short-name )
!! %( )),
provides => ($spec.short-name.contains('/')
?? %( )
!! %( $spec.short-name => first *,
grep { $!prefix.child($_).f },
map { $spec.short-name.subst(:g, "::", $*SPEC.dir-sep) ~ ".$_" },
@extensions) ),
}, :$!prefix);
my $version-matcher = ($spec.version-matcher ~~ Bool)
?? $spec.version-matcher # fast path for matching Version.new(*)
!! Version.new($spec.version-matcher);
my $api-matcher = ($spec.api-matcher ~~ Bool)
?? $spec.api-matcher
!! Version.new($spec.api-matcher);
return False unless $!distribution.meta<auth> ~~ $spec.auth-matcher
and Version.new($!distribution.meta<ver>) ~~ $version-matcher
and Version.new($!distribution.meta<api>) ~~ $api-matcher;
$!distribution;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment