Skip to content

Instantly share code, notes, and snippets.

@ugexe
Last active August 29, 2022 01:15
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/ce581c7cac445395299308ebe816d97f to your computer and use it in GitHub Desktop.
Save ugexe/ce581c7cac445395299308ebe816d97f to your computer and use it in GitHub Desktop.
module UseFromDist {
=begin pod
=title module UseFromDist
=subtitle Restrict module loading to the current distribution.
=head1 Synopsis
=begin code :lang<raku>
use UseFromDist;
use-from-dist("Test");
=end code
=head1 Description
Sugar around writing use statements that automatically contain the auth, api, and version of
the calling module's distribution.
=head1 Subroutines
=head2 sub use-from-dist
sub use-from-dist($module-name --> Nil)
Load a module from the current distribution.
=end pod
sub use-from-dist($module-name --> Nil) is export {
my $dist := CALLERS::<$*DISTRIBUTION>;
my $meta := $dist.meta.hash;
my $spec := CompUnit::DependencySpecification.new(
short-name => $module-name,
auth-matcher => $meta<auth> // True,
api-matcher => $meta<api> // True,
version-matcher => $meta<version> // True,
);
my $repo := CompUnit::RepositoryRegistry.repository-for-spec($dist.repo);
$repo.need($spec);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment