-
-
Save ugexe/ce581c7cac445395299308ebe816d97f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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