1. role CompUnit::Repository {
  2. has CompUnit::Repository $.next-repo is rw;
  3. # Resolves a dependency specification to a concrete dependency. If the
  4. # dependency was not already loaded, loads it. Returns a CompUnit
  5. # object that represents the selected dependency. If there is no
  6. # matching dependency, throws X::CompUnit::UnsatisfiedDependency.
  7. method need(CompUnit::DependencySpecification $spec,
  8. # If we're first in the chain, our precomp repo is the chosen one.
  9. CompUnit::PrecompilationRepository $precomp = self.precomp-repository(),
  10. CompUnit::PrecompilationStore :@precomp-stores = Array[CompUnit::PrecompilationStore].new($precomp.store)
  11. --> CompUnit:D)
  12. { ... }
  13. # Resolves a dependency specification to a concrete dependency.
  14. # Returns a CompUnit object that represents the selected dependency.
  15. # If there is no matching dependency, Nil is returned.
  16. method resolve(CompUnit::DependencySpecification $spec --> CompUnit:D)
  17. {
  18. self.next-repo
  19. ?? self.next-repo.resolve($spec)
  20. !! Nil
  21. }
  22. # Just load the file and return a CompUnit object representing it.
  23. method load(IO::Path:D $file --> CompUnit:D)
  24. {
  25. self.next-repo
  26. ?? self.next-repo.load($file)
  27. !! nqp::die("Could not find $file in:\n"
  28. ~ $*REPO.repo-chain.map(*.Str).join("\n").indent(4));
  29. }
  30. # Returns the CompUnit objects describing all of the compilation
  31. # units that have been loaded by this repository in the current
  32. # process.
  33. method loaded(--> Iterable:D)
  34. { ... }
  35. # Returns a unique ID of this repository
  36. method id(--> Str:D)
  37. { ... }
  38. method precomp-store(--> CompUnit::PrecompilationStore)
  39. { CompUnit::PrecompilationStore }
  40. method precomp-repository(--> CompUnit::PrecompilationRepository)
  41. { CompUnit::PrecompilationRepository::None }
  42. method repo-chain() {
  43. ($.next-repo and $.next-repo.defined) ?? (self, |$.next-repo.repo-chain()) !! (self, );
  44. }
  45. }